Last active
June 27, 2023 09:01
-
-
Save voodoocode/d1b17a76260d670bea0d5eb901d861fc to your computer and use it in GitHub Desktop.
Checks page for url change, then add target blank attribute to all external links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Open feddit links in new tab | |
// @version 0.1 | |
// @description Opens feddit links in new tab | |
// @author voodoocode | |
// @match feddit.de/* | |
// @icon https://feddit.de/pictrs/image/uI7Q7MuePp.png | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
let pageURLCheckTimer = setInterval ( | |
function () { | |
if (this.lastPathStr !== location.pathname | |
|| this.lastQueryStr !== location.search | |
|| this.lastPathStr === null | |
|| this.lastQueryStr === null | |
) { | |
this.lastPathStr = location.pathname; | |
this.lastQueryStr = location.search; | |
main(); | |
} | |
} | |
, 200 | |
); | |
function main() { | |
setTimeout(()=> { | |
let as = document.querySelectorAll('a[href^="http"]') | |
as.forEach(function (a) { | |
a.setAttribute('target', '_blank') | |
}) | |
}, 500); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment