aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Storage.js17
1 files changed, 16 insertions, 1 deletions
diff --git a/common/Storage.js b/common/Storage.js
index a83ce8f..8010f3f 100644
--- a/common/Storage.js
+++ b/common/Storage.js
@@ -66,6 +66,13 @@ class ListStore {
});
}
+ 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})`;
}
@@ -125,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 };
}