Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Commit

Permalink
finalize fix to #319 -- redirect if meta/refresh found in noscript tags
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Dec 5, 2017
1 parent 5c340e8 commit a90e5cc
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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);
}
};
Expand Down

0 comments on commit a90e5cc

Please sign in to comment.