AudioPlayerLib

Library for ADDING and PLAYING AUDIO anywhere you need (Global Player)

このスクリプトは単体で利用できません。右のようなメタデータを含むスクリプトから、ライブラリとして読み込まれます: // @require https://update.greatest.deepsurf.us/scripts/490601/1347581/AudioPlayerLib.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// Library for ADDING and PLAYING AUDIO anywhere you need
/*global player*/

"use strict";

window.player = {};

player.play = function (
    source,
    { volume = 0.5, controls = false, removePlayerAfterPlayed = true },
    insertNode = document.body,
    referenceNode = null,
) {
    return new Promise((resolve) => {
        const player = document.createElement("audio");
        player.addEventListener("ended", () => {
            if (removePlayerAfterPlayed) {
                this.remove(player.id);
            }
            resolve(player);
        });
        player.id = Math.random().toString(32).substring(2);
        player.src = source;
        player.autoplay = true;
        player.controls = controls;
        player.volume = volume;
        insertNode.insertBefore(player, referenceNode);
    });
};

player.remove = function (id) {
    document.getElementById(id).remove();
};