From 1e4ce528dec55b79501e15ef08b751b4f533d756 Mon Sep 17 00:00:00 2001 From: hackademix Date: Mon, 11 Mar 2019 23:57:36 +0100 Subject: Fix for large scripts thrashing the black/white lists when added. --- bg/ListManager.js | 2 +- common/Storage.js | 18 +++++++++++++++--- main_background.js | 15 ++------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/bg/ListManager.js b/bg/ListManager.js index 354866d..2f5f74e 100644 --- a/bg/ListManager.js +++ b/bg/ListManager.js @@ -50,7 +50,7 @@ class ListManager { */ getStatus(key, defValue = "unknown") { let {blacklist, whitelist} = this.lists; - let inline = ListStore.viewSourceItem(key); + let inline = ListStore.inlineItem(key); if (inline) { return blacklist.contains(inline) ? "blacklisted" diff --git a/common/Storage.js b/common/Storage.js index 415b4bb..8010f3f 100644 --- a/common/Storage.js +++ b/common/Storage.js @@ -66,8 +66,12 @@ class ListStore { }); } - static viewSourceItem(url) { - return url.startsWith("view-source:") && url.replace(/#line\d+/,"#"); + static inlineItem(url) { + // here we simplify and hash inline script references + return url.startsWith("inline:") ? url + : url.startsWith("view-source:") + && url.replace(/^view-source:[\w-+]+:\/+([^/]+).*#line\d+/,"inline://$1#") + .replace(/\n[^]*/, s => s.replace(/\s+/g, ' ').substring(0, 16) + "…" + hash(s.trim())); } static hashItem(hash) { return hash.startsWith("(") ? hash : `(${hash})`; @@ -128,6 +132,14 @@ class ListStore { return this.items.has(item); } } + +var jssha = require('jssha'); +function hash(source){ + var shaObj = new jssha("SHA-256","TEXT") + shaObj.update(source); + return shaObj.getHash("HEX"); +} + if (typeof module === "object") { - module.exports = { ListStore, Storage }; + module.exports = { ListStore, Storage, hash }; } diff --git a/main_background.js b/main_background.js index 4442c6d..8060ebd 100644 --- a/main_background.js +++ b/main_background.js @@ -22,10 +22,9 @@ var acorn = require('acorn'); var acornLoose = require('acorn-loose'); -var jssha = require('jssha'); var legacy_license_lib = require("./legacy_license_check.js"); var {ResponseProcessor} = require("./bg/ResponseProcessor"); -var {Storage, ListStore} = require("./common/Storage"); +var {Storage, ListStore, hash} = require("./common/Storage"); var {ListManager} = require("./bg/ListManager"); var {ExternalLicenses} = require("./bg/ExternalLicenses"); @@ -51,16 +50,6 @@ function dbg_print(a,b){ } } -/** -* Wrapper around crypto lib -* -*/ -function hash(source){ - var shaObj = new jssha("SHA-256","TEXT") - shaObj.update(source); - return shaObj.getHash("HEX"); -} - /* NONTRIVIAL THINGS: - Fetch @@ -339,7 +328,7 @@ async function connected(p) { if (m.site) { key = ListStore.siteItem(key); } else { - key = ListStore.viewSourceItem(key) || key; + key = ListStore.inlineItem(key) || key; } await listManager[action](key); update = true; -- cgit v1.2.3