Last active
June 27, 2019 19:25
-
-
Save chapterjason/63d2273f3d02a4ad40fd789101f8991d to your computer and use it in GitHub Desktop.
Tampermonkey youtube script - automatically switch to videos tab
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 Automatic channel tab switch | |
// @namespace http://tampermonkey.net/ | |
// @version 0.5 | |
// @description Switches automatically to the videos tab if a channel or user page is requested | |
// @author Jason Schilling <jason.schilling@sourecode.de> | |
// @updateURL https://gist.github.com/chapterjason/63d2273f3d02a4ad40fd789101f8991d/raw/auto-switch.js | |
// @downloadURL https://gist.github.com/chapterjason/63d2273f3d02a4ad40fd789101f8991d/raw/auto-switch.js | |
// @match https://www.youtube.com/* | |
// @run-at document-end | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function notEmptyFilter(item){ | |
return item.length; | |
} | |
console.info("Automatic tab switch loaded!"); | |
document.addEventListener('yt-navigate-start', function(event){ | |
execute(event.detail.url); | |
return false; | |
}); | |
function execute(url){ | |
const parts = url.split('/').filter(notEmptyFilter); | |
if(parts.length === 2 && (parts[0] === 'user' || parts[0] === 'channel')){ | |
const target = location.href + '/videos'; | |
location.href = target | |
location.replace(target); | |
} | |
} | |
execute(location.pathname); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment