Browse Source

fix: use arraybuffer to support dataURL resource

Gerald 8 years ago
parent
commit
e9ed36307e
2 changed files with 4 additions and 12 deletions
  1. 1 0
      src/background/utils/requests.js
  2. 3 12
      src/options/views/confirm.vue

+ 1 - 0
src/background/utils/requests.js

@@ -246,6 +246,7 @@ const installURLs = [
   '^https://greasyfork.org/scripts/[^/]*/code/[^/]*?\\.user\\.js([?#]|$)',
   '^https://openuserjs.org/install/[^/]*/[^/]*?\\.user\\.js([?#]|$)',
   '^https://github.com/[^/]*/[^/]*/raw/[^/]*/[^/]*?\\.user\\.js([?#]|$)',
+  '^https://gist.github.com/.*?/[^/]*?.user.js([?#]|$)',
 ].map(re => new RegExp(re));
 
 browser.webRequest.onBeforeRequest.addListener(req => {

+ 3 - 12
src/options/views/confirm.vue

@@ -30,7 +30,7 @@
 </template>
 
 <script>
-import { sendMessage, zfill, request } from 'src/common';
+import { sendMessage, zfill, request, buffer2string } from 'src/common';
 import options from 'src/common/options';
 import initCache from 'src/common/cache';
 import VmCode from './code';
@@ -176,18 +176,9 @@ export default {
         return Promise.resolve(cache.get(cacheKey));
       }
       return request(url, {
-        responseType: isBlob ? 'blob' : null,
-      })
-      .then(({ data }) => {
-        if (!isBlob) return data;
-        return new Promise(resolve => {
-          const reader = new FileReader();
-          reader.onload = function onload() {
-            resolve(window.btoa(this.result));
-          };
-          reader.readAsBinaryString(data);
-        });
+        responseType: isBlob ? 'arraybuffer' : null,
       })
+      .then(({ data }) => (isBlob ? window.btoa(buffer2string(data)) : data))
       .then(data => {
         if (useCache) cache.put(cacheKey, data);
         return data;