YouTube Embed: Use Storage Access API

Use Storage Access API to Play YouTube (Music)? Premium Required Videos on Embed Player

目前為 2022-04-08 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        YouTube Embed: Use Storage Access API
// @namespace   https://rinsuki.net
// @match       https://www.youtube.com/embed/*
// @grant       none
// @version     1.0
// @author      rinsuki
// @license     MIT
// @description Use Storage Access API to Play YouTube (Music)? Premium Required Videos on Embed Player
// ==/UserScript==

if ("requestStorageAccess" in document) {
    document.requestStorageAccess().then(()=> {
        console.warn("[UserScript] --- requestStorageAccess success ---")
    }, () => {
        console.warn("[UserScript] --- requestStorageAccess failed ---")
    })
    
    const origOpen = XMLHttpRequest.prototype.open
    const origSend = XMLHttpRequest.prototype.send
    const weakMap = new WeakMap()
    
    // addEventListener("mouseenter", () => document.requestStorageAccess())
    
    XMLHttpRequest.prototype.open = function(method, url, ...args) {
        weakMap.set(this, url)
        return origOpen.apply(this, [method, url, ...args])
    }
    
    XMLHttpRequest.prototype.send = function(...args) {
        const url = weakMap.get(this)
        if (!url.includes("youtubei/v1/player")) {
            return origSend.apply(this, args)
        }
        document.requestStorageAccess().then(()=> {
            console.warn("[UserScript] --- requestStorageAccess success ---")
        }, () => {
            console.warn("[UserScript] --- requestStorageAccess failed ---")
        }).then(() => {
            origSend.apply(this, args)
        })
    }
} else {
    console.warn("[UserScript] -- requestStorageAccess not found --")
}