Last active
August 26, 2022 20:21
-
-
Save dshoreman/1d28c1372f507d5afe79a6d62da66324 to your computer and use it in GitHub Desktop.
Greasemonkey script to open youtube videos in MPV
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: Open in mpv | |
// @version 1 | |
// @grant none | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js | |
// @require https://gist.githubusercontent.com/BrockA/2625891/raw/9c97aa67ff9c5d56be34a55ad6c18a314e5eb548/waitForKeyElements.js | |
// @match https://*.youtube.com/results* | |
// @match https://*.youtube.com/c/*/videos | |
// @match https://*.youtube.com/u/*/videos | |
// @match https://*.youtube.com/channel/*/videos | |
// @match https://*.youtube.com/user/*/videos | |
// @match https://*.youtube.com/watch?* | |
// ==/UserScript== | |
const dot = '<span id="dot" class="ytd-video-primary-info-renderer" style="color: var(--dimmer-text)">•</span>' | |
const params = new URLSearchParams(window.location.search) | |
function mkLink(to) { | |
return $('<a>') | |
.attr('href', "mpv:youtube.com"+to) | |
.css('color', '#9AB87C') | |
.text('Play in MPV') | |
} | |
waitForKeyElements('.ytd-thumbnail', function(t) { | |
$('#buttons', t.parent().parent()) | |
.append(mkLink(t.attr('href'))) | |
}) | |
if (window.location.pathname == '/watch' && params.has('v')) { | |
waitForKeyElements('#info-text', function(t) { | |
t.append( | |
$('<div style="display: inline-block" />') | |
.append(dot) | |
.append(mkLink('/watch?v=' + params.get('v'))) | |
) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment