Last active
August 29, 2015 14:12
-
-
Save Zod-/88a0c303caef51eb2597 to your computer and use it in GitHub Desktop.
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 Link Cleaner | |
// @namespace bc947901639b2ed3841f71b5bab09262 | |
// @description Removes unneeded parameters and redirection pages from YouTube links. | |
// @include http://youtube.com/* | |
// @include http://www.youtube.com/* | |
// @include https://youtube.com/* | |
// @include https://www.youtube.com/* | |
// @require https://greasyfork.org/scripts/2859-video-url-parser/code/Video%20Url%20Parser.js?version=29929 | |
// @version 3 | |
// @grant none | |
// ==/UserScript== | |
var parsed, url; | |
/* Dieses Skript steht unter CC0 / This script is licensed under CC0: | |
* http://creativecommons.org/publicdomain/zero/1.0/deed.de | |
* http://creativecommons.org/publicdomain/zero/1.0/deed.en */ | |
/* If on a redirect page, redirect */ | |
if(window.location.pathname == "/redirect") { | |
window.location.href.match(/(&|\?)q=(.*?)(&|$)/); | |
window.location.replace(window.decodeURIComponent(RegExp.$2)); | |
} | |
/* If a unneeded parameter exists, remove it */ | |
if(window.location.href.match(/(&(feature|src_vid|annotation_id|gl|hl)=[a-zA-Z0-9_-]*|\?(feature|src_vid|annotation_id|gl|hl)=[a-zA-Z0-9_-]*$)/)) { | |
parsed = urlParser.parse(window.location.href); | |
if(parsed){ | |
url = urlParser.create({videoInfo: parsed, format: 'long'}); | |
window.history.pushState(window.location.href,window.document.title, url); | |
} | |
} | |
LinkCount = 0; | |
function ChangeLinks() { | |
if(LinkCount != window.document.links.length) { | |
for (var i = 0; i < window.document.links.length; i++) { | |
/* Remove unneeded parameters */ | |
parsed = urlParser.parse(window.document.links[i].href); | |
if(parsed){ | |
url = urlParser.create({videoInfo: parsed, format: 'long'}); | |
window.document.links[i].href = url; | |
} | |
/* Do not use redirect pages, disable AJAX on links */ | |
window.document.links[i].className = window.document.links[i].className.replace(/(yt-uix-redirect-link|spf-link)/g, ""); | |
} | |
LinkCount = window.document.links.length; | |
} | |
} | |
ChangeLinks(); | |
window.setInterval(ChangeLinks, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment