您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
影片播放超過指定時間自動按讚,同網址只會執行一次,換影片才重跑
当前为
// ==UserScript== // @name B站自動按讚 // @namespace http://tampermonkey.net/ // @version 0.3 // @description 影片播放超過指定時間自動按讚,同網址只會執行一次,換影片才重跑 // @author You // @match https://www.bilibili.com/video/* // @grant none // ==/UserScript== (function() { let observer = null; let lastUrl = null; // 記錄上次執行的網址] let currentTimer = null; // 記錄排程用 function runMyScript() { const video = document.querySelector("video"); const currentUrl = window.location.href; if (currentUrl === lastUrl) { console.log("⚠️ 網址相同,跳過 runMyScript"); return; } lastUrl = currentUrl; if ((video) && currentUrl.includes("/video/")) { console.log("找到新影片:", video); // 避免重複排定,先清掉舊的 if (currentTimer) { clearTimeout(currentTimer); currentTimer = null; } function isVideoPlaying(video) { return !!(video && !video.paused && !video.ended && video.readyState > 2); } currentTimer = setTimeout(() => { const video = document.querySelector('video'); if (isVideoPlaying(video)) { console.log('正在播放,執行按讚'); triggerLikeButton(); } else { console.log('未播放,不執行'); } currentTimer = null; // 執行後清空 }, 60000); } } function triggerLikeButton() { const likeButton = document.querySelector('div.video-like'); if (likeButton) { if (likeButton.classList.contains('on')) { console.log('✅ 已經按過讚,跳過'); showMsg(); return; } likeButton.click(); console.log('👍 已按讚'); } else { console.log('❌ 找不到按讚按鈕'); } } // 顯示提示訊息 function showMsg() { const msg = document.createElement('div'); msg.textContent = '按讚過了'; Object.assign(msg.style, { position: 'fixed', left: '50%', transform: 'translateX(-50%)', top: '30%', padding: '10px 20px', background: 'rgba(0,0,0,0.8)', color: '#fff', borderRadius: '8px', zIndex: 9999, fontSize: '16px', opacity: '0', transition: 'opacity 0.3s' }); document.body.appendChild(msg); setTimeout(() => { msg.style.opacity = '1'; }, 10); setTimeout(() => { msg.style.opacity = '0'; setTimeout(() => { document.body.removeChild(msg); }, 300); }, 2500); } // 啟動監聽,偵測 video 的 src 是否切換 function startObserver() { const video = document.querySelector("video"); if (!video) { console.log('⚠️ 找不到 <video>'); return; } if (observer) { observer.disconnect(); } observer = new MutationObserver((mutationsList) => { for (const mutation of mutationsList) { if (mutation.type === 'attributes' && mutation.attributeName === 'src') { console.log('🎥 偵測到影片切換'); runMyScript(); } } }); observer.observe(video, { attributes: true, attributeFilter: ['src'] }); // 播放事件觸發也檢查一次(但同網址不會重複) video.addEventListener('play', () => { console.log('▶️ 播放觸發'); runMyScript(); }); console.log('✅ 監聽啟動完畢'); } // 初始執行 runMyScript(); startObserver(); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址