41 KiB
Qutebrowser Configuration
- Import
- Auto Config
- General config
- Qt
- Content
- Editor
- Downloads
- File Select
- Colors
- Fonts
- Input
- New Instance Options
- Spell Check
- Status Bar
- Tabs
- Urls and Search Engines
- Normal Bindings
- Custom Bindings
- Userscripts
- Create a new password
- Download Youtube Video
- Password_fill_rc
- Password_fill_ESRF
- OTP_fill_ESRF
- Org-Capture
- Org-Protocol-Capture-HTML
- Open Bookmark with Linkding
- Add Url to Linkding
- Add Url to Buku using Rofi
- Add Url to Buku without asking for information
- Download with aria2c
- Download with aria2c on the Homelab
- Save to PNG
- Get OTP number
- Download AES video
- Display URL as a QRcode
- Greasemonkey Scripts
Import
from qutebrowser.config.configfiles import ConfigAPI
from qutebrowser.config.config import ConfigContainer
import sys, os
Auto Config
Do not load config set with :set command in qutebrowser.
config.load_autoconfig(True)
General config
c.aliases = {'w': 'session-save', 'q': 'quit', 'wq': 'quit --save'}
c.auto_save.session = False
c.backend = 'webengine'
c.confirm_quit = ['downloads', 'multiple-tabs']
c.aliases['paywall'] = "open https://www.google.com/search?q=cache:{url}"
Qt
Linked to issue.
c.qt.workarounds.remove_service_workers = True
Content
c.content.autoplay = False
c.content.notifications.enabled = False
c.content.geolocation = 'ask'
c.content.javascript.alert = True
c.content.pdfjs = False
c.content.proxy = 'system'
c.content.blocking.method = 'both'
c.content.blocking.adblock.lists = ['https://easylist.to/easylist/easylist.txt', 'https://easylist.to/easylist/easyprivacy.txt', 'https://secure.fanboy.co.nz/fanboy-cookiemonster.txt']
Editor
c.editor.command = ['kitty', '--class', 'terminal,Floating', '-e', 'nvim', '{}']
Downloads
c.downloads.location.directory = '$HOME/Downloads/'
c.downloads.location.prompt = True
c.downloads.location.remember = True
c.downloads.location.suggestion = 'path'
c.downloads.position = 'bottom'
c.downloads.remove_finished = 10000
# c.downloads.open_dispatcher = 'linkhandler'
File Select
c.fileselect.handler = "external"
c.fileselect.single_file.command = ['kitty', '--class', 'floating', '-e', 'yazi', '--chooser-file', '{}']
c.fileselect.multiple_files.command = ['kitty', '--class', 'floating', '-e', 'yazi', '--chooser-file', '{}']
Colors
# c.colors.webpage.darkmode.enabled = True
Fonts
c.fonts.default_family = ["Hack Nerd Font Mono", "DejaVu Sans Mono", "Monaco"]
c.fonts.prompts = '10pt monospace'
c.fonts.statusbar = '10pt monospace'
Input
c.input.insert_mode.auto_enter = True
# Very annoying when automatically leave insert mode
c.input.insert_mode.auto_leave = False
c.input.insert_mode.auto_load = False
c.input.insert_mode.plugins = True
New Instance Options
c.new_instance_open_target = 'tab'
c.new_instance_open_target_window = 'last-focused'
Spell Check
c.spellcheck.languages = ['en-US', 'fr-FR']
Status Bar
# Hide the statusbar unless a message is shown.
c.statusbar.position = 'bottom'
# List of widgets displayed in the statusbar.
# Valid values:
# - url: Current page URL.
# - scroll: Percentage of the current page position like `10%`.
# - scroll_raw: Raw percentage of the current page position like `10`.
# - history: Display an arrow when possible to go back/forward in history.
# - tabs: Current active tab, e.g. `2`.
# - keypress: Display pressed keys when composing a vi command.
# - progress: Progress bar for the current page loading.
c.statusbar.widgets = ['keypress', 'url', 'scroll', 'history', 'progress']
Tabs
# Open new tabs (middleclick/ctrl+click) in the background.
c.tabs.background = True
# Mouse button with which to close tabs.
c.tabs.close_mouse_button = 'right'
# How to behave when the last tab is closed.
c.tabs.last_close = 'ignore'
# Switch between tabs using the mouse wheel.
c.tabs.mousewheel_switching = False
# Position of new tabs opened from another tab.
# Valid values:
# - prev: Before the current tab.
# - next: After the current tab.
# - first: At the beginning.
# - last: At the end.
c.tabs.new_position.related = 'next'
# Position of new tabs which aren't opened from another tab.
# Valid values:
# - prev: Before the current tab.
# - next: After the current tab.
# - first: At the beginning.
# - last: At the end.
c.tabs.new_position.unrelated = 'last'
# Position of the tab bar.
c.tabs.position = 'left'
# Which tab to select when the focused tab is removed.
c.tabs.select_on_remove = 'next'
# Width (in pixels or as percentage of the window) of the tab bar if it's vertical.
c.tabs.width = 30
# Wrap when changing tabs.
c.tabs.wrap = False
Urls and Search Engines
c.url.searchengines = {
'DEFAULT': 'https://www.duckduckgo.org/?q={}',
'wi': 'https://en.wikipedia.org/wiki/Special:Search?search={}',
'go': 'https://www.google.com/search?q={}',
'gc': 'https://scholar.google.fr/scholar?hl=fr&as_sdt=0%2C5&q={}&btnG=',
'gm': 'https://www.google.com/maps/search/{}/',
'gh': 'https://github.com/search?q={}',
'yt': 'https://www.youtube.com/results?search_query={}',
're': 'https://www.reddit.com/search?q={}',
'lb': 'http://gen.lib.rus.ec/search.php?req={}',
'la': 'http://gen.lib.rus.ec/scimag/index.php?s={}',
'sm': 'https://www.openstreetmap.org/search?query={}',
'am': 'https://www.amazon.fr/s?k={}',
'md': 'https://fr.mathworks.com/help/search.html?qdoc={}&submitsearch=',
'tf': 'https://www.deepl.com/en/translator#en/fr/{}',
'te': 'https://www.deepl.com/en/translator#fr/en/{}',
'lb': 'https://www.leboncoin.fr/recherche?text={}',
}
c.url.start_pages = ['https://homepage.tdehaeze.xyz/']
c.url.default_page = 'https://homepage.tdehaeze.xyz/'
Normal Bindings
Zooming
config.bind('+', 'zoom-in')
config.bind('-', 'zoom-out')
config.bind('=', 'zoom')
Inputs blocks
config.bind(';t', 'hint inputs')
config.bind('gi', 'hint inputs --first')
Opening New Window
config.bind('<Ctrl-N>', 'open -w')
History
config.bind('H', 'back')
config.bind('L', 'forward')
Move tabs around
config.bind('d', 'tab-close')
config.bind('<', 'tab-move -')
config.bind('>', 'tab-move +')
config.bind('gO', 'tab-give') # Open current tab in a new window
config.bind('J', 'tab-next')
config.bind('K', 'tab-prev')
Bookmarks and Quickmark
config.bind('M', 'bookmark-add')
config.bind('m', 'quickmark-save')
Open New Pages/Tabs
config.bind('o', 'cmd-set-text -s :open')
config.bind('O', 'cmd-set-text -s :open -t')
Open new page/tab with clipboard content
config.bind('pp', 'open -- {clipboard}')
config.bind('pP', 'open -t -- {clipboard}')
Link Hinting
config.bind('f', 'hint')
config.bind('F', 'hint all tab')
Yanking url
config.bind('yy', 'yank')
Go to specific websites
config.bind('gy', 'open -t https://www.youtube.com/feed/subscriptions')
config.bind('gf', 'open -t https://rss.tdehaeze.xyz/')
config.bind('gr', 'open -t https://www.reddit.com/')
config.bind('gh', 'open -t https://homepage.tdehaeze.xyz/')
config.bind('ge', 'open -t http://intranet.esrf.fr/')
config.bind('gc', 'open -t https://calendar.esrf.fr/')
config.bind('gn', 'open -t https://node-red.tdehaeze.xyz/ui/#!/1')
config.bind('gN', 'open -t https://node-red.pic05.eu/ui/#!/3')
config.bind('gb', 'open -t qute://bookmarks')
config.bind('gH', 'open -t qute://history')
config.bind('gs', 'open -t qute://settings')
Quit.
config.bind('D', 'close')
Custom Bindings
c.aliases['proxy_homelab_on'] = 'set content.proxy socks5://localhost:8080'
c.aliases['proxy_homelab_off'] = 'config-unset content.proxy'
c.aliases['proxy_esrf_on'] = 'set content.proxy socks5://localhost:8081'
c.aliases['proxy_esrf_off'] = 'config-unset content.proxy'
Use Pass to fill password and username (configuration is done in ~/.config/qutebrowser/password_fill_rc)
c.aliases['Password_Fill'] = 'spawn --userscript password_fill'
config.bind(',p', 'Password_Fill')
Create a Password for the current website
c.aliases['Password_Add'] = 'spawn --userscript ~/.config/qutebrowser/userscripts/add-passowrd.sh'
config.bind(',P', 'Password_Add')
c.aliases['Password_ESRF'] = 'spawn --userscript password_ESRF'
config.bind(',e', 'Password_ESRF')
c.aliases['OTP_ESRF'] = 'spawn --userscript OTP_ESRF'
config.bind(',3', 'OTP_ESRF')
Get Two Factor Authentication number.
c.aliases['OTP'] = 'spawn --userscript ~/.config/qutebrowser/userscripts/get-otp.sh'
config.bind(',2', 'OTP')
Open current page with Firefox:
c.aliases['Firefox'] = 'spawn --detach firefox-developer-edition --new-tab {url}'
config.bind(',f', 'Firefox')
Open Youtube video using mpv
c.aliases['MPV_view'] = 'spawn --detach mpv --force-window yes {url}'
config.bind(',m', 'MPV_view')
c.aliases['MPV_view_hint'] = 'hint links spawn --detach mpv --force-window yes {hint-url}'
config.bind(';m', 'MPV_view_hint')
Download Youtube video / entire playlist
c.aliases['Download_Youtube'] = 'spawn --userscript ~/.config/qutebrowser/userscripts/yt-download.sh {url}'
config.bind(',v', 'Download_Youtube')
c.aliases['Download_Youtube_hint'] = 'hint links spawn --userscript ~/.config/qutebrowser/userscripts/yt-download.sh {hint-url}'
config.bind(';v', 'Download_Youtube_hint')
Add page to Bookmarks using linkding
c.aliases['Bookmark_Add'] = 'spawn --userscript ~/.config/qutebrowser/userscripts/linkding-add.sh'
config.bind(',b', 'Bookmark_Add')
Download with aria2c
c.aliases['Download_Local'] = 'hint links spawn --userscript ~/.config/qutebrowser/userscripts/aria2c-add.sh {hint-url}'
config.bind(',d', 'Download_Local')
c.aliases['Download_Homelab'] = 'hint links spawn --userscript ~/.config/qutebrowser/userscripts/aria2c-add-homelab.sh {hint-url}'
config.bind(',D', 'Download_Homelab')
Open bookmark using linkding
c.aliases['Open_Bookmark'] = 'spawn --userscript ~/.config/qutebrowser/userscripts/linkding-open.sh'
config.bind(',o', 'Open_Bookmark')
Open with linkhandler
c.aliases['Open_Default'] = 'hint links spawn --detach linkhandler {hint-url}'
config.bind(',O', 'Open_Default')
Org Capture
c.aliases['Org_Capture'] = 'spawn --userscript ~/.config/qutebrowser/userscripts/org-capture.sh'
config.bind(',r', 'Org_Capture')
c.aliases['Org_Capture_hint'] = 'hint links userscript ~/.config/qutebrowser/userscripts/org-capture.sh'
config.bind(';R', 'Org_Capture_hint')
Screenshot of webpage to png
c.aliases['Save_PNG'] = 'spawn --userscript html-to-png.sh'
config.bind(',S', 'Save_PNG')
Download AES video
c.aliases['Download_AES'] = 'spawn --userscript aes-download.sh'
config.bind(',E', 'Download_AES')
See Amazon price history using CamelCamelCamel
c.aliases['CamelCamelCamel'] = 'open -t https://fr.camelcamelcamel.com/search?sq={url}'
config.bind(',A', 'CamelCamelCamel')
Org Roam Entry for the current page
c.aliases['Org_Roam_Save'] = "open javascript:void(location.href='org-protocol://roam-ref?template=r&ref='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title))"
config.bind(',R', 'Org_Roam_Save')
Display Current URL as a QRcode (useful to open in on a phone).
c.aliases['QRcode'] = "spawn --userscript ~/.config/qutebrowser/userscripts/url-to-qrcode.sh {url}"
config.bind(',q', 'QRcode')
Userscripts
Here is the documentation related to userscripts.
Create a new password
url=$(echo "$QUTE_URL" | awk -F[/:] '{print $4}' | rofi -i -p "URL" -dmenu -lines 1)
username=$(echo -e "dehaeze.thomas@gmail.com\nthomas.dehaeze@esrf.fr\ntdehaeze" | rofi -p "Username" -dmenu -lines 5)
password=$(rofi -p "Password" -dmenu -password -lines 1)
if [ -z "$url" ] || [ -z "$username" ] || [ -z "$password" ]; then
dunstify --urgency=critical "Pass" "Failed to Add Password"
else
echo -e "$password\nlogin: $username\nurl: $QUTE_URL" > /tmp/add-password.txt
pass insert --multiline "$url/$username" < /tmp/add-password.txt;
rm /tmp/add-password.txt
dunstify "Pass " "Password Added"
fi
Download Youtube Video
cd ~/Documents/to-watch/ || exit;
if [[ "$1" == *"list"* ]]; then
choice=$(echo -e "Video\nPlaylist" | rofi -dmenu -only-match -i)
fi
if [ -n "$choice" ] && [ "$choice" = "Playlist" ]; then
dunstify --replace=19243 "Youtube " "Downloading Playlist...";
youtube-dl -i -f 'bestvideo[height<=720]+bestaudio/best[height<=720]' "$1" -o "%(playlist_title)s/%(playlist_index)s-%(title)s.%(ext)s" && \
dunstify --replace=19243 "Youtube " "Downloaded" || \
dunstify --replace=19243 --urgency=critical "Youtube " "Failed to download"
else
dunstify --replace=19243 "Youtube " "Downloading Video...";
youtube-dl --no-playlist -f 'bestvideo[height<=720]+bestaudio/best[height<=720]' "$1" && \
dunstify --replace=19243 "Youtube " "Downloaded" || \
dunstify --replace=19243 --urgency=critical "Youtube " "Failed to download"
fi
Password_fill_rc
# Show all password fields in the menu
query_entries() {
# safe queried url for choose_entry
# the subdomains are removed
export queried_url=$(expr match ".$1" '.*\.\(.*\..*\)')
mapfile -t files < <(find -L "$PREFIX" -iname '*.gpg' -printf '%P\n' |sed 's,\.gpg$,,')
}
# Even if there is only one entry, always show a menu
# for user confirmation.
choose_entry() {
MENU_COMMAND=(
rofi -dmenu
-p "qutebrowser> "
-filter "$queried_url"
-mesg $'Pick a password entry for <b>'"${QUTE_URL//&/&}"'</b>'
)
file=$( printf "%s\n" "${files[@]}" | "${MENU_COMMAND[@]}" )
}
Password_fill_ESRF
echo "insert-text $(pass esrf.fr/dehaeze | head -n 1) ;; cmd-later 100 fake-key <enter>" >> "$QUTE_FIFO"
OTP_fill_ESRF
echo "insert-text $(pass otp totp-esrf) ;; cmd-later 100 fake-key <enter>" >> "$QUTE_FIFO"
Org-Capture
readonly CAPTURE_SCRIPT=~/.config/qutebrowser/userscripts/org-protocol-capture-html.sh
if [[ "$QUTE_MODE" = "hints" ]]; then
# if we start with hints, we juste want to capture the URL
$CAPTURE_SCRIPT --template "pu" --url "${QUTE_URL}"
elif [[ -n "$QUTE_SELECTED_TEXT" ]]; then
# if text is selected, we want to capture the text
$CAPTURE_SCRIPT --template "pt" --heading "${QUTE_TITLE}" --url "${QUTE_URL}" "${QUTE_SELECTED_TEXT}"
else
# if no text is selected, we want to capture the url
$CAPTURE_SCRIPT --template "pu" --heading "${QUTE_TITLE}" --url "${QUTE_URL}"
fi
Org-Protocol-Capture-HTML
Defaults
heading="link"
template="pu"
url="https://google.com/"
Functions
function debug {
if [[ -n $debug ]]
then
function debug {
echo "DEBUG: $@" >&2
}
debug "$@"
else
function debug {
true
}
fi
}
function die {
echo "$@" >&2
exit 1
}
function urlencode {
python -c "
from __future__ import print_function
try:
from urllib import quote # Python 2
except ImportError:
from urllib.parse import quote # Python 3
import sys
print(quote(sys.stdin.read()[:-1], safe=''))"
}
Documentation
function usage {
cat <<EOF
$0 [OPTIONS] [HTML]
html | $0 [OPTIONS]
Send HTML to Emacs through org-protocol, passing it through Pandoc to
convert HTML to Org-mode. HTML may be passed as an argument or
through STDIN. If only URL is given, it will be downloaded and its
contents used.
Options:
-h, --heading HEADING Heading
-t, --template TEMPLATE org-capture template key (default: pu)
-u, --url URL URL
--debug Print debug info
--help I need somebody!
EOF
}
Arguments
args=$(getopt -n "$0" -o dh:rt:u: -l debug,help,heading:,template:,url: -- "$@") \
|| die "Unable to parse args. Is getopt installed?"
eval set -- "$args"
while true
do
case "$1" in
-d|--debug)
debug=true
debug "Debugging on"
;;
--help)
usage
exit
;;
-h|--heading)
shift
heading="$1"
;;
-t|--template)
shift
template="$1"
;;
-u|--url)
shift
url="$1"
;;
--)
# Remaining args
shift
rest=("$@")
break
;;
esac
shift
done
debug "ARGS: $args"
debug "Remaining args: ${rest[@]}"
Get HTML
if [[ -n $@ ]]
then
debug "Text from args"
body="$@"
fi
URL-encode
heading=$(urlencode <<<"$heading") || die "Unable to urlencode heading."
url=$(urlencode <<<"$url") || die "Unable to urlencode URL."
body=$(urlencode <<<"$body") || die "Unable to urlencode text."
Send to Emacs
emacsclient "org-protocol://capture?template=$template&url=$url&title=$heading&body=$body"
Open Bookmark with Linkding
# Verify that environment variable are set
if [[ -z "${LINKDING_URL}" ]]; then
LINKDING_URL=$(pass nas/linkding_url)
fi
if [[ -z "${LINKDING_TOKEN}" ]]; then
LINKDING_TOKEN=$(pass nas/linkding_token)
fi
curl -H "Authorization: Token ${LINKDING_TOKEN}" ${LINKDING_URL}/api/bookmarks/ | jq '.results[] | "\(.title) - \(.url) - [#\((.tag_names | join(", #")))]"' -r | rofi -dmenu -i -no-custom | grep -Eo 'https?://[^ ]+' | head -1 | xargs -I {} echo "open -t {}" >> "$QUTE_FIFO"
Add Url to Linkding
# Verify that environment variable are set
if [[ -z "${LINKDING_URL}" ]]; then
LINKDING_URL=$(pass nas/linkding_url)
fi
if [[ -z "${LINKDING_TOKEN}" ]]; then
LINKDING_TOKEN=$(pass nas/linkding_token)
fi
title=$(echo "$QUTE_TITLE" | rofi -p "Title" -dmenu -lines 1)
existing_tags=$(curl -H "Authorization: Token ${LINKDING_TOKEN}" ${LINKDING_URL}/api/tags/ | jq '.results[].name' -r | rofi -multi-select -p "Existing tags" -dmenu)
new_tags=$(rofi -p "New tags" -dmenu)
formated_tags=$(echo $existing_tags $new_tags | sed -E 's/(\w+)/"\1"/g;s/\s/,/g')
curl -H "Authorization: Token ${LINKDING_TOKEN}" -H "Content-Type: application/json" -d "{\"url\": \"$QUTE_URL\", \"title\": \"$title\", \"tag_names\": [$formated_tags]}" ${LINKDING_URL}/api/bookmarks/ && \
dunstify "Linkding" " Bookmark Added" || \
dunstify --urgency=critical "Linkding" "Failed"
Add Url to Buku using Rofi
title=$(echo "$QUTE_TITLE" | rofi -p "Title" -dmenu -lines 1)
tags=$(buku -t --nc --np | sed -e 's/\s*[[:digit:]]*\.\s*\(.*\)\s*([[:digit:]]*)\s*/\1/' -e '/^\s*$/d' | sort | uniq | rofi -multi-select -p "Tags" -dmenu | tr "\n" "," | sed 's/\s*,\s*$//')
buku --add "$QUTE_URL" --tag "$tags" --title "$title" && \
dunstify "Buku" "Bookmark Added" || \
dunstify --urgency=critical "Buku" " Bookmark Added"
Add Url to Buku without asking for information
buku --add $QUTE_URL --title "$QUTE_TITLE" && \
dunstify "Buku" "📑 Bookmark Added"
Download with aria2c
aria2p add "$1" && \
dunstify "Aria2" "Download Started" || \
dunstify "Aria2" "Error"
Download with aria2c on the Homelab
dl-add $(echo "$1" | sed 's/\&af=.*$//g') && \
dunstify "Aria2" "Download Started" || \
dunstify "Aria2" "Error"
Save to PNG
filename=$(rofi -p "filename" -dmenu -lines 1)
if [ -n "filename" ]; then
cd ~/Cloud/pictures/screenshots/ && \
firefox-developer-edition -P default -headless --screenshot "$filename.png" "$QUTE_URL" && \
dunstify "Screenshot" "Taken successfully"
fi
Get OTP number
passname=$(ls ~/.local/share/pass/totp-* | xargs -n 1 basename | sed -e 's/\..*$//' | rofi -p "TOPT" -dmenu)
if [ -n "$passname" ]; then
otpnumber=`pass otp $passname`
echo $otpnumber | xsel -ib
dunstify 'OTP' "$otpnumber" &
fi
Download AES video
m3u8_path=`curl -L -s "$QUTE_URL" | pcregrep -o1 "file = \"\/(.*aes.*mp4)\""`
if [ -z "$m3u8_path" ]; then
dunstify --urgency=critical "Qutebrowser" "No m3u8 playlist found"
else
dunstify "Qutebrowser" "Downloads..." && \
cd ~/Downloads/ && \
ffmpeg -user_agent "Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0" -referer "$QUTE_URL" -i "https://cdn2.digitellinc.com/play/_definst_/mp4:$m3u8_path/playlist.m3u8" -c copy "$QUTE_TITLE.mp4" && \
dunstify "Qutebrowser" "$QUTE_TITLE Downloaded"
fi
Display URL as a QRcode
qrencode -o /tmp/qrcode.png "$1" && nsxiv /tmp/qrcode.png
Greasemonkey Scripts
Skip Youtube ads
https://github.com/qutebrowser/qutebrowser/issues/6480 https://greasyfork.org/en
// ==UserScript==
// @name Disable YouTube Video Ads
// @namespace DisableYouTubeVideoAds
// @version 1.5.42
// @license AGPLv3
// @author jcunews
// @description Disable YouTube video & screen based ads at home page, and right before or in the middle of the main video playback. Also disable YouTube's anti-adblocker popup dialog. For new YouTube layout (Polymer) only.
// @website https://greasyfork.org/en/users/85671-jcunews
// @include https://www.youtube.com/*
// @grant unsafeWindow
// @run-at document-start
// ==/UserScript==
((window, disableAnnotations, fn) => {
//===== CONFIG BEGIN =====
disableAnnotations = true;
//===== CONFIG END =====
fn = (a, ipse, haia, hca, rpo, et) => {
if ((a = document.scripts[document.scripts.length - 1]) && (a.id === "dyvaUjs")) a.remove();
et = document.styleSheetSetsz ? "beforescriptexecute" : false; //Firefox workaround
JSON.parse_dyva = JSON.parse;
JSON.parse = function(a) {
var m, z;
if (rpo) {
a = rpo; //JSON.parse_dyva(a); //from xhr/fetch
try {
if (a.forEach) {
a.forEach((p, a) => {
if (p.player && p.player.args && (p.player.args.raw_player_response || p.player.args.player_response)) {
patchPlayerResponse(a = p.player_response_);
if (p.player.args.raw_player_response) {
p.raw_player_response = JSON.stringify(a)
} else p.player_response = JSON.stringify(a)
} else if (p.playerResponse) {
patchPlayerResponse(p.playerResponse);
}
});
} else patchPlayerResponse(a);
} catch(z) {}
rpo = null;
} else if ((a = JSON.parse_dyva(a)).playerResponse) patchPlayerResponse(a.playerResponse);
return a;
};
var ftc = window.fetch_dyva = window.fetch;
window.fetch = function(u) {
if (u) {
if (u.substr && /\/v1\/player\/ad_break/.test(u)) return new Promise(() => {});
if (u.url && u.url.substr && /\/v1\/player\/ad_break/.test(u.url)) return new Promise(() => {});
}
return ftc.apply(this, arguments);
};
var rj = Response.prototype.json_dyva = Response.prototype.json;
Response.prototype.json = function() {
var rs = this, p = rj.apply(this, arguments), pt = p.then;
p.then = function(fn) {
var fn_ = fn;
fn = function(j) {
if (/\/v1\/player\?/.test(rs.url)) rpo = j;
if ("function" === typeof fn_) return fn_.apply(this, arguments);
};
return pt.apply(this, arguments);
};
return p;
};
var rt = Response.prototype.text;
Response.prototype.text = function() {
var rs = this, p = rt.apply(this, arguments), pt = p.then;
p.then = function(fn) {
var fn_ = fn;
fn = function(t) {
if (/\/v1\/player\?/.test(rs.url)) rpo = JSON.parse_dyva(t);
if ("function" === typeof fn_) return fn_.apply(this, arguments);
};
return pt.apply(this, arguments);
};
return p;
};
window.XMLHttpRequest.prototype.open_dyva = window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function(mtd, url) {
if (!(/get_midroll_info/).test(url) && !((/^\/watch/).test(location.pathname) && (/get_video_info/).test(url))) {
this.url_dyva = url;
return this.open_dyva.apply(this, arguments);
}
};
window.XMLHttpRequest.prototype.addEventListener_dyva = window.XMLHttpRequest.prototype.addEventListener;
window.XMLHttpRequest.prototype.addEventListener = function(typ, fn) {
if (typ === "readystatechange") {
var f = fn;
fn = function() {
var z;
if (this.readyState === 4) {
if (this.url_dyva?.includes("youtubei/v1/player")) {
rpo = JSON.parse_dyva(this.responseText);
try {
patchPlayerResponse(rpo);
} catch(z) {}
} else if ((/\/watch\?|get_video_info/).test(this.url_dyva)) {
rpo = JSON.parse_dyva(this.responseText);
try {
rpo.forEach(p => {
if (p.player && p.player.args && (p.player.args.raw_player_response || p.player.args.player_response)) {
p.playerResponse_ = JSON.parse_dyva(p.player.args.raw_player_response || p.player.args.player_response);
if (p.playerResponse_.playabilityStatus && (p.playerResponse_.playabilityStatus.status === "LOGIN_REQUIRED")) {
nav.navigate({commandMetadata: {webCommandMetadata: {url: location.href, webPageType: "WEB_PAGE_TYPE_BROWSE"}}}, false);
return;
}
patchPlayerResponse(p.playerResponse_);
if (p.player.args.raw_player_response) {
p.player.args.raw_player_response = JSON.stringify(p.playerResponse_)
} else p.player.args.player_response = JSON.stringify(p.playerResponse_)
} else if (p.playerResponse) {
patchPlayerResponse(p.playerResponse);
}
});
} catch(z) {}
}
}
return f.apply(this, arguments);
};
}
return this.addEventListener_dyva.apply(this, arguments);
};
window.Node.prototype.appendChild_dyva = window.Node.prototype.appendChild;
window.Node.prototype.appendChild = function(node) {
var a;
if (!ipse && (a = document.querySelector('ytd-watch-flexy')) && (a = a.constructor.prototype) && a.isPlaShelfEnabled_) {
a.isPlaShelfEnabled_ = () => false;
ipse = true;
}
if ((!hca || !haia) && (a = document.querySelector('ytd-watch-next-secondary-results-renderer')) && (a = a.constructor.prototype)) {
if (a.hasAllowedInstreamAd_ && !haia) {
a.hasAllowedInstreamAd_ = () => false;
haia = true;
}
if (a.hasCompanionAds_ && !hca) {
a.hasCompanionAds_ = () => false;
hca = true;
}
}
if ((node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) && Array.from(node.childNodes).some((n, i) => {
if (n.id === "masthead-ad") {
n.style.setProperty("display", "none", "important");
//n.remove();
return true;
}
})); //window.Node.prototype.appendChild = window.Node.prototype.appendChild_dyva;
if (node.querySelector && (a = node.querySelector('.ytp-ad-skip-button'))) a.click();
return this.appendChild_dyva.apply(this, arguments);
};
var to = {createHTML: s => s, createScript: s => s}, tp = window.trustedTypes?.createPolicy ? trustedTypes.createPolicy("", to) : to;
var html = s => tp.createHTML(s), script = s => tp.createScript(s);
function patchPlayerResponse(playerResponse, i) {
delete playerResponse.adBreakHeartbeatParams;
if (playerResponse.adPlacements) playerResponse.adPlacements = [];
if (disableAnnotations) delete playerResponse.annotations;
if (playerResponse.adSlots) playerResponse.adSlots = [];
if (playerResponse.auxiliaryUi?.messageRenderers?.bkaEnforcementMessageViewModel) {
delete playerResponse.auxiliaryUi.messageRenderers.bkaEnforcementMessageViewModel;
if (!Object.keys(playerResponse.auxiliaryUi.messageRenderers).length) {
delete playerResponse.auxiliaryUi.messageRenderers;
if (!Object.keys(playerResponse.auxiliaryUi).length) delete playerResponse.auxiliaryUi
}
var vd = playerResponse.videoDetails;
delete playerResponse.videoDetails;
Object.defineProperty(playerResponse, "videoDetails", {
get() {
return vd
},
set(v) {
if (this.playabilityStatus?.errorScreen) {
delete this.playabilityStatus.errorScreen;
this.playabilityStatus.status = "OK"
}
return v
}
});
}
if (playerResponse.messages) {
for (i = playerResponse.messages.length - 1; i >= 0; i--) {
if (playerResponse.messages[i].mealbarPromoRenderer) playerResponse.messages.splice(i, 1)
}
}
if (playerResponse.playerAds) playerResponse.playerAds = [];
if (playerResponse.playbackTracking) {
delete playerResponse.playbackTracking.googleRemarketingUrl;
delete playerResponse.playbackTracking.youtubeRemarketingUrl;
}
}
function patchPlayerArgs(args, a) {
if (args.ad_device) args.ad_device = "0";
if (args.ad_flags) args.ad_flags = 0;
if (args.ad_logging_flag) args.ad_logging_flag = "0";
if (args.ad_preroll) args.ad_preroll = "0";
if (args.ad_slots) delete args.ad_slots;
if (args.ad_tag) delete args.ad_tag;
if (args.ad3_module) args.ad3_module = "0";
if (args.adsense_video_doc_id) delete args.adsense_video_doc_id;
if (args.afv) args.afv = false;
if (args.afv_ad_tag) delete args.afv_ad_tag;
if (args.allow_html5_ads) args.allow_html5_ads = 0;
if (args.csi_page_type) args.csi_page_type = args.csi_page_type.replace(/watch7ad/, "watch7");
if (args.enable_csi) args.enable_csi = "0";
if (args.pyv_ad_channel) delete args.pyv_ad_channel;
if (args.show_pyv_in_related) args.show_pyv_in_related = false;
if (args.vmap) delete args.vmap;
if (args.raw_player_response) {
patchPlayerResponse(a = args.raw_player_response.charAt ? JSON.parse_dyva(args.raw_player_response) : args.raw_player_response);
if (args.raw_player_response.charAt) args.raw_player_response = JSON.stringify(a)
} else if (args.player_response) {
patchPlayerResponse(a = JSON.parse_dyva(args.player_response));
args.player_response = JSON.stringify(a);
}
}
function patchSpf() {
if (window.spf && !spf.request_dyva) {
spf.request_dyva = spf.request;
spf.request = function(a, b) {
if (b && b.onDone) {
var onDone_ = b.onDone;
b.onDone = function(response) {
var a = response;
if (a && (/\/watch\?/).test(a.url) && (a = a.response) && (a = a.parts)) {
a.forEach((p, a) => {
if (p.player && p.player.args && (p.player.args.raw_player_response || p.player.args.player_response)) {
p = p.player.args;
patchPlayerResponse(a = JSON.parse_dyva(p.raw_player_response || p.player_response));
if (p.raw_player_response) {
p.raw_player_response = JSON.stringify(a)
} else p.player_response = JSON.stringify(a)
} else if (p.playerResponse) {
patchPlayerResponse(p.playerResponse);
}
});
}
return onDone_.apply(this, arguments);
};
}
return this.request_dyva.apply(this, arguments);
};
return;
}
}
var ldh, docnt = 5 * 60;
function do1(ev, a) {
if ((a = document.scripts[document.scripts.length - 1]) && /"adPlacements"/.test(a.text)) {
a.text = script(a.text.replace(/"adPlacements"/, '"adPlacements":[],"zadPlacements"'));
}
if (window.loadDataHook) {
if (!window.loadDataHook.dyva) {
ldh = window.loadDataHook;
window.loadDataHook = function(ep, dt) {
if (dt.playabilityStatus && (dt.playabilityStatus === "LOGIN_REQUIRED")) {
location.href = location.href;
throw "Ain't gonna login";
}
patchPlayerResponse(dt);
return ldh.apply(this, arguments);
};
window.loadDataHook.dyva = true;
}
}
if (window.ytcfg && window.ytcfg.set) {
if (!window.ytcfg.set.dyva) {
var ytcfgSet = window.ytcfg.set;
window.ytcfg.set = function(ytConfig, ytValue){
if (window.ytInitialPlayerResponse) {
if (ytInitialPlayerResponse.playabilityStatus && (ytInitialPlayerResponse.playabilityStatus === "LOGIN_REQUIRED")) {
location.href = location.href;
throw "Ain't gonna login";
}
patchPlayerResponse(window.ytInitialPlayerResponse);
}
patchSpf();
if (ytConfig) {
var a;
if (a = ytConfig.EXPERIMENT_FLAGS) {
if (a.enable_auto_play_param_fix_for_masthead_ad) a.enable_auto_play_param_fix_for_masthead_ad = false;
if (a.html5_check_both_ad_active_and_ad_info) a.html5_check_both_ad_active_and_ad_info = false;
if (a.web_enable_ad_signals_in_it_context) a.web_enable_ad_signals_in_it_context = false;
}
if (ytConfig.SKIP_RELATED_ADS === false) ytConfig.SKIP_RELATED_ADS = true;
if (ytConfig.TIMING_ACTION) ytConfig.TIMING_ACTION = ytConfig.TIMING_ACTION.replace(/watch7ad/, "watch7");
if (a = ytConfig.TIMING_INFO) {
if (a.yt_ad) a.yt_ad = 0;
if (a.yt_ad_an) delete a.yt_ad_an;
if (a.yt_ad_pr) a.yt_ad_pr = 0;
}
if (
(a = ytConfig.WEB_PLAYER_CONTEXT_CONFIGS) && (a = a.WEB_PLAYER_CONTEXT_CONFIG_ID_KEVLAR_WATCH) &&
a.serializedExperimentFlags && a.serializedExperimentFlags.replace
) {
a.serializedExperimentFlags = a.serializedExperimentFlags.replace(
/([a-z][^=]+)=([^&]+)/g, (s, a, b) => {
switch (a) {
case "enable_ad_break_end_time_on_pacf_tvhtml5":
case "enable_auto_play_param_fix_for_masthead_ad":
case "html5_check_both_ad_active_and_ad_info": b = false; break;
case "web_enable_ad_signals_in_it_context":
case "web_player_gvi_wexit_adunit": b = false; break;
}
return a + "=" + b;
}
);
}
}
return ytcfgSet.apply(this, arguments);
};
window.ytcfg.set.dyva = true;
}
}
if (window.yt) {
if (window.yt.player && window.yt.player.Application) {
if (window.yt.player.Application.create) {
if (!window.yt.player.Application.create.dyva) {
var ytPlayerApplicationCreate = window.yt.player.Application.create;
window.yt.player.Application.create = function(id, ytPlayerConfig) {
if ((id === "player-api") && ytPlayerConfig && ytPlayerConfig.args) {
if (ytPlayerConfig.args.raw_player_response) patchPlayerResponse(ytPlayerConfig.args.raw_player_response);
if (ytPlayerConfig.args.vmap) delete ytPlayerConfig.args.vmap;
}
return ytPlayerApplicationCreate.apply(this, arguments);
};
window.yt.player.Application.create.dyva = true;
}
}
if (window.yt.player.Application.createAlternate) {
if (!window.yt.player.Application.createAlternate.dyva) {
var ytPlayerApplicationCreateAlternate = window.yt.player.Application.createAlternate;
window.yt.player.Application.createAlternate = function(id, ytPlayerConfig) {
if ((id === "player-api") && ytPlayerConfig && ytPlayerConfig.args) {
if (ytPlayerConfig.args.raw_player_response) patchPlayerResponse(ytPlayerConfig.args.raw_player_response);
if (ytPlayerConfig.args.vmap) delete ytPlayerConfig.args.vmap;
}
return ytPlayerApplicationCreateAlternate.apply(this, arguments);
};
window.yt.player.Application.createAlternate.dyva = true;
}
}
}
if (window.yt.setConfig) {
if (!window.yt.setConfig.dyva) {
var ytSetConfig = window.yt.setConfig;
window.yt.setConfig = function(ytConfig){
if (ytConfig && ytConfig.ADS_DATA) delete ytConfig.ADS_DATA;
return ytSetConfig.apply(this, arguments);
};
window.yt.setConfig.dyva = true;
}
}
}
if (window.ytplayer && window.ytplayer.config && window.ytplayer.config.args) {
if (!window.ytplayer.config.args.dvya) {
patchPlayerArgs(window.ytplayer.config.args);
window.ytplayer.config.args.dvya = true;
}
}
if (document.readyState !== "complete") {
if ((et === false) && (--docnt > 0)) requestAnimationFrame(do1)
} else if (et !== false) removeEventListener(et, do1)
}
addEventListener(et, do1);
do1();
addEventListener("spfpartprocess", function(ev) { //old youtube
if (ev.detail && ev.detail.part && ev.detail.part.data &&
ev.detail.part.data.swfcfg && ev.detail.part.data.swfcfg.args) {
patchPlayerArgs(ev.detail.part.data.swfcfg.args);
}
}, true);
addEventListener("load", a => {
if (!(a = window.ayvp_cssOverride)) {
a = document.createElement("STYLE");
a.id = "ayvp_cssOverride";
a.innerHTML = html(`\
.html5-video-player>.ytp-suggested-action,
.video-ads{display:none!important}
.ytp-ad-overlay-open .caption-window.ytp-caption-window-bottom{margin-bottom:4em}
.ytp-autohide .caption-window.ytp-caption-window-bottom, .ytp-hide-controls .caption-window.ytp-caption-window-bottom{margin-bottom:0!important}`);
document.documentElement.appendChild(a);
}
if (et === "message") {
if (document.readyState !== "complete") {
postMessage({});
} else removeEventListener(et, do1);
}
});
var dce = document.createElement;
document.createElement = function(tag) {
if ((tag === "meta") && window.ytInitialPlayerResponse && ytInitialPlayerResponse.adPlacements && ytInitialPlayerResponse.adPlacements.length) {
patchPlayerResponse(window.ytInitialPlayerResponse)
}
return dce.apply(this, arguments)
};
};
if (("object" === typeof GM_info) && ["FireMonkey", "Greasemonkey"].includes(GM_info.scriptHandler)) {
//FireMonkey and new Greasemonkey workaround for compatibility with the original (unrestricted) Greasemonkey version.
let e = document.createElement("SCRIPT");
e.id = "dyvaUjs";
e.text = "(" + fn + ")()";
document.documentElement.appendChild(e);
} else fn();
})(unsafeWindow);