diff options
Added YouTube shorts redirector script
1 files changed, 33 insertions, 0 deletions
| -rw-r--r-- | youtube-shorts-redirector.js | 33 |
diff --git a/youtube-shorts-redirector.js b/youtube-shorts-redirector.js new file mode 100644 index 0000000..27ed515 --- /dev/null +++ b/youtube-shorts-redirector.js @@ -0,0 +1,33 @@ +// ==UserScript== +// @name YouTube shorts redirector +// @description Redirects all youtube shorts videos to normal video pages +// @author Kamen Mladenov +// @match *://*.youtube.com/* +// @icon https://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Youtube_shorts_icon.svg/193px-Youtube_shorts_icon.svg.png +// @grant none +// @run-at document-end +// ==/UserScript== + +function redirect() { + if (window.location.pathname.indexOf('shorts') !== 1) { + return; + } + + const loc = 'sh_' + window.location.pathname.substr(8); + + if (localStorage.getItem(loc) === 'true') { + return; + } + + const latest = localStorage.getItem('sh_LATEST'); + if (latest) { + localStorage.removeItem(latest); + } + + localStorage.setItem(loc, true); + localStorage.setItem('sh_LATEST', loc); + window.location = window.location.href.replace("youtube.com/shorts/", "youtube.com/watch?v="); +} + +const observer = new MutationObserver(redirect); +observer.observe(document.getElementsByTagName('ytd-app')[0], { childList: true, attributes: true, subtree: true, }); |
