From 789ee8d910a0ce9741e3712efe7eef2746a2bd1f Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 7 Jan 2023 12:52:46 -0500 Subject: [PATCH] Minor code review --- src/js/scriptlets/noscript-spoof.js | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/js/scriptlets/noscript-spoof.js b/src/js/scriptlets/noscript-spoof.js index 2e6f0fdf7..6c2898015 100644 --- a/src/js/scriptlets/noscript-spoof.js +++ b/src/js/scriptlets/noscript-spoof.js @@ -29,18 +29,18 @@ // https://github.com/gorhill/uMatrix/issues/232 // Force `display` property, Firefox is still affected by the issue. -(function() { - let noscripts = document.querySelectorAll('noscript'); +(( ) => { + const noscripts = document.querySelectorAll('noscript'); if ( noscripts.length === 0 ) { return; } - let redirectTimer, - reMetaContent = /^\s*(\d+)\s*;\s*url=(['"]?)([^'"]+)\2/i, - reSafeURL = /^https?:\/\//; + const reMetaContent = /^\s*(\d+)\s*;\s*url=(['"]?)([^'"]+)\2/i; + const reSafeURL = /^https?:\/\//; + let redirectTimer; - let autoRefresh = function(root) { - let meta = root.querySelector('meta[http-equiv="refresh"][content]'); + const autoRefresh = function(root) { + const meta = root.querySelector('meta[http-equiv="refresh"][content]'); if ( meta === null ) { return; } - let match = reMetaContent.exec(meta.getAttribute('content')); + const match = reMetaContent.exec(meta.getAttribute('content')); if ( match === null || match[3].trim() === '' ) { return; } let url; @@ -59,26 +59,26 @@ meta.parentNode.removeChild(meta); }; - let morphNoscript = function(from) { + const morphNoscript = function(from) { if ( /^application\/(?:xhtml\+)?xml/.test(document.contentType) ) { - let to = document.createElement('span'); + const to = document.createElement('span'); while ( from.firstChild !== null ) { to.appendChild(from.firstChild); } return to; } - let parser = new DOMParser(); - let doc = parser.parseFromString( + const parser = new DOMParser(); + const doc = parser.parseFromString( '' + from.textContent + '', 'text/html' ); return document.adoptNode(doc.querySelector('span')); }; - for ( let noscript of noscripts ) { - let parent = noscript.parentNode; + for ( const noscript of noscripts ) { + const parent = noscript.parentNode; if ( parent === null ) { continue; } - let span = morphNoscript(noscript); + const span = morphNoscript(noscript); span.style.setProperty('display', 'inline', 'important'); if ( redirectTimer === undefined ) { autoRefresh(span);