Last active
July 14, 2026 20:17
-
-
Save ergolyam/9f88c27394c25dd0e394fb4c06b8d0d9 to your computer and use it in GitHub Desktop.
Tampermonkey userscript: Opens TorrServer M3U playlists directly in mpv
This file contains hidden or 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 TorrServer playlists to mpv | |
| // @namespace local.torrserver.mpv | |
| // @version 1.2.0 | |
| // @description Opens TorrServer M3U playlists directly in mpv | |
| // @match http://192.168.1.11:8090/* | |
| // @match http://127.0.0.1:8090/* | |
| // @match http://localhost:8090/* | |
| // @run-at document-start | |
| // @sandbox raw | |
| // @grant none | |
| // ==/UserScript== | |
| (() => { | |
| 'use strict'; | |
| const originalWindowOpen = window.open; | |
| function getPlaylistUrl(value) { | |
| if (value == null) { | |
| return null; | |
| } | |
| try { | |
| const url = new URL(String(value), window.location.href); | |
| const isPlaylist = | |
| /^\/stream\/.+\.m3u8?$/i.test(url.pathname) && | |
| url.searchParams.has('link') && | |
| url.searchParams.has('m3u'); | |
| return isPlaylist ? url.href : null; | |
| } catch { | |
| return null; | |
| } | |
| } | |
| function openInMpv(playlistUrl) { | |
| const mpvUrl = `mpv://${encodeURIComponent(playlistUrl)}`; | |
| console.info('[TorrServer → mpv] Opening:', playlistUrl); | |
| window.location.assign(mpvUrl); | |
| } | |
| window.open = function (url, target, features) { | |
| const playlistUrl = getPlaylistUrl(url); | |
| if (playlistUrl) { | |
| openInMpv(playlistUrl); | |
| return null; | |
| } | |
| return Reflect.apply(originalWindowOpen, window, arguments); | |
| }; | |
| document.addEventListener( | |
| 'click', | |
| event => { | |
| if (!(event.target instanceof Element)) { | |
| return; | |
| } | |
| const anchor = event.target.closest('a[href]'); | |
| if (!anchor) { | |
| return; | |
| } | |
| const playlistUrl = getPlaylistUrl(anchor.href); | |
| if (!playlistUrl) { | |
| return; | |
| } | |
| event.preventDefault(); | |
| event.stopImmediatePropagation(); | |
| openInMpv(playlistUrl); | |
| }, | |
| true | |
| ); | |
| console.info('[TorrServer → mpv] Userscript loaded'); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment