8 ms·
My tampermonkey script (credit to the original author, I forget where I got it from): // ==UserScript== // @name Youtube shorts redirect // @name
by brokenmachine 2y ago
My tampermonkey script (credit to the original author, I forget where I got it from):
// ==UserScript==
// @name Youtube shorts redirect
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Youtube shorts > watch redirect
// @author
// @match *://*.youtube.com/*
// @icon https://www.google.com/s2/favicons?domain=youtube.com
// @grant none
// @run-at document-start
// @license GNU GPLv2
// ==/UserScript==
var oldHref = document.location.href;
if (window.location.href.indexOf('youtube.com/shorts') > -1) {
window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
}
window.onload = function() {
var bodyList = document.querySelector("body")
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (oldHref != document.location.href) {
oldHref = document.location.href;
console.log('location changed!');
if (window.location.href.indexOf('youtube.com/shorts') > -1) {
window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
}
}
});
});
var config = {
childList: true,
subtree: true
};
observer.observe(bodyList, config);
};
- somat 2y agoFor completeness here is mine. I will try yours and see if it works better. // ==UserScript== // @name eat my shorts // @namespace http://tampermonkey.net/ // @version 0.1 // @description change links to youtube shorts to reguler site // @author jrs // @match https://www.youtube.com/* // @icon none // @grant none // ==/UserScript== (function() { 'use strict'; function eat_shorts() { const root = document; const shorts_re = /^\/shorts\/(.*)/; const ae = root.getElementsByTagName("a"); for (var i = 0; i < ae.length; i++) { const this_a = ae[i]; const short_match = shorts_re.exec(this_a.getAttribute("href") ); if (short_match) { this_a.setAttribute("href", "/v/" + short_match[1]); } } } const config = { attributes: false, childList: true, subtree: true } //timer resets every time the returned function is called function make_reset_timer(cb, timeout) { var timer = setTimeout(cb, timeout); function reset_timer(mutation_list, observer) { clearTimeout(timer); timer = setTimeout(cb, timeout); } return reset_timer; } const short_observer = new MutationObserver(make_reset_timer(eat_shorts, 10)); short_observer.observe(document, config); })();