您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Replaces outgoing links to avoid the YouTube "are you sure you want to leave" page
// ==UserScript== // @name YouTube outgoing links fix // @version 1.0.2 // @description Replaces outgoing links to avoid the YouTube "are you sure you want to leave" page // @author Thomas van der Berg // @namespace tmsbrg // @match https://www.youtube.com/* // @grant none // @license GPLv3+ // ==/UserScript== (function() { 'use strict'; // from https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function replaceLinks() { await sleep(2000); // bit of a hack: seems we need to wait for YouTube to do its stuff before we act let outgoing_links = document.querySelectorAll('a[href^="https://www.youtube.com/redirect"]'); for (let i = 0; i < outgoing_links.length; i++) { let original_destination = outgoing_links[i].href; let new_destination = decodeURIComponent(original_destination.split("&").filter(arg => arg.startsWith("q="))[0].substring(2)); outgoing_links[i].href = new_destination; outgoing_links[i].data = null; // remove some YouTube specific stuff that tries to open youtube.com/redirect on click } } window.addEventListener('yt-navigate-finish', replaceLinks ); })();