YouTube Embed: Use Storage Access API

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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 --")
}