From c0a43b0d32e38aa3858644db20fc69a7b0c85e82 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 3 Oct 2021 09:46:24 -0400 Subject: [PATCH] Add refresh-defuser scriptlet To specifically defuse the reloading of a document through a meta "refresh" tag. Related feedback: - https://www.reddit.com/r/uBlockOrigin/comments/q0frv0/ As per solution from AdGuard: - https://www.reddit.com/r/uBlockOrigin/comments/q0frv0/while_reading_a_sports_article_i_was_redirected/hf7wo9v/ --- assets/resources/scriptlets.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index ba7d2dea3..5604ae4a0 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -723,6 +723,27 @@ })(); +/// refresh-defuser.js +// https://www.reddit.com/r/uBlockOrigin/comments/q0frv0/while_reading_a_sports_article_i_was_redirected/hf7wo9v/ +(function() { + const arg1 = '{{1}}'; + const defuse = ( ) => { + const meta = document.querySelector('meta[http-equiv="refresh" i][content]'); + if ( meta === null ) { return; } + const s = arg1 === '' || arg1 === '{{1}}' + ? meta.getAttribute('content') + : arg1; + const ms = Math.max(parseFloat(s) || 0, 0) * 1000; + setTimeout(( ) => { window.stop(); }, ms); + }; + if ( document.readyState === 'loading' ) { + document.addEventListener('DOMContentLoaded', defuse, { once: true }); + } else { + defuse(); + } +})(); + + /// remove-attr.js /// alias ra.js (function() {