flash.moe/public/userscripts/mpvfriend.user.js
2020-10-30 20:29:27 +00:00

54 lines
1.3 KiB
JavaScript

// ==UserScript==
// @name mpv friend
// @version 1
// @grant none
// ==/UserScript==
/** mpvfriend.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\mpv]
@="URL:mpv"
"URL Protocol"=""
"DefaultIcon"="\"C:\\Users\\Julian\\Software\\mpv\\mpv.exe\",1"
[HKEY_CLASSES_ROOT\mpv\shell]
[HKEY_CLASSES_ROOT\mpv\shell\open]
[HKEY_CLASSES_ROOT\mpv\shell\open\command]
@="\"C:\\Users\\Julian\\Software\\mpv\\open.bat\" \"%1\""
**/
/** open.bat
@echo off
set URL=%1
mpv %URL:~0,1%%URL:~5,255%
**/
window.addEventListener('click', function(ev) {
var target = ev.target;
while(!(target instanceof HTMLAnchorElement)) {
target = target.parentNode;
if(!target)
return;
}
if(!target.href)
return;
var url = new URL(target.href);
if(url.protocol === 'mpv:')
return;
if((url.origin === 'https://www.youtube.com' && url.pathname === '/watch')) {
ev.preventDefault();
ev.stopPropagation();
var open = document.createElement('a');
open.href = 'https://flash.moe/mpv.php?url=' + encodeURIComponent(url.href);
open.target = '_blank';
document.body.appendChild(open);
open.click();
document.body.removeChild(open);
return false;
}
}, true);