Configurable capability to show noscript elements on script-disabled pages.
This commit is contained in:
parent
12c654f130
commit
c42cbb7290
|
@ -577,6 +577,9 @@
|
||||||
"cap_ping": {
|
"cap_ping": {
|
||||||
"message": "ping"
|
"message": "ping"
|
||||||
},
|
},
|
||||||
|
"cap_noscript": {
|
||||||
|
"message": "noscript"
|
||||||
|
},
|
||||||
"cap_other": {
|
"cap_other": {
|
||||||
"message": "other"
|
"message": "other"
|
||||||
},
|
},
|
||||||
|
|
|
@ -238,7 +238,19 @@ var LifeCycle = (() => {
|
||||||
if (Ver.is(previousVersion, "<=", "11.0.10")) {
|
if (Ver.is(previousVersion, "<=", "11.0.10")) {
|
||||||
log(`Upgrading from 11.0.10 or below (${previousVersion}): configure the "ping" capability.`);
|
log(`Upgrading from 11.0.10 or below (${previousVersion}): configure the "ping" capability.`);
|
||||||
await ns.initializing;
|
await ns.initializing;
|
||||||
ns.policy.TRUSTED.capabilities.add("ping")
|
ns.policy.TRUSTED.capabilities.add("ping");
|
||||||
|
await ns.savePolicy();
|
||||||
|
}
|
||||||
|
if (Ver.is(previousVersion, "<", "11.2.rc4")) {
|
||||||
|
log(`Upgrading from ${previousVersion}: configure the "noscript" capability.`);
|
||||||
|
await ns.initializing;
|
||||||
|
let {DEFAULT, TRUSTED, UNTRUSTED} = ns.policy;
|
||||||
|
// let's add "noscript" to DEFAULY, TRUSTED and any CUSTOM preset
|
||||||
|
let presets = [DEFAULT, TRUSTED];
|
||||||
|
presets = presets.concat([...ns.policy.sites.values()].filter(p => p !== TRUSTED && p !== UNTRUSTED));
|
||||||
|
for (let p of presets) {
|
||||||
|
p.capabilities.add("noscript");
|
||||||
|
}
|
||||||
await ns.savePolicy();
|
await ns.savePolicy();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,99 +1,69 @@
|
||||||
|
// depends on /nscl/content/NoscriptElements.js
|
||||||
|
|
||||||
|
"use strict";
|
||||||
function onScriptDisabled() {
|
function onScriptDisabled() {
|
||||||
if (document.readyState === "loading") {
|
|
||||||
if (!onScriptDisabled._installed) {
|
|
||||||
window.addEventListener("DOMContentLoaded", e => onScriptDisabled());
|
|
||||||
onScriptDisabled._installed = true;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
onScriptDisabled = () => {};
|
onScriptDisabled = () => {};
|
||||||
let refresh = false;
|
|
||||||
for (let noscript of document.querySelectorAll("noscript")) {
|
|
||||||
|
|
||||||
// force show NOSCRIPT elements content
|
let emulateNoScriptElement = () => {
|
||||||
let replacement = createHTMLElement("span");
|
if (ns.allows("noscript")) {
|
||||||
replacement.innerHTML = noscript.innerHTML;
|
NoscriptElements.emulate(true);
|
||||||
// emulate meta-refresh
|
|
||||||
for (let meta of replacement.querySelectorAll('meta[http-equiv="refresh"]')) {
|
|
||||||
refresh = true;
|
|
||||||
document.head.appendChild(meta);
|
|
||||||
console.log(`State %s, emulating`, document.readyState, meta);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (noscript.closest("head") && document.body) {
|
if (document.readyState === "loading") {
|
||||||
document.body.insertBefore(noscript, document.body.firstChild);
|
window.addEventListener("DOMContentLoaded", emulateNoScriptElement, true);
|
||||||
}
|
return;
|
||||||
noscript.replaceWith(replacement);
|
} else {
|
||||||
|
emulateNoScriptElement();
|
||||||
}
|
}
|
||||||
if (refresh) {
|
|
||||||
let html = document.documentElement.outerHTML;
|
|
||||||
let rewrite = () => {
|
|
||||||
let document = window.wrappedJSObject ? window.wrappedJSObject.document : window.document;
|
|
||||||
try {
|
|
||||||
document.open();
|
|
||||||
document.write(html);
|
|
||||||
document.close();
|
|
||||||
} catch (e) {
|
|
||||||
error(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (document.readyState === "complete") {
|
|
||||||
rewrite();
|
|
||||||
} else {
|
|
||||||
window.addEventListener("load", e => {
|
|
||||||
if (e.isTrusted) rewrite();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
let eraser = {
|
|
||||||
tapped: null,
|
|
||||||
delKey: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
addEventListener("pagehide", ev => {
|
let eraser = {
|
||||||
if (!ev.isTrusted) return;
|
tapped: null,
|
||||||
|
delKey: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
addEventListener("pagehide", ev => {
|
||||||
|
if (!ev.isTrusted) return;
|
||||||
|
eraser.tapped = null;
|
||||||
|
eraser.delKey = false;
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
addEventListener("keyup", ev => {
|
||||||
|
if (!ev.isTrusted) return;
|
||||||
|
let el = eraser.tapped;
|
||||||
|
if (el && ev.code === "Delete" || ev.code === "Backspace") {
|
||||||
eraser.tapped = null;
|
eraser.tapped = null;
|
||||||
|
eraser.delKey = true;
|
||||||
|
let doc = el.ownerDocument;
|
||||||
|
let w = doc.defaultView;
|
||||||
|
if (w.getSelection().isCollapsed) {
|
||||||
|
let root = doc.body || doc.documentElement;
|
||||||
|
let posRx = /^(?:absolute|fixed)$/;
|
||||||
|
do {
|
||||||
|
if (posRx.test(w.getComputedStyle(el, '').position)) {
|
||||||
|
(eraser.tapped = el.parentNode).removeChild(el);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while ((el = el.parentNode) && el != root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
addEventListener("mousedown", ev => {
|
||||||
|
if (!ev.isTrusted) return;
|
||||||
|
if (ev.button === 0) {
|
||||||
|
eraser.tapped = ev.target;
|
||||||
eraser.delKey = false;
|
eraser.delKey = false;
|
||||||
}, false);
|
}
|
||||||
|
}, true);
|
||||||
|
|
||||||
addEventListener("keyup", ev => {
|
addEventListener("mouseup", ev => {
|
||||||
if (!ev.isTrusted) return;
|
if (!ev.isTrusted) return;
|
||||||
let el = eraser.tapped;
|
if (eraser.delKey) {
|
||||||
if (el && ev.code === "Delete" || ev.code === "Backspace") {
|
eraser.delKey = false;
|
||||||
eraser.tapped = null;
|
ev.preventDefault();
|
||||||
eraser.delKey = true;
|
ev.stopPropagation();
|
||||||
let doc = el.ownerDocument;
|
}
|
||||||
let w = doc.defaultView;
|
eraser.tapped = null;
|
||||||
if (w.getSelection().isCollapsed) {
|
}, true);
|
||||||
let root = doc.body || doc.documentElement;
|
|
||||||
let posRx = /^(?:absolute|fixed)$/;
|
|
||||||
do {
|
|
||||||
if (posRx.test(w.getComputedStyle(el, '').position)) {
|
|
||||||
(eraser.tapped = el.parentNode).removeChild(el);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while ((el = el.parentNode) && el != root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
addEventListener("mousedown", ev => {
|
|
||||||
if (!ev.isTrusted) return;
|
|
||||||
if (ev.button === 0) {
|
|
||||||
eraser.tapped = ev.target;
|
|
||||||
eraser.delKey = false;
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
addEventListener("mouseup", ev => {
|
|
||||||
if (!ev.isTrusted) return;
|
|
||||||
if (eraser.delKey) {
|
|
||||||
eraser.delKey = false;
|
|
||||||
ev.preventDefault();
|
|
||||||
ev.stopPropagation();
|
|
||||||
}
|
|
||||||
eraser.tapped = null;
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,8 +100,9 @@
|
||||||
"lib/CSP.js",
|
"lib/CSP.js",
|
||||||
"nscl/content/patchWindow.js",
|
"nscl/content/patchWindow.js",
|
||||||
"common/CapsCSP.js",
|
"common/CapsCSP.js",
|
||||||
"/nscl/common/RequestKey.js",
|
"nscl/common/RequestKey.js",
|
||||||
"content/DocumentCSP.js",
|
"content/DocumentCSP.js",
|
||||||
|
"nscl/content/NoscriptElements.js",
|
||||||
"content/onScriptDisabled.js",
|
"content/onScriptDisabled.js",
|
||||||
"content/staticNS.js",
|
"content/staticNS.js",
|
||||||
"content/PlaceHolder.js",
|
"content/PlaceHolder.js",
|
||||||
|
|
2
src/nscl
2
src/nscl
|
@ -1 +1 @@
|
||||||
Subproject commit 077b98985354ca42b9a73fd49d3c8c5b8b42ddfe
|
Subproject commit 48d590749688928dda8e27e7e1e4e388057f4836
|
Loading…
Reference in New Issue