flash.moe/public/userscripts/mpvfriend.user.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-10-03 16:22:14 +00:00
// ==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) {
2020-10-30 20:29:27 +00:00
var target = ev.target;
while(!(target instanceof HTMLAnchorElement)) {
2020-10-03 16:22:14 +00:00
target = target.parentNode;
2020-10-30 20:29:27 +00:00
if(!target)
2020-10-03 16:22:14 +00:00
return;
}
2020-10-30 20:29:27 +00:00
if(!target.href)
return;
var url = new URL(target.href);
if(url.protocol === 'mpv:')
2020-10-03 16:22:14 +00:00
return;
if((url.origin === 'https://www.youtube.com' && url.pathname === '/watch')) {
2020-10-30 20:29:27 +00:00
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;
2020-10-03 16:22:14 +00:00
}
}, true);