浏览代码

fix GM_addStyle in CSP limited pages

Gerald 9 年之前
父节点
当前提交
2c8cae0813
共有 2 个文件被更改,包括 18 次插入17 次删除
  1. 1 1
      src/background/sync/index.js
  2. 17 16
      src/injected.js

+ 1 - 1
src/background/sync/index.js

@@ -326,7 +326,7 @@ define('sync', function (require, _exports, module) {
           };
           xhr.send(options.body);
 
-          function requestError(reason) {
+          function requestError() {
             reject({
               url: options.url,
               status: xhr.status,

+ 17 - 16
src/injected.js

@@ -479,12 +479,7 @@ var comm = {
       },
       GM_addStyle: {
         value: function (css) {
-          if (document.head) {
-            var style = document.createElement('style');
-            style.innerHTML = css;
-            document.head.appendChild(style);
-            return style;
-          }
+          comm.post({cmd: 'AddStyle', data: css});
         },
       },
       GM_log: {
@@ -611,9 +606,6 @@ function injectScript(data) {
   };
   inject('!' + func.toString() + '(' + JSON.stringify(data[0]) + ',' + JSON.stringify(comm.did) + ',function(g){' + data[1] + '})');
 }
-function newTab(url) {
-  window.open(url);
-}
 function handleC(e) {
   var req = e.detail;
   if (!req) {
@@ -621,18 +613,27 @@ function handleC(e) {
     return;
   }
   var maps = {
-    SetValue: function(data) {
+    GetRequestId: getRequestId,
+    HttpRequest: httpRequest,
+    AbortRequest: abortRequest,
+    Inject: injectScript,
+    NewTab: function (url) {
+      window.open(url);
+    },
+    SetValue: function (data) {
       _.sendMessage({cmd: 'SetValue', data: data});
     },
-    RegisterMenu: function(data) {
+    RegisterMenu: function (data) {
       if (window.top === window) menus.push(data);
       getPopup();
     },
-    GetRequestId: getRequestId,
-    HttpRequest: httpRequest,
-    AbortRequest: abortRequest,
-    Inject: injectScript,
-    NewTab: newTab,
+    AddStyle: function (css) {
+      if (document.head) {
+        var style = document.createElement('style');
+        style.innerHTML = css;
+        document.head.appendChild(style);
+      }
+    },
   };
   var func = maps[req.cmd];
   if (func) func(req.data);