aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorhackademix <giorgio@maone.net>2019-03-11 23:57:36 +0100
committerhackademix <giorgio@maone.net>2019-03-11 23:57:36 +0100
commit1e4ce528dec55b79501e15ef08b751b4f533d756 (patch)
treea5f3f2b8c168f0ec85d709f3104e0fd1bd40292c /common
parent3f325cea256c5fd082a1c029d27f63ab93440ba6 (diff)
Fix for large scripts thrashing the black/white lists when added.
Diffstat (limited to 'common')
-rw-r--r--common/Storage.js18
1 files changed, 15 insertions, 3 deletions
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 };
}