【问题标题】:Tampermonkey/greasemonkey youtube redirect script from /shorts/* to /watch?v=*Tampermonkey/greasemonkey youtube 重定向脚本从 /shorts/* 到 /watch?v=*
【发布时间】:2022-08-06 08:28:49
【问题描述】:

不知道如何编码,但标题应该解释我所追求的。

如果我转到https://www.youtube.com/shorts/zUy4y2CqCV0,我想自动重定向到完整的 youtube 播放器版本,即https://www.youtube.com/watch?v=zUy4y2CqCV0

提前致谢。

标签: youtube greasemonkey tampermonkey


【解决方案1】:

这里可以做到: https://greasyfork.org/en/scripts/439993-youtube-shorts-redirect

链接断开时脚本的内容。

// ==UserScript==
// @name         Youtube shorts redirect
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Youtuebe shorts > watch redirect
// @author       Fuim
// @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);
};

【讨论】:

    猜你喜欢
    • 2018-09-14
    • 2018-05-15
    • 2016-10-03
    • 2012-05-27
    • 1970-01-01
    • 1970-01-01
    • 2013-10-23
    • 2014-09-16
    • 1970-01-01
    相关资源
    最近更新 更多