diff --git a/userscripts/yt-noshorts.user.js b/userscripts/yt-noshorts.user.js index af29938..2c5c89f 100644 --- a/userscripts/yt-noshorts.user.js +++ b/userscripts/yt-noshorts.user.js @@ -6,50 +6,115 @@ // @exclude-match`*://music.youtube.com/* // @icon https://upload.wikimedia.org/wikipedia/commons/f/fc/Youtube_shorts_icon.svg // @grant none -// @version 1.2.1 +// @version 1.3.0 // @author tretrauit -// @description 22:36:53, 18/3/2022 // @require https://raw.githubusercontent.com/naugtur/insertionQuery/master/insQ.min.js // @homepageURL https://gitlab.com/tretrauit/scripts // @supportURL https://gitlab.com/tretrauit/scripts/-/issues // @downloadURL https://gitlab.com/tretrauit/scripts/-/raw/main/userscripts/yt-noshorts.user.js +// @run-at document-start // ==/UserScript== -function getShortsId(videoPathname) +const DEBUG = false; + +function logDebug(...kwargs) { + if (!DEBUG) { + return; + } + console.log(...kwargs); +} + +function getShortsId(videoPathName) { - const shortPath = videoPathname.split("/") + const shortPath = videoPathName.split("/") return shortPath[shortPath.length - 1] } -function redirect() -{ - window.location.replace("https://www.youtube.com/watch?v=" + getShortsId(window.location.pathname)) -} - -function replaceHrefURL(element) -{ - if (element.href.includes("/shorts/")) - { - element.href = "/watch?v=" + getShortsId(element.href) - } +function redirectReplace() { + window.location.replace("https://www.youtube.com/watch?v=" + getShortsId(window.location.pathname)); } function checkCurrentURL() { if (window.location.pathname.includes("/shorts/")) { - redirect() + logDebug("Shorts url detected, redirecting..."); + redirectReplace(); + } +} + +// Should be run asap +checkCurrentURL(); + +function replaceHrefURL(element) +{ + if (element.href != null && element.href.includes("/shorts/")) + { + element.href = "/watch?v=" + getShortsId(element.href) } } function checkElements() { - insertionQ(':is(#video-title, #thumbnail) ').every(function(element){ - replaceHrefURL(element) + insertionQ(':is(#video-title, #thumbnail) ').every(function(element) { + replaceHrefURL(element); }); } -window.addEventListener('yt-navigate-finish', checkCurrentURL) -checkCurrentURL() -checkElements() -console.log("Fuck you YouTube - NoShorts loaded.") +window.addEventListener('yt-navigate-finish', checkCurrentURL); +// Replace addEventListener with our sus one. +const o_addEventListener = window.addEventListener; +const o_shady_addEventListener = window.__shady_addEventListener; +function f_addEventListener(eventName, callback) { + logDebug("Event listener added: ", eventName); + function f_callback(event) { + function cb_dbg() { + if (event instanceof MouseEvent) { + // Event flood in console + return; + } else if (event instanceof PointerEvent) { + // Event flood in console + return; + } else if (event instanceof BeforeUnloadEvent) { + // Event flood in console + return; + } + logDebug("Event callback triggered: ", event, event.data); + logDebug("Page url: ", window.location.href); + } + if (DEBUG) { + cb_dbg(); + } + if (event instanceof MessageEvent) { + // This event is made by SponsorBlock not Youtube so by default it will not run. + // But this can speed up the page navigation process so i'll just keep it. + const data = event.data; + if (data.type == 'navigation' && data.pageType == 'shorts') { + if (data.videoID == undefined) { + return; + } + logDebug("Thank you SponsorBlock for this event :3"); + logDebug("Navigating to video..."); + if (window.location.pathname.includes("/shorts/")) { + window.location.replace("https://www.youtube.com/watch?v=" + data.videoID); + return; + } + window.location.assign("https://www.youtube.com/watch?v=" + data.videoID); + return; + } + } + callback(event); + } + o_addEventListener(eventName, f_callback); +} +function f_sus_addEventListener(a, b, c) { + logDebug("Shady addEventListener triggered."); + logDebug(a, b, c); + o_shady_addEventListener(a, b, c); +} +window.addEventListener = f_addEventListener; +logDebug("Init fake addEventListener successful."); +window.__shady_addEventListener = f_sus_addEventListener; +logDebug("Init fake __shady_addEventListener successful."); +checkElements(); +console.warn("Fuck you YouTube - NoShorts loaded.")