diff options
author | lxf <sng@luxagraf.net> | 2022-04-05 10:16:51 -0400 |
---|---|---|
committer | lxf <sng@luxagraf.net> | 2022-04-05 10:16:51 -0400 |
commit | e2737d673880d1a4896490f784919bcf08b8af9d (patch) | |
tree | 463ecb6fbc2c5b29635fee9050619008f04c41ec | |
parent | 76e93063e1923625905816667e75c4175feb4593 (diff) |
brsr: updated qutebrowser configs
-rw-r--r-- | .config/qutebrowser/config/bookmarks/urls | 0 | ||||
-rw-r--r-- | .config/qutebrowser/config/quickmarks | 0 | ||||
-rw-r--r-- | .config/qutebrowser/greasemonkey/autostop.js | 171 | ||||
-rwxr-xr-x | .config/qutebrowser/userscripts/camel.py | 38 | ||||
-rw-r--r-- | .config/qutebrowser/userscripts/youtube-dl | 53 | ||||
-rw-r--r-- | .config/qutebrowser/whitelists/js | 37 |
6 files changed, 299 insertions, 0 deletions
diff --git a/.config/qutebrowser/config/bookmarks/urls b/.config/qutebrowser/config/bookmarks/urls new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/.config/qutebrowser/config/bookmarks/urls diff --git a/.config/qutebrowser/config/quickmarks b/.config/qutebrowser/config/quickmarks new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/.config/qutebrowser/config/quickmarks diff --git a/.config/qutebrowser/greasemonkey/autostop.js b/.config/qutebrowser/greasemonkey/autostop.js new file mode 100644 index 0000000..a0196c9 --- /dev/null +++ b/.config/qutebrowser/greasemonkey/autostop.js @@ -0,0 +1,171 @@ +// ==UserScript== +// @name Autostop +// @description Autoplay sucks, even on youtube +// @namespace github.com/seebye/autostop +// @match <all_urls> +// @run-at document-start +// ==/UserScript== +/* +Copyright (C) 2017 Nico Baeurer + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +(function() { + "use strict"; + + let playable = false; + let proto = (() => { + let iframe = document.createElement('iframe'); + let protos = {}; + + try { + iframe.sandbox = 'allow-same-origin'; + document.documentElement.insertBefore(iframe, document.documentElement.firstChild); + + for (let i of Object.getOwnPropertyNames(iframe.contentWindow)) { + try { + protos[i] = iframe.contentWindow[i].prototype; + } + catch (e) { + // some members are still protected (cross origin) + } + } + + return protos; + } + finally { + document.documentElement.removeChild(iframe); + } + })(); + + + let accessUnmodified = function(target, cb) { + let tmp = target.__proto__; + + try { + target.__proto__ = proto[tmp.constructor.name]; + return cb(target); + } + finally { + target.__proto__ = tmp; + } + }; + + + let hook = function(proto) { + let helper = {}; + + for (let member in proto) { + try { + if (proto[member] instanceof Function) { + helper[member] = { + override: function(creator) { + proto[member] = creator(proto[member]); + return helper; + } + }; + } + } + catch (e) { + helper[member] = { + property: function({getter, setter=() => {}}) { + Object.defineProperty(proto, member, { + get: getter, + configurable: false, + enumerable: true, + set: setter + }); + return helper; + }, + constant: function(val) { + Object.defineProperty(proto, member, { + value: val, + configurable: false, + enumerable: true + }); + return helper; + } + }; + } + } + + return helper; + }; + + + let disableAutoplay = function(target) { + for (let v of target.getElementsByTagName('video')) { + v.pause(); + } + }; + + + let onceTrustedEvent = function(target, ev, cb) { + target.addEventListener(ev, (() => { + let listener = (e) => { + if (e.isTrusted) { + target.removeEventListener(ev, listener); + cb(e); + } + }; + return listener; + })()); + }; + + + let init = (function() { + onceTrustedEvent(document, "click", (e) => { + playable = true; + }); + + hook(window.HTMLMediaElement.prototype) + // block javascript code from playing a video till the first user interaction + .play.override((orig) => function() { + try { + return orig.apply(this); + } + finally { + // pause video instead of block calling play + // (e.g. youtube produces a high load otherwise..) + if (!playable) { + this.pause(); + } + } + }) + // block javascript code from enabling autoplay + .autoplay.property({getter: function() { + return accessUnmodified(this, (self) => self.autoplay); + }}); + + // disable autoplay via html attribute + hook(window.Element.prototype) + .innerHTML.property({ + getter: function() { + return accessUnmodified(this, (self) => self.innerHTML); + }, + setter: function(val) { + accessUnmodified(this, (self) => { + self.innerHTML = val; + }); + + disableAutoplay(this); + }}); + + document.addEventListener("DOMContentLoaded", (e) => { + disableAutoplay(document); + }, {once: true}); + })(); +})(); + diff --git a/.config/qutebrowser/userscripts/camel.py b/.config/qutebrowser/userscripts/camel.py new file mode 100755 index 0000000..926d6e9 --- /dev/null +++ b/.config/qutebrowser/userscripts/camel.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# coding=utf-8 +""" +Description: Qutebrowser userscript. Allows you to download and watch a youtube video +Keyboard binding: config.bind("\\", 'hint all userscript watchyt.py') +Config file location: ~/.config/qutebrowser/config.py +Script file location: ~/.local/share/qutebrowser/userscripts/watchyt.py +Manually set keybinding: :bind \ hint all userscript watchyt.py +Usage: Press \ then the hint keys for the video you wish to watch. + You must select the video title not the image + +This is my first Qutebrowser plugin so it is pretty basic right now. +Why download and watch when you can stream to mpv? +mpv has a thumbnails plugin that doesn't work when streaming. +You don't have to deal with buffering when it is already downloaded. +""" + +from __future__ import unicode_literals + +import os + +from executor import execute +from lxml import html +from qutescript import userscript + + +@userscript +def search_camel(request): + # TODO: Add title, url, img, filepath to a database + #dom = html.parse(request.html) + camel_url = 'https://camelcamelcamel.com/search?sq=%s' % os.environ["QUTE_URL"].strip() + with open(os.environ['QUTE_FIFO'], 'w') as fifo: + fifo.write('open -t %s' % camel_url) + +if __name__ == "__main__": + search_camel() + + diff --git a/.config/qutebrowser/userscripts/youtube-dl b/.config/qutebrowser/userscripts/youtube-dl new file mode 100644 index 0000000..5cd71e6 --- /dev/null +++ b/.config/qutebrowser/userscripts/youtube-dl @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# coding=utf-8 +""" +Description: Qutebrowser userscript. Allows you to download and watch a youtube video +Keyboard binding: config.bind("\\", 'hint all userscript watchyt.py') +Config file location: ~/.config/qutebrowser/config.py +Script file location: ~/.local/share/qutebrowser/userscripts/watchyt.py +Manually set keybinding: :bind \ hint all userscript watchyt.py +Usage: Press \ then the hint keys for the video you wish to watch. + You must select the video title not the image + +This is my first Qutebrowser plugin so it is pretty basic right now. +Why download and watch when you can stream to mpv? +mpv has a thumbnails plugin that doesn't work when streaming. +You don't have to deal with buffering when it is already downloaded. +""" + +from __future__ import unicode_literals + +import os + +import youtube_dl +from executor import execute +from lxml import html +from qutescript import userscript + + +@userscript +def watch_youtube(request): + # TODO: Add title, url, img, filepath to a database + # TODO: Make webpage to watch the downloaded videos + # dom = html.parse(request.html) + # out = dom.find(".//title").text + # out = "<br>\n".join([f"{j}: {k}" for j, k in os.environ.items()]) + # title = os.environ["QUTE_SELECTED_TEXT"].strip() + # TODO: Verify it is a video link. Not an image. If image then search for correct URL in dom + url = os.environ["QUTE_URL"].strip() + # href = url.split("/")[-1] + # img = dom.xpath(f".//a[@id='thumbnail' and @href='/{href}']/yt-img-shadow/img")[0].get("src") + # out += f"<p>\n\n{title} - {url} - /{href} - {img}" + # TODO: Use fallback formats incase 18 is not available. + with youtube_dl.YoutubeDL({ + "restrictfilenames": True, + "format": "18", + "outtmpl": "/yt/%(upload_date)s_%(title)s-%(id)s.%(ext)s", + }) as ydl: + info_dict = ydl.extract_info(url) + filepath = ydl.prepare_filename(info_dict) + execute(f"mpv {filepath}") +# request.send_html(out) + +if __name__ == "__main__": + watch_youtube() diff --git a/.config/qutebrowser/whitelists/js b/.config/qutebrowser/whitelists/js new file mode 100644 index 0000000..0bc12fa --- /dev/null +++ b/.config/qutebrowser/whitelists/js @@ -0,0 +1,37 @@ +*://localhost/* +*://127.0.0.1/* +https://live.luxagraf.net/* +https://cloud.luxagraf.net/* +https://webmail.luxagraf.net/* +https://luxagraf.net/* +https://rss.luxagraf.net/* +https://github.com/* +https://gitlab.com/* +https://*.youtube.com/* +https://*.tastyworks.com/* +https://wandererfinancial.com/* +https://*.tradingview.com/* +https://translate.google.com/* +https://schoolsfirstfcu.org/* +https://www.schoolsfirstfcu.org/* +https://www.ssec.wisc.edu/* +https://bumfuzzle.com/* +https://pmags.com/* +https://*.tastyworks.com/* +https://discuss.pixls.us/* +https://www.startpage.com/* +https://*.schwab.com/* +https://*.hyvor.com/* +https://ecosophia.dreamwidth.org/* +https://signin.ebay.com/* +https://www.ebay.com/* +https://ebay.com/* +https://*.ebay.com/* +https://manage.buyvm.net/* +https://my.frantech.ca/* +https://oltx.fidelity.com/* +https://freemusicarchive.org/* +https://*.duckduckgo.com/* +https://charlenewinfred.com/* +https://app.nixplay.com/* +https://docs.google.com/spreadsheets/d/* |