Skip to content

Instantly share code, notes, and snippets.

@Dykam
Last active February 12, 2017 23:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dykam/8250bc1bb0f62b1c946a to your computer and use it in GitHub Desktop.
Save Dykam/8250bc1bb0f62b1c946a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Youtube to Youtube gaming
// @namespace http://dykam.nl/
// @version 0.1
// @description Redirects the YT watch page to the better YT gaming watch page
// @author Dykam
// @match https://www.youtube.com/*
// @grant none
// ==/UserScript==
var core = function(e) {
document.location.host = "gaming.youtube.com";
};
document.addEventListener('DOMContentLoaded', function() {
var masthead_user = document.querySelector("#yt-masthead-user");
var upload_button = document.querySelector("#upload-btn");
var gaming_button = document.createElement("a");
gaming_button.classList.add.apply(gaming_button.classList, upload_button.classList);
gaming_button.style.marginRight = "15px";
gaming_button.addEventListener("click", function(e) {
e.stopPropagation();
core();
});
var gaming_button_text = document.createElement("span");
gaming_button_text.innerText = "Gaming";
gaming_button_text.classList.add.apply(gaming_button_text.classList, upload_button.children[0].classList);
gaming_button.appendChild(gaming_button_text);
masthead_user.insertBefore(gaming_button, upload_button);
});
/** why no worky
var _wr = function(type) {
var orig = history[type];
return function() {
var rv = orig.apply(this, arguments);
var e = new Event(type);
e.arguments = arguments;
window.dispatchEvent(e);
return rv;
};
};
history.pushState = _wr('pushState'), history.replaceState = _wr('replaceState');
setTimeout(function() {
history.pushState = _wr('pushState'), history.replaceState = _wr('replaceState');
}, 1000);
window.addEventListener('replaceState', core);
window.addEventListener('pushState', core);
**/
// Don't redirect if url has a timestamp, YT Gaming doesn't support it.
if(document.location.pathname == "/watch") {
if(!/[?&](t=\d|noredirect\b)/.test(document.location.search)) {
core();
} else {return;
var n = new Notification("Gaming", {
body: "No automatic redirect to TY Gaming, as jumping to a timestamp is unsupported by YT gaming."
});
setTimeout(n.close.bind(n), 4000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment