diff options
author | Jesús <heckyel@hyperbola.info> | 2019-12-07 18:01:31 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2019-12-07 18:01:31 -0500 |
commit | ebeb422c79294ebfaacbaef957586c89642ca107 (patch) | |
tree | 2ae2c0e495fb03a87113653be0b7b22b22f49c9a | |
parent | a4a5c3ae12cc495b5e1e114e835cf58b72737943 (diff) | |
download | book-ebeb422c79294ebfaacbaef957586c89642ca107.tar.lz book-ebeb422c79294ebfaacbaef957586c89642ca107.tar.xz book-ebeb422c79294ebfaacbaef957586c89642ca107.zip |
[twitter_to_nitter] improve regex and fix other browser invoke function
-rw-r--r-- | scripts-greasemonkey/twitter_to_nitter.user.js | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/scripts-greasemonkey/twitter_to_nitter.user.js b/scripts-greasemonkey/twitter_to_nitter.user.js index b8342ad..a9b5538 100644 --- a/scripts-greasemonkey/twitter_to_nitter.user.js +++ b/scripts-greasemonkey/twitter_to_nitter.user.js @@ -24,10 +24,10 @@ let consoleCSS = 'background: #000; color: #00FF00; padding: 0px 7px; border: 1p // Do the actual rewrite function rewriteLinks() { - for (var i = 0; i < document.links.length; i++) { - var elem = document.links[i]; - if (elem.href.match(/(mobile\.)?twitter\.com\/([^&#]+)/i)) { - elem.href='https://' + instance + '/' + RegExp.$2; + for (let i = 0; i < document.links.length; i++) { + let elem = document.links[i]; + if (elem.href.match(/http(s|)\:\/\/(mobile[.]|www[.]|)(twitter[.]com)\/([^&#]+.*$)/i)) { + elem.href='https://' + instance + '/' + RegExp.$4; } } statuscheck() @@ -38,4 +38,6 @@ function statuscheck(){ console.log("%cUSERSCRIPT | " + GM_info.script.name + " " + GM_info.script.version + " | successfully initialized", consoleCSS); } -rewriteLinks(); +window.addEventListener('load', () => { + rewriteLinks(); +}); |