ccb2e899b3
* use wrappedJSObject to create style elements in page context * skip unnecessary polyfills in content scripts * group all style management stuff in injector * support all API methods in content scripts
23 lines
606 B
JavaScript
23 lines
606 B
JavaScript
'use strict';
|
|
/*
|
|
Convert chrome APIs into promises. Example:
|
|
|
|
const storageSyncGet = promisify(chrome.storage.sync.get.bind(chrome.storage.sync));
|
|
storageSyncGet(['key']).then(result => {...});
|
|
|
|
*/
|
|
self.promisify = self.INJECTED === 1 ? self.promisify : fn =>
|
|
(...args) =>
|
|
new Promise((resolve, reject) => {
|
|
fn(...args, (...result) => {
|
|
if (chrome.runtime.lastError) {
|
|
reject(chrome.runtime.lastError);
|
|
return;
|
|
}
|
|
resolve(
|
|
result.length === 0 ? undefined :
|
|
result.length === 1 ? result[0] : result
|
|
);
|
|
});
|
|
});
|