From 21175a8267aae9d88652fac832a90266d5484cd5 Mon Sep 17 00:00:00 2001 From: hackademix Date: Tue, 30 Apr 2019 13:31:49 +0200 Subject: Display NOSCRIPT elements when scripts are blocked or the data-librejs-display attribute is present. --- main_background.js | 64 +++++++++++++++++++++++++++++++++++++++--------- test/spec/LibreJSSpec.js | 24 ++++++++++++++++++ 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/main_background.js b/main_background.js index f9e7521..0a1a2e9 100644 --- a/main_background.js +++ b/main_background.js @@ -938,16 +938,55 @@ function doc2HTML(doc) { } /** -* Removes noscript tags with name "librejs-path" leaving the inner content to load. +* Shortcut to create a correctly namespaced DOM HTML elements */ -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; - } - } +function createHTMLElement(doc, name) { + return doc.createElementNS("http://www.w3.org/1999/xhtml", name); +} - return doc2HTML(html_doc); +/** +* Replace any element with a span having the same content (useful to force +* NOSCRIPT elements to visible the same way as NoScript and uBlock do) +*/ +function forceElement(doc, element) { + let replacement = createHTMLElement(doc, "span"); + replacement.innerHTML = element.innerHTML; + element.replaceWith(replacement); + return replacement; +} + +/** +* Forces displaying any element having the "data-librejs-display" attribute and +*