2019-03-04 10:22:00 +01:00
|
|
|
|
;;; oni-browse-url.el --- Browse URL configuration -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
|
|
;; Copyright (C) 2019 Tom Willemse
|
|
|
|
|
|
|
|
|
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
|
|
|
|
;; Keywords: local
|
2022-02-08 18:42:32 +01:00
|
|
|
|
;; Version: 2022.0207.000602
|
2019-03-04 10:22:00 +01:00
|
|
|
|
|
|
|
|
|
;; 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/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; Browse URL configuration.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(require 'browse-url)
|
|
|
|
|
|
2022-02-08 18:42:32 +01:00
|
|
|
|
;; 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)))
|
|
|
|
|
|
2019-03-04 10:22:00 +01:00
|
|
|
|
(setq browse-url-browser-function
|
|
|
|
|
(if (eql system-type 'windows-nt)
|
|
|
|
|
'browse-url-default-windows-browser
|
|
|
|
|
'browse-url-firefox))
|
|
|
|
|
|
2022-02-08 18:42:32 +01:00
|
|
|
|
(advice-add 'browse-url :filter-args #'browse-url-redirect-alternative)
|
|
|
|
|
|
2019-03-04 10:22:00 +01:00
|
|
|
|
(provide 'oni-browse-url)
|
|
|
|
|
;;; oni-browse-url.el ends here
|