From a90e5cc7b49224d5ee7f3ad3d53be3367be5eb15 Mon Sep 17 00:00:00 2001 From: gorhill Date: Tue, 5 Dec 2017 16:09:30 -0500 Subject: [PATCH] finalize fix to #319 -- redirect if meta/refresh found in noscript tags --- src/js/contentscript.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/js/contentscript.js b/src/js/contentscript.js index ae4d8e8..a60a0d2 100644 --- a/src/js/contentscript.js +++ b/src/js/contentscript.js @@ -502,10 +502,27 @@ var nodeListsAddedHandler = function(nodeLists) { var noscripts = document.querySelectorAll('noscript'); if ( noscripts.length === 0 ) { return; } + var redirectTimer, + reMetaContent = /^\s*(\d+)\s*;\s*url=(['"]?)([^'"]+)\2/; + + var autoRefresh = function(root) { + var meta = root.querySelector('meta[http-equiv="refresh"][content]'); + if ( meta === null ) { return; } + var match = reMetaContent.exec(meta.getAttribute('content')); + if ( match === null || match[3].trim() === '' ) { return; } + redirectTimer = setTimeout( + function() { + location.assign(match[3]); + }, + parseInt(match[1], 10) * 1000 + 1 + ); + meta.parentNode.removeChild(meta); + }; + var renderNoscriptTags = function(response) { if ( response !== true ) { return; } var parser = new DOMParser(); - var doc, parent, span, meta; + var doc, parent, span; for ( var noscript of noscripts ) { parent = noscript.parentNode; if ( parent === null ) { continue; } @@ -515,6 +532,9 @@ var nodeListsAddedHandler = function(nodeLists) { ); span = document.adoptNode(doc.querySelector('span')); span.style.setProperty('display', 'inline', 'important'); + if ( redirectTimer === undefined ) { + autoRefresh(span); + } parent.replaceChild(span, noscript); } };