Skip to content

Instantly share code, notes, and snippets.

@lionel-rowe
Last active February 19, 2024 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lionel-rowe/130b59a8cd06bdf359f9d4888baefb94 to your computer and use it in GitHub Desktop.
Save lionel-rowe/130b59a8cd06bdf359f9d4888baefb94 to your computer and use it in GitHub Desktop.
// ==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