yt-noshorts.user.js: 1.3.0
This commit is contained in:
parent
d753bee5e3
commit
bae0d02885
@ -6,50 +6,115 @@
|
|||||||
// @exclude-match`*://music.youtube.com/*
|
// @exclude-match`*://music.youtube.com/*
|
||||||
// @icon https://upload.wikimedia.org/wikipedia/commons/f/fc/Youtube_shorts_icon.svg
|
// @icon https://upload.wikimedia.org/wikipedia/commons/f/fc/Youtube_shorts_icon.svg
|
||||||
// @grant none
|
// @grant none
|
||||||
// @version 1.2.1
|
// @version 1.3.0
|
||||||
// @author tretrauit
|
// @author tretrauit
|
||||||
// @description 22:36:53, 18/3/2022
|
|
||||||
// @require https://raw.githubusercontent.com/naugtur/insertionQuery/master/insQ.min.js
|
// @require https://raw.githubusercontent.com/naugtur/insertionQuery/master/insQ.min.js
|
||||||
// @homepageURL https://gitlab.com/tretrauit/scripts
|
// @homepageURL https://gitlab.com/tretrauit/scripts
|
||||||
// @supportURL https://gitlab.com/tretrauit/scripts/-/issues
|
// @supportURL https://gitlab.com/tretrauit/scripts/-/issues
|
||||||
// @downloadURL https://gitlab.com/tretrauit/scripts/-/raw/main/userscripts/yt-noshorts.user.js
|
// @downloadURL https://gitlab.com/tretrauit/scripts/-/raw/main/userscripts/yt-noshorts.user.js
|
||||||
|
// @run-at document-start
|
||||||
// ==/UserScript==
|
// ==/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]
|
return shortPath[shortPath.length - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirect()
|
function redirectReplace() {
|
||||||
{
|
window.location.replace("https://www.youtube.com/watch?v=" + getShortsId(window.location.pathname));
|
||||||
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 checkCurrentURL()
|
function checkCurrentURL()
|
||||||
{
|
{
|
||||||
if (window.location.pathname.includes("/shorts/"))
|
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()
|
function checkElements()
|
||||||
{
|
{
|
||||||
insertionQ(':is(#video-title, #thumbnail) ').every(function(element) {
|
insertionQ(':is(#video-title, #thumbnail) ').every(function(element) {
|
||||||
replaceHrefURL(element)
|
replaceHrefURL(element);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('yt-navigate-finish', checkCurrentURL)
|
window.addEventListener('yt-navigate-finish', checkCurrentURL);
|
||||||
checkCurrentURL()
|
// Replace addEventListener with our sus one.
|
||||||
checkElements()
|
const o_addEventListener = window.addEventListener;
|
||||||
console.log("Fuck you YouTube - NoShorts loaded.")
|
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.")
|
||||||
|
Loading…
Reference in New Issue
Block a user