~chimo/dotfiles

f6dd9a26777b3f04edf72cdc5c5206c6fd984d3c — chimo 11 days ago a35ab3b
qutebrowser: Redirect youtube to inv.nadeko.net
M .config/qutebrowser/config.py => .config/qutebrowser/config.py +5 -2
@@ 22,7 22,7 @@ bind_chained("xJS", "set content.javascript.enabled false",
c.editor.command = ["foot", "-e", "vim", "{}"]

# The page(s) to open at the start.
c.url.start_pages = "https://home.brub.ca"
c.url.start_pages = "https://srht.chromic.org/~chimo/"

c.content.javascript.enabled = False
js_whitelist = [


@@ 32,7 32,10 @@ js_whitelist = [
    "*://*.brub.ca/*",
    "*://chromic.org/*",
    "*://*.chromic.org/*",
    "*://github.com/*"
    "*://github.com/*",
    "*://youtube.com/*",    # Youtube is only here because python redirectors
    "*://www.youtube.com/*" # crash the renderer, and greasemonkey scripts only
                            # work with JS enabled.
]

for site in js_whitelist:

A .config/qutebrowser/greasemonkey/youtube.user.js => .config/qutebrowser/greasemonkey/youtube.user.js +17 -0
@@ 0,0 1,17 @@
// ==UserScript==
// @name         youtube to yewtube / inv.nadeko.net
// @namespace    https://gist.github.com/bitraid/d1901de54382532a03b9b22a207f0417
// @version      1.0
// @description  youtube to yewtube
// @match        *://youtube.com/*
// @match        *://*.youtube.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
	'use strict';
	// top.location.hostname = "yewtu.be";
	top.location.hostname = "inv.nadeko.net";
})();


M .config/qutebrowser/pyconfig/redirectors.py => .config/qutebrowser/pyconfig/redirectors.py +24 -14
@@ 1,29 1,39 @@
# From here: https://gitlab.com/jgkamat/dotfiles/blob/master/qutebrowser/.config/qutebrowser/pyconfig/redirectors.py#L35

import operator, re, typing
from urllib.parse import urljoin
import operator

from qutebrowser.api import interceptor, message
from PyQt6.QtCore import QUrl

# Any return value other than a literal 'False' means we redirected
REDIRECT_MAP = {
	"reddit.com": operator.methodcaller('setHost', 'old.reddit.com'),
	"www.reddit.com": operator.methodcaller('setHost', 'old.reddit.com'),
    'reddit.com': operator.methodcaller('setHost', 'old.reddit.com'),
    'www.reddit.com': operator.methodcaller('setHost', 'old.reddit.com'),

    # Youtube redirection crashes the renderer for whatever reason...
    # Those redirects are done via greasemonkey script.
    #
    # Also, youtube video URLs have a ResourceType of `preload_frame` so that
    # needs to be whitelisted in the "Block..." if below if we want to try this
    # again.
    #
    #"youtube.com": operator.methodcaller('setHost', 'yewtu.be'),
    #"www.youtube.com": operator.methodcaller('setHost', 'yewtu.be'),
    #"youtube.com": operator.methodcaller('setHost', 'inv.nadeko.net'),
    #"www.youtube.com": operator.methodcaller('setHost', 'inv.nadeko.net'),
} # type: typing.Dict[str, typing.Callable[..., typing.Optional[bool]]]

def int_fn(info: interceptor.Request):
	"""Block the given request if necessary."""
	if (info.resource_type != interceptor.ResourceType.main_frame or
			info.request_url.scheme() in {"data", "blob"}):
		return
    """Block the given request if necessary."""
    if (info.resource_type != interceptor.ResourceType.main_frame or
            info.request_url.scheme() in {'data', 'blob'}):
        return

	url = info.request_url
	redir = REDIRECT_MAP.get(url.host())
    url = info.request_url
    redir = REDIRECT_MAP.get(url.host())

	if redir is not None and redir(url) is not False:
		message.info("Redirecting to " + url.toString())
		info.redirect(url)
    if redir is not None and redir(url) is not False:
        message.info('Redirecting to ' + url.toString())
        info.redirect(url)

interceptor.register(int_fn)


M .gitignore => .gitignore +1 -0
@@ 4,3 4,4 @@
!.config/qutebrowser/config.py
!.config/qutebrowser/userscripts
!.config/qutebrowser/pyconfig
!.config/qutebrowser/greasemonkey