From dcf277a644e83826ff6fc419b0d5ec282bcec5fd Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 8 Feb 2022 09:42:32 -0800 Subject: [PATCH] =?UTF-8?q?[oni-browse-url]=20Add=20advice=20to=20?= =?UTF-8?q?=E2=80=98browse-url=E2=80=99=20to=20redirect=20some=20URLs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are a couple of free alternative front-ends to certain services: - Scribe for Medium. - Nitter for Twitter. - Invidious for Youtube. --- oni-browse-url.el | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/oni-browse-url.el b/oni-browse-url.el index cfb8c9d..57feb6e 100644 --- a/oni-browse-url.el +++ b/oni-browse-url.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2021.0727.202603 +;; Version: 2022.0207.000602 ;; 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 @@ -27,10 +27,40 @@ (require 'browse-url) +;; Ideas: +;; - Split out to different functions for Medium, Twitter, Youtube, etc. +;; - Split the medium one into *.medium.com and also allow arbitrary sites to be added. +(defun browse-url-redirect-alternative (args) + "Check the url given to ‘browse-url’ and redirect to a free alternative if available. +ARGS is the list of arguments that was passed to ‘browse-url’ +before this filter." + (cond + ((string-prefix-p "https://blog.bitsrc.io" (car args)) + (cons (string-replace "https://blog.bitsrc.io" "https://scribe.rip/bitsrc" (car args)) + (cdr args))) + ((string-prefix-p "https://levelup.gitconnected.com" (car args)) + (cons (string-replace "https://levelup.gitconnected.com" "https://scribe.rip/gitconnected" (car args)) + (cdr args))) + ((string-prefix-p "https://twitter.com" (car args)) + (cons (string-replace "https://twitter.com" "https://nitter.net" (car args)) + (cdr args))) + ((string-prefix-p "https://kevingosse.medium.com" (car args)) + (cons (string-replace "https://kevingosse.medium.com" "https://scribe.rip/kevingosse" (car args)) + (cdr args))) + ((string-prefix-p "https://medium.com" (car args)) + (cons (string-replace "https://medium.com" "https://scribe.rip" (car args)) + (cdr args))) + ((string-prefix-p "https://www.youtube.com" (car args)) + (cons (string-replace "https://www.youtube.com" "https://yewtu.be" (car args)) + (cdr args))) + (t args))) + (setq browse-url-browser-function (if (eql system-type 'windows-nt) 'browse-url-default-windows-browser 'browse-url-firefox)) +(advice-add 'browse-url :filter-args #'browse-url-redirect-alternative) + (provide 'oni-browse-url) ;;; oni-browse-url.el ends here