-
-
Save SpiritAxolotl/58e2bc079bcae19aac379ca1b61f1a12 to your computer and use it in GitHub Desktop.
Youtube Userscript
This file contains 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
/(?<=^https?:\/\/(?:www\.)?youtube\.com\/redirect\?.*q=)(.*?)(?=(?:&.*)|$)/gm |
This file contains 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 Youtube direct hyperlinks | |
// @namespace https://github.com/SpiritAxolotl | |
// @version 0.1 | |
// @description makes hyperlinks link directly to what they say they are, no youtube middleman tracking what links you click on | |
// @author Spax | |
// @match https://www.youtube.com/* | |
// @match https://www.youtube-nocookie.com/* | |
// @match https://m.youtube.com/* | |
// @match https://music.youtube.com/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(function() {'use strict'; | |
console.log("running redirect remover"); | |
const regex = new RegExp("(?<=^https?:\\/\\/(?:www\\.)?youtube\\.com\\/redirect\\?.*q=)(.*?)(?=(?:&.*)|$)"); | |
const desclinks = document.querySelector("#description-inline-expander > yt-attributed-string").getElementsByTagName("a"); | |
for (let i=0; desclinks && i<desclinks.length; i++) { | |
const href = desclinks[i].href | |
if (regex.test(href)) { | |
const newhref = decodeURI(regex.match(href)[0]); | |
console.log("old href: " + href); | |
console.log("new href: " + newhref); | |
desclinks[i].setAttribute("href", newhref); | |
} | |
} | |
console.log("redirect remover finished!"); | |
//sample url | |
//https://www.youtube.com/redirect?event=video_description&redir_token=QUFFLUhqbXZ6VWxET21uVklFdXRPRkhBTGWzcEZpVVFpQXxBQ3Jtc0ttVXU1djhXUS1uMGUyTUVPM3RBQmFHQVZQZHZkTy1ndmlJX2lWYVV2aG9SZ1BUc0Z1a0Q3MDM4VVJwOVptWmxXeXItN3dqVVd0dWtSam9LVGpsZml2Q1dObnRpSUpsQlBrbXBtYmgtY0dRbVY4WTl2QQ&q=https%3A%2F%2Fgist.github.com%2FSpiritAxolotl%2F58e2bc079bcae19aac379ca1b61f1a12&v=tvkxupwbFLk | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment