// ==UserScript== // @name 外挂弹幕插件 // @version 0.2.1 // @description 为任意网页播放器提供了加载本地弹幕的功能 // @author DeltaFlyer // @copyright 2023, DeltaFlyer(https://github.com/DeltaFlyerW) // @license MIT // @match https://pan.baidu.com/pfile/video* // @match https://www.aliyundrive.com/drive/legacy* // @match https://www.tucao.cam/play/* // @run-at document-start // @grant unsafeWindow // @grant GM_setValue // @grant GM_getValue // @icon https://avatars.githubusercontent.com/u/1879224?v=4 // @require https://cdn.jsdelivr.net/npm/@xpadev-net/niconicomments@0.2.55/dist/bundle.min.js // @require https://cdn.jsdelivr.net/npm/danmaku@2.0.6/dist/danmaku.min.js // @namespace https://greasyfork.org/users/927887 // @downloadURL none // ==/UserScript== (async function main() { async function waitForDOMContentLoaded() { return new Promise((resolve) => { console.log(document.readyState) if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', resolve); } else { resolve(); } }); } async function sleep(time) { await new Promise((resolve) => setTimeout(resolve, time)); } await waitForDOMContentLoaded() let danmakuPlayer let toastText = (function () { let html = `
` document.body.insertAdjacentHTML("beforeend", html) let bubbleContainer = document.querySelector('.df-bubble-container') function createToast(text) { console.log('toast', text) const bubble = document.createElement('div'); bubble.classList.add('df-bubble'); bubble.textContent = text; bubbleContainer.appendChild(bubble); setTimeout(() => { bubble.classList.add('df-show-bubble'); setTimeout(() => { bubble.classList.remove('df-show-bubble'); setTimeout(() => { bubbleContainer.removeChild(bubble); }, 500); // Remove the bubble after fade out }, 3000); // Show bubble for 3 seconds }, 100); // Delay before showing the bubble } return createToast })(); let loadDanmaku = (function () { let [loadNicoCommentArt, clearNicoComment] = (function loadNicoCommentArt() { function buildCanvas() { // Get a reference to the existing element in the document let html = `