Skip to content

Instantly share code, notes, and snippets.

@lassekongo83
Last active May 17, 2023 08:38
Show Gist options
  • Select an option

  • Save lassekongo83/8c025d93da1061c69c13c2040b8ee9da to your computer and use it in GitHub Desktop.

Select an option

Save lassekongo83/8c025d93da1061c69c13c2040b8ee9da to your computer and use it in GitHub Desktop.

Revisions

  1. lassekongo83 revised this gist May 17, 2023. 1 changed file with 24 additions and 20 deletions.
    44 changes: 24 additions & 20 deletions yt-shorts-redirect.user.js
    Original file line number Diff line number Diff line change
    @@ -1,33 +1,37 @@
    // ==UserScript==
    // @name Youtube shorts redirect
    // @namespace ViolentMonkey Scripts
    // @version 0.2
    // @version 0.3
    // @match *://*.youtube.com/*
    // @grant none
    // @run-at document-start
    // ==/UserScript==

    let oldHref = document.location.href;
    if (window.location.href.indexOf('youtube.com/shorts') > -1) {
    window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
    }
    (function() {
    'use strict';

    const replaceShortsLinks = () => {
    [...document.querySelectorAll('a[href*="/shorts/"]')]
    .forEach(a => {
    a.href = a.href.replace(/\/shorts\/(.*)/, '/watch?v=$1')
    });
    };

    window.addEventListener("yt-navigate-finish", replaceShortsLinks, true);

    function shortsRedirector() {
    if (oldHref != document.location.href) {
    oldHref = document.location.href;
    if (window.location.href.indexOf('youtube.com/shorts') > -1) {
    window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
    let oldHref = document.location.href;
    if (window.location.href.indexOf('youtube.com/shorts') > -1) {
    window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
    }
    function shortsRedirector() {
    if (oldHref != document.location.href) {
    oldHref = document.location.href;
    if (window.location.href.indexOf('youtube.com/shorts') > -1) {
    window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
    }
    }
    }
    }
    window.addEventListener("yt-navigate-finish", shortsRedirector, true);

    // Replace links as well
    const replaceShortsLinks = () => {
    [...document.querySelectorAll('a[href*="/shorts/"]')]
    .forEach(a => {
    a.href = a.href.replace(/\/shorts\/(.*)/, '/watch?v=$1')
    });
    };
    window.addEventListener("yt-navigate-finish", shortsRedirector, true);

    window.addEventListener("yt-navigate-finish", replaceShortsLinks, true);
    })();
  2. lassekongo83 revised this gist May 17, 2023. 1 changed file with 13 additions and 2 deletions.
    15 changes: 13 additions & 2 deletions yt-shorts-redirect.user.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,12 @@
    // ==UserScript==
    // @name Youtube shorts redirect
    // @namespace ViolentMonkey Scripts
    // @version 0.1
    // @version 0.2
    // @match *://*.youtube.com/*
    // @grant none
    // @run-at document-start
    // ==/UserScript==

    let oldHref = document.location.href;
    if (window.location.href.indexOf('youtube.com/shorts') > -1) {
    window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
    @@ -19,4 +20,14 @@ function shortsRedirector() {
    }
    }
    }
    window.addEventListener("yt-navigate-finish", shortsRedirector, true);
    window.addEventListener("yt-navigate-finish", shortsRedirector, true);

    // Replace links as well
    const replaceShortsLinks = () => {
    [...document.querySelectorAll('a[href*="/shorts/"]')]
    .forEach(a => {
    a.href = a.href.replace(/\/shorts\/(.*)/, '/watch?v=$1')
    });
    };

    window.addEventListener("yt-navigate-finish", replaceShortsLinks, true);
  3. lassekongo83 revised this gist Jul 5, 2022. No changes.
  4. lassekongo83 created this gist May 17, 2022.
    22 changes: 22 additions & 0 deletions yt-shorts-redirect.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    // ==UserScript==
    // @name Youtube shorts redirect
    // @namespace ViolentMonkey Scripts
    // @version 0.1
    // @match *://*.youtube.com/*
    // @grant none
    // @run-at document-start
    // ==/UserScript==
    let oldHref = document.location.href;
    if (window.location.href.indexOf('youtube.com/shorts') > -1) {
    window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
    }

    function shortsRedirector() {
    if (oldHref != document.location.href) {
    oldHref = document.location.href;
    if (window.location.href.indexOf('youtube.com/shorts') > -1) {
    window.location.replace(window.location.toString().replace('/shorts/', '/watch?v='));
    }
    }
    }
    window.addEventListener("yt-navigate-finish", shortsRedirector, true);