Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Freetube-redirect TamperMonkey
// ==UserScript==
// @name Freetube Redirect
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http*://*/*
// @grant none
// @run-at document-end
// ==/UserScript==
(function () {
'use strict'
function docReady (fn) {
// https://stackoverflow.com/a/9899701
// see if DOM is already available
if (document.readyState === 'complete' || document.readyState ===
'interactive') {
// call on next available tick
setTimeout(fn, 1)
} else {
document.addEventListener('DOMContentLoaded', fn)
}
}
docReady(function () {
document.querySelectorAll('a').forEach(element => {
if (element.href.includes('youtube.com') ||
element.href.includes('youtu.be') ||
element.href.includes('hooktube.com')) {
element.href = 'freetube://' + element.href
} else {
return
}
if (window.location.href.includes('youtube')) {
element.onclick = function (e) {
window.stop()
e.stopImmediatePropagation()
e.preventDefault()
location.assign(element.href)
}
}
})
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment