| |
@@ -938,12 +938,26 @@
|
| |
}
|
| |
|
| |
/**
|
| |
- * Removes noscript tags with name "librejs-path" leaving the inner content to load.
|
| |
+ * Force displaying <noscript> sections when there are blocked scripts.
|
| |
*/
|
| |
function remove_noscripts(html_doc){
|
| |
- for(var i = 0; i < html_doc.getElementsByName("librejs-path").length; i++){
|
| |
- if(html_doc.getElementsByName("librejs-path")[i].tagName == "NOSCRIPT"){
|
| |
- html_doc.getElementsByName("librejs-path")[i].outerHTML = html_doc.getElementsByName("librejs-path")[i].innerHTML;
|
| |
+
|
| |
+ var noscripts=html_doc.getElementsByTagName("noscript");
|
| |
+ var scripts_blocked = html_doc.documentElement.innerHTML.indexOf("LibreJS: script blocked") >= 0;
|
| |
+
|
| |
+ if (noscripts.length > 0){
|
| |
+ if (scripts_blocked){
|
| |
+ for(var i = 0; i < noscripts.length; i++){
|
| |
+ //Ignore noscripts with attribute "data-librejs-nodisplay"
|
| |
+ if (noscripts[i].attributes.getNamedItem("data-librejs-nodisplay") === null){
|
| |
+ console.log("LibreJS: blocked some scripts, displaying noscript #"+i)
|
| |
+ html_doc.getElementsByTagName("noscript")[i].outerHTML = noscripts[i].innerHTML;
|
| |
+ }
|
| |
+ }
|
| |
+ }
|
| |
+ for (var i = 0; i < html_doc.querySelectorAll('[data-librejs-display]').length; i++){
|
| |
+ console.log("LibreJS: displaying noscript, by site's request.")
|
| |
+ html_doc.querySelectorAll('[data-librejs-display]')[i].outerHTML = noscripts[i].innerHTML;
|
| |
}
|
| |
}
|
| |
|
| |
Most of that code is pretty straightforward, but the test I do to check if scripts were blocked is very ugly.