Explorar el Código

fix: handle sleazyfork in more places

tophf hace 2 años
padre
commit
768399d35a
Se han modificado 3 ficheros con 7 adiciones y 12 borrados
  1. 1 0
      src/background/utils/script.js
  2. 2 2
      src/background/utils/tab-redirector.js
  3. 4 10
      src/common/util.js

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

@@ -136,6 +136,7 @@ function inferScriptHome(script) {
     u = u.split('/', 6);
     u = u.split('/', 6);
     switch (u[2]) {
     switch (u[2]) {
     case 'greasyfork.org':
     case 'greasyfork.org':
+    case 'sleazyfork.org':
       if (u[3] !== 'scripts') u.splice(3, 1);
       if (u[3] !== 'scripts') u.splice(3, 1);
       break;
       break;
     case 'raw.githubusercontent.com':
     case 'raw.githubusercontent.com':

+ 2 - 2
src/background/utils/tab-redirector.js

@@ -38,7 +38,7 @@ addPublicCommands({
 });
 });
 
 
 const whitelistRe = re`/^https:\/\/(
 const whitelistRe = re`/^https:\/\/(
-  greasyfork\.org\/scripts\/[^/]*\/code|
+  (greas|sleaz)yfork\.org\/scripts\/[^/]*\/code|
   openuserjs\.org\/install\/[^/]*|
   openuserjs\.org\/install\/[^/]*|
   github\.com\/[^/]*\/[^/]*\/(
   github\.com\/[^/]*\/[^/]*\/(
     raw\/[^/]*|
     raw\/[^/]*|
@@ -49,7 +49,7 @@ const whitelistRe = re`/^https:\/\/(
 )\/[^/]*?\.user\.js  ([?#]|$)  /ix`;
 )\/[^/]*?\.user\.js  ([?#]|$)  /ix`;
 const blacklistRe = re`/^https?:\/\/(
 const blacklistRe = re`/^https?:\/\/(
   (gist\\.)?github\\.com|
   (gist\\.)?github\\.com|
-  (greasyfork|openuserjs)\\.org
+  ((greas|sleaz)yfork|openuserjs)\\.org
 )\//ix`;
 )\//ix`;
 const resolveVirtualUrl = url => (
 const resolveVirtualUrl = url => (
   `${extensionOptionsPage}${ROUTE_SCRIPTS}/${+url.split('#')[1]}`
   `${extensionOptionsPage}${ROUTE_SCRIPTS}/${+url.split('#')[1]}`

+ 4 - 10
src/common/util.js

@@ -268,14 +268,6 @@ export async function requestLocalFile(url, options = {}) {
   });
   });
 }
 }
 
 
-/**
- * Excludes `text/html` to avoid LINK header that Chrome uses to prefetch js and css,
- * because GreasyFork's 404 error response causes CSP violations in console of our page.
- */
-const FORCED_ACCEPT = {
-  'greasyfork.org': 'application/javascript, text/plain, text/css',
-};
-
 const isLocalUrlRe = re`/^(
 const isLocalUrlRe = re`/^(
   file:\/\/|
   file:\/\/|
   about:|
   about:|
@@ -307,8 +299,10 @@ export async function request(url, options = {}) {
   const { body, headers, [kResponseType]: responseType } = options;
   const { body, headers, [kResponseType]: responseType } = options;
   const isBodyObj = body && body::({}).toString() === '[object Object]';
   const isBodyObj = body && body::({}).toString() === '[object Object]';
   const [, scheme, auth, hostname, urlTail] = url.match(/^([-\w]+:\/\/)([^@/]*@)?([^/]*)(.*)|$/);
   const [, scheme, auth, hostname, urlTail] = url.match(/^([-\w]+:\/\/)([^@/]*@)?([^/]*)(.*)|$/);
-  const accept = FORCED_ACCEPT[hostname];
-  // Not using ...spread because Babel mistakenly adds its polyfill to injected-web
+  // Avoiding LINK header prefetch of js in 404 pages which cause CSP violations in our console
+  // TODO: toggle a webRequest/declarativeNetRequest rule to strip LINK headers
+  const accept = (hostname === 'greasyfork.org' || hostname === 'sleazyfork.org')
+    && 'application/javascript, text/plain, text/css';
   const init = Object.assign({
   const init = Object.assign({
     cache: isRemote(url) ? undefined : 'no-cache',
     cache: isRemote(url) ? undefined : 'no-cache',
   }, options, {
   }, options, {