instagram 短影音停用重播、解除靜音、增加可點擊的進度條

IG 短影音停用重播、解除靜音、增加可點擊的進度條

// ==UserScript==
// @name         instagram 短影音停用重播、解除靜音、增加可點擊的進度條
// @namespace    http://tampermonkey.net/
// @version      1.3.1
// @description  IG 短影音停用重播、解除靜音、增加可點擊的進度條
// @author       shanlan(ChatGPT o3-mini)
// @match        *://www.instagram.com/*
// @grant        none
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(function(){
'use strict';
const enhance = v => {
if(!v || v.__enhanced) return;
v.__enhanced = true;
v.loop = false;
v.addEventListener('ended',()=>{ v.pause(); v.currentTime = v.duration });
v.addEventListener('canplay', function h(){
setTimeout(()=>{
if(v.muted)
if(location.pathname.startsWith("/stories/")){
let b = v.closest('div[style*="width"]')?.parentNode?.parentNode?.parentNode
?.querySelector('div[aria-label="Toggle audio"]');
b && b.click();
} else {
v.parentElement.querySelectorAll('button').forEach(btn=>{
Object.keys(btn).some(k=> k.startsWith("__reactProps$") && String(btn[k].onClick).includes("AUDIO_STATES") && (btn.click(), true));
});
}
setTimeout(()=> v.muted && console.warn('解除靜音失敗'),300);
},100);
v.removeEventListener('canplay', h);
});
if(!v.parentElement.querySelector('.progress')){
let bar = document.createElement('div'), ind = document.createElement('div');
bar.className = 'progress';
Object.assign(bar.style, {position:'absolute', bottom:'0', left:'0', width:'100%', height:'8px', background:'rgba(0,0,0,0.5)', cursor:'pointer', zIndex:9999});
Object.assign(ind.style, {height:'100%', width:'0%', background:'#f00'});
bar.appendChild(ind);
if(getComputedStyle(v.parentElement).position === 'static') v.parentElement.style.position = 'relative';
v.parentElement.appendChild(bar);
v.addEventListener('timeupdate', ()=> ind.style.width = (v.currentTime/v.duration*100 || 0) + '%');
bar.addEventListener('click', e=>{
let r = bar.getBoundingClientRect();
v.currentTime = v.duration * ((e.clientX - r.left)/r.width);
});
}
};
const scan = n => {
if(!n) return;
n.nodeName==='VIDEO' ? enhance(n) : n.querySelectorAll?.('video').forEach(enhance);
};
new MutationObserver(ms => ms.forEach(m => m.addedNodes && m.addedNodes.forEach(scan)))
.observe(document.body, {childList:true, subtree:true});
document.querySelectorAll('video').forEach(enhance);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址