您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Allow Instagram Stories to play in the background
当前为
// ==UserScript== // @name Instagram Stories Background Playback // @namespace http://tampermonkey.net/ // @version 1.0 // @description Allow Instagram Stories to play in the background // @author HaiDang // @match https://*.instagram.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=instagram.com // @grant none // @run-at document-start // ==/UserScript== (function() { 'use strict'; const config = { debug: false, events: ['visibilitychange', 'blur', 'freeze', 'resume', 'pause'], checkInterval: 500, videoSelectors: [ 'video[class*="Story"]', 'video[class*="stories"]', 'video[class*="Reel"]', 'video[class*="reels"]', 'video[class*="Video"]', 'video._aa63' ] }; const logger = { log: (message) => { if (config.debug) { console.log(`[IG Stories Background] ${message}`); } }, error: (message) => { if (config.debug) { console.error(`[IG Stories Background] Error: ${message}`); } } }; const handleEvent = (evt) => { logger.log(`${evt.type} event intercepted`); evt.stopImmediatePropagation(); }; const ensureVideoPlaying = () => { const videoElements = config.videoSelectors .map(selector => [...document.querySelectorAll(selector)]) .flat(); videoElements.forEach((video) => { if (video.paused && !video.ended) { video.play() .then(() => logger.log('Video resumed successfully')) .catch((err) => logger.error(`Play failed: ${err.message}`)); } video.controls = true; video.onpause = null; video.onblur = null; video.onfocus = null; }); }; const initEventListeners = () => { config.events.forEach((eventName) => { document.addEventListener(eventName, handleEvent, { capture: true, passive: false }); window.addEventListener(eventName, handleEvent, { capture: true, passive: false }); }); }; const initVideoObserver = () => { const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { if (mutation.addedNodes.length > 0) { ensureVideoPlaying(); } }); }); observer.observe(document.body, { childList: true, subtree: true }); }; const init = () => { logger.log('Initializing Instagram background playback script'); initEventListeners(); if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initVideoObserver); } else { initVideoObserver(); } setInterval(ensureVideoPlaying, config.checkInterval); }; init(); })();