Last active
December 25, 2022 19:13
-
-
Save pkillnine/c730ee294d8c3729209b2d654b53576c to your computer and use it in GitHub Desktop.
qutebrowser url rewriter userscript
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
#!/usr/bin/env python | |
#more ideas https://addons.mozilla.org/en-US/firefox/addon/redirectbypasser/ https://github.com/mozlima/redirectbypasser https://github.com/D4Vinci/AdflyUrlGrabber/blob/master/AdflyUrlGrabber.py | |
#todo: check the new url that is found. | |
from sys import argv | |
from os import environ | |
domains = { | |
'l.facebook.com' : 'https:\/\/l\.facebook\.com\/l\.php\?u\=(?P<actual_url>.+)\&h\=', | |
} | |
qute_url = environ['QUTE_URL'] | |
fifo_path = environ['QUTE_FIFO'] | |
def exec(cmd): | |
with open(fifo_path, 'w') as f: | |
f.write(cmd) | |
return | |
def open_url(url): | |
exec("open --tab --implicit {}".format(url)) | |
def message(msg): | |
exec('message-info "{}"'.format(msg)) | |
if __name__ == '__main__': | |
for domain in domains: | |
if domain not in qute_url: | |
open_url(qute_url) | |
exit() | |
import re | |
valid_url = re.match('https?://([\w\.]+)\/?', qute_url) | |
if valid_url: | |
domain = valid_url.group(1) | |
if domain in domains: | |
import urllib.parse | |
regex = domains[domain] | |
message('{} detected'.format(domain)) | |
unquoted_url = urllib.parse.unquote(qute_url) | |
converted_url = re.match(regex, unquoted_url).groupdict()['actual_url'] | |
open_url(converted_url) | |
else: | |
open_url(qute_url) |
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
#!/usr/bin/env python | |
#more ideas https://addons.mozilla.org/en-US/firefox/addon/redirectbypasser/ https://github.com/mozlima/redirectbypasser https://github.com/D4Vinci/AdflyUrlGrabber/blob/master/AdflyUrlGrabber.py | |
#todo: check the new url that is found. | |
from sys import argv | |
from os import environ | |
domains = { | |
'l.facebook.com' : 'https:\/\/l\.facebook\.com\/l\.php\?u\=(?P<actual_url>.+)\&h\=', | |
} | |
qute_url = environ['QUTE_URL'] | |
fifo_path = environ['QUTE_FIFO'] | |
def exec(cmd): | |
with open(fifo_path, 'w') as f: | |
f.write(cmd) | |
return | |
def open_url_current(url): | |
"""Open url in current tab""" | |
exec("open --implicit {}".format(url)) | |
def open_url_tab(url): | |
"""Open url in new tab""" | |
exec("open --implicit {}".format(url)) | |
def message(msg): | |
exec('message-info "{}"'.format(msg)) | |
def rewrite_url(): | |
for domain in domains: | |
if domain not in qute_url: | |
open_url(qute_url) | |
exit() | |
import re | |
valid_url = re.match('https?://([\w\.]+)\/?', qute_url) | |
if valid_url: | |
domain = valid_url.group(1) | |
if domain in domains: | |
import urllib.parse | |
regex = domains[domain] | |
message('{} detected'.format(domain)) | |
unquoted_url = urllib.parse.unquote(qute_url) | |
converted_url = re.match(regex, unquoted_url).groupdict()['actual_url'] | |
return converted_url | |
else: | |
return qute_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment