diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-13 11:46:27 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-13 12:12:51 -0400 |
commit | c9158a37b509ba58cd1e364e3d7a31cd43de5789 (patch) | |
tree | 248de2c0fd48df1003b831488ff857730d41ae73 /ext/bg | |
parent | 32729482844d7af9e9f307a69c96ea34f1e66011 (diff) |
Allow outer popup stylesheets to be injected
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/js/api.js | 29 | ||||
-rw-r--r-- | ext/bg/js/backend.js | 1 |
2 files changed, 30 insertions, 0 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index f768e6f9..94a70c34 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -241,3 +241,32 @@ function apiFrameInformationGet(sender) { const frameId = sender.frameId; return Promise.resolve({frameId}); } + +function apiInjectStylesheet(css, sender) { + if (!sender.tab) { + return Promise.reject(new Error('Invalid tab')); + } + + const tabId = sender.tab.id; + const frameId = sender.frameId; + const details = { + code: css, + runAt: 'document_start', + cssOrigin: 'user', + allFrames: false + }; + if (typeof frameId === 'number') { + details.frameId = frameId; + } + + return new Promise((resolve, reject) => { + chrome.tabs.insertCSS(tabId, details, () => { + const e = chrome.runtime.lastError; + if (e) { + reject(new Error(e.message)); + } else { + resolve(); + } + }); + }); +} diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 453f4282..c1216d95 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -185,6 +185,7 @@ Backend.messageHandlers = { screenshotGet: ({options}, sender) => apiScreenshotGet(options, sender), forward: ({action, params}, sender) => apiForward(action, params, sender), frameInformationGet: (params, sender) => apiFrameInformationGet(sender), + injectStylesheet: ({css}, sender) => apiInjectStylesheet(css, sender) }; window.yomichan_backend = new Backend(); |