FIX: Ensure splash screen `<noscript>` is loaded for legacy browsers (#17413)

Previously we would only expand the main `<noscript>` element for older browsers. This commit ensures that we expand all noscript elements on the page, including the one used by the splashscreen to hide itself on the no-js view.
This commit is contained in:
David Taylor 2022-07-11 09:07:10 +01:00 committed by GitHub
parent a94dee31c4
commit e62730a4c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 12 deletions

View File

@ -24,21 +24,23 @@
} }
document.getElementsByTagName("body")[0].className += " crawler"; document.getElementsByTagName("body")[0].className += " crawler";
var mainElement = document.getElementById("main");
var noscriptElements = document.getElementsByTagName("noscript"); var noscriptElements = document.getElementsByTagName("noscript");
// find the element with the "data-path" attribute set // find the element with the "data-path" attribute set
for (var i = 0; i < noscriptElements.length; ++i) { for (var i = noscriptElements.length - 1; i >= 0; i--) {
if (noscriptElements[i].getAttribute("data-path")) { var element = noscriptElements[i];
// noscriptElements[i].innerHTML contains encoded HTML, so we need to access // noscriptElements[i].innerHTML contains encoded HTML, so we need to access
// the childNodes instead. Browsers seem to split very long content into multiple // the childNodes instead. Browsers seem to split very long content into multiple
// text childNodes. // text childNodes.
var result = ""; var result = "";
for (var j = 0; j < noscriptElements[i].childNodes.length; j++) { for (var j = 0; j < element.childNodes.length; j++) {
result += noscriptElements[i].childNodes[j].nodeValue; result += element.childNodes[j].nodeValue;
} }
mainElement.outerHTML = result; if (element.getAttribute("data-path")) {
break; document.getElementById("main").outerHTML = result;
} else {
element.outerHTML = result;
} }
} }