Last active
February 19, 2024 04:42
-
-
Save lionel-rowe/130b59a8cd06bdf359f9d4888baefb94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Yes I Am Sure I Want To Leave YouTube | |
// @namespace https://github.com/lionel-rowe/ | |
// @version 0.1 | |
// @description Disable "Are you sure that you want to leave YouTube?" redirect page | |
// @author https://github.com/lionel-rowe/ | |
// @match https://www.youtube.com/* | |
// @icon https://www.youtube.com/favicon.ico | |
// @updateURL https://gist.github.com/lionel-rowe/130b59a8cd06bdf359f9d4888baefb94/raw/yes-i-am-sure-i-want-to-leave-youtube.user.js | |
// @downloadURL https://gist.github.com/lionel-rowe/130b59a8cd06bdf359f9d4888baefb94/raw/yes-i-am-sure-i-want-to-leave-youtube.user.js | |
// @grant none | |
// ==/UserScript== | |
const eventNames = [ | |
'mouseover', // before clicks | |
'focusin', // before keyboard navigation (Tab + Enter) | |
] | |
for (const eventName of eventNames) { | |
document.body.addEventListener(eventName, (e) => { | |
if (e.target.matches('a[href]')) { | |
const url = new URL(e.target.href, document.baseURI) | |
if (url.href.startsWith('https://www.youtube.com/redirect?')) { | |
e.target.href = url.searchParams.get('q') | |
// remove all existing event listeners by overwriting innerHTML | |
e.target.parentElement.innerHTML = e.target.parentElement.innerHTML | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment