aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/api.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-13 12:14:53 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-13 12:15:25 -0400
commit2f88bcf82c4dd82d1dd2f035717effaa2673e3c2 (patch)
tree437f8f97629ea735089a8f7195b2cea09eadb894 /ext/bg/js/api.js
parent320af99b7676a37157e2d7207756dd502e6be608 (diff)
parent1b96e69ea2bfe26ded82e2f058d30500290e9d2d (diff)
Merge branch 'style-editor2'
#253
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r--ext/bg/js/api.js29
1 files changed, 29 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();
+ }
+ });
+ });
+}