Skip to content

Instantly share code, notes, and snippets.

@Necroforger
Last active September 7, 2018 05:31
Show Gist options
  • Save Necroforger/de3272453b269e70813630d33db466c4 to your computer and use it in GitHub Desktop.
Save Necroforger/de3272453b269e70813630d33db466c4 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Youtube Tools Popout Helper
// @namespace http://tampermonkey.net/
// @version 0.2
// @description replaces links in the end screen to point towards another embed page
// @author necroforger
// @match https://www.youtube.com/embed/*?*ytt_popout=1*
// @grant none
// ==/UserScript==
(function () {
'use strict';
function replaceLinks() {
let elements = document.querySelectorAll("a.ytp-suggestion-set");
for (let x of elements) {
if (x.getAttribute("target") !== "") {
x.setAttribute("target", "");
}
if (x.getAttribute("href").includes("/watch?")) {
let url = x.getAttribute("href");
let id = url.substr(url.indexOf("?")).match(/(v=)(.*?)(&|$)/)[2];
let newLocation = `https://www.youtube.com/embed/${id}?ytt_popout=1&autoplay=1`;
x.setAttribute("href", newLocation);
}
}
}
setInterval(replaceLinks, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment