Greasy Fork 还支持 简体中文。

Plex Media Server beta update link fixer

Plex Media Server has been corrupting update download links for users on the beta channel on linux. This user-script "turns up the geek", and fixes the links to point to the correct address.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name       Plex Media Server beta update link fixer
// @namespace  http://mathemaniac.org/
// @version    1.0.1
// @description  Plex Media Server has been corrupting update download links for users on the beta channel on linux. This user-script "turns up the geek", and fixes the links to point to the correct address.
// @match        https://app.plex.tv/desktop*
// @copyright  2022, Sebastian Paaske Tørholm
// @require    https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @grant none
// ==/UserScript==

// See https://forums.plex.tv/t/server-download-link-hiding-makes-it-useless/791780 for context.

/* jshint -W097 */
/* eslint-env jquery */
'use strict';

// Automatically fix broken links back into correct ones - and hide the link in the Shadow DOM, so the token isn't removed again.
function fixLink(elm) {
    let link = elm.href.replace('xxxxxxxxxxxxxxxxxxxx', localStorage.myPlexAccessToken);
    let shadowDOM = elm.parentNode.attachShadow({ mode: 'closed' });
    elm.remove();
    elm.href = link;

    let styleSheets = document.querySelectorAll('link[rel="stylesheet"]');
    for (let ss of styleSheets) {
        shadowDOM.appendChild(ss.cloneNode());
    }

    shadowDOM.appendChild(elm);
}

$(function () {
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
    var config = { childList: true, characterData: false, attributes: true, subtree: true };
    var observer = new MutationObserver( function (mutations) {
        mutations.forEach( function (mutation) {
            if (mutation.type == 'childList') {
                for (let m of mutation.addedNodes) {
                    $('a[href^="https://plex.tv/downloads/latest"]', m).each(function () { fixLink(this) });
                }
            } else if (mutation.type == 'attributes') {
                if (mutation.attributeName == 'href' && $(mutation.target).attr('href').match(/^https:\/\/plex\.tv\/downloads\/latest/)) {
                    fixLink(mutation.target);
                }
            }
        });
    });

    observer.observe(document.querySelector('#plex'), config);

    $('a[href^="https://plex.tv/downloads/latest"]').each( function () {
        fixLink(this);
    });
});