// ==UserScript== // @name Twitch Auto Click Channel Points Chest and Statistics // @name:zh-TW Twitch 自動點擊忠誠點數寶箱和統計 // @name:zh-CN Twitch 自动点击忠诚点数宝箱和统计 // @namespace http://tampermonkey.net/ // @version 1.8 // @description Automatically click the Twitch channel points chest, monitor all point increases, and reset the accumulated total when switching channels. // @description:zh-TW 自動點擊 Twitch 忠誠點數寶箱,並監控所有點數增加,切換直播間累積歸零 // @description:zh-CN 自动点击 Twitch 忠诚点数宝箱,并监控所有点数增加,切换直播间累积归零 // @author chatgpt // @match https://www.twitch.tv/* // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; let totalPoints = 0; let lastPoints = null; let lastUrl = location.href; // 建立提示框 function createPanel() { const panel = document.createElement('span'); panel.id = 'my-loyalty-points-panel'; panel.style.background = '#18181b'; panel.style.color = '#dedee3'; panel.style.padding = '2px 8px'; panel.style.marginLeft = '8px'; panel.style.borderRadius = '8px'; panel.style.fontSize = '14px'; panel.style.verticalAlign = 'middle'; panel.style.display = 'inline-block'; panel.style.zIndex = 9999; panel.innerText = `累積領取:${totalPoints} 點`; return panel; } // 插入提示框到忠誠點數旁邊(不覆蓋原本內容) function insertPanel() { const oldPanel = document.getElementById('my-loyalty-points-panel'); if (oldPanel) oldPanel.remove(); const balance = document.querySelector('div[data-test-selector="copo-balance-string"]'); if (balance) { const panel = createPanel(); balance.parentNode.insertBefore(panel, balance.nextSibling); } } // 更新提示框內容 function updatePanel() { const panel = document.getElementById('my-loyalty-points-panel'); if (panel) { panel.innerText = `累積領取:${totalPoints} 點`; } } // 監控寶箱出現並自動點擊 function checkAndClickChest() { const chest = document.querySelector('button[aria-label="領取額外獎勵"]'); if (chest && !chest.disabled) { chest.click(); } } // 監控忠誠點數變化 function watchPointsChange() { const balanceSpan = document.querySelector('div[data-test-selector="copo-balance-string"] span'); if (!balanceSpan) return; const currentPoints = parseInt(balanceSpan.textContent.replace(/,/g, ''), 10); if (lastPoints !== null && currentPoints > lastPoints) { const diff = currentPoints - lastPoints; totalPoints += diff; updatePanel(); } lastPoints = currentPoints; } // 監控網址變化(切換直播間時歸零) function watchUrlChange() { if (location.href !== lastUrl) { lastUrl = location.href; // 歸零 totalPoints = 0; updatePanel(); // 等待新直播間的點數渲染出來 setTimeout(() => { const balanceSpan = document.querySelector('div[data-test-selector="copo-balance-string"] span'); if (balanceSpan) { lastPoints = parseInt(balanceSpan.textContent.replace(/,/g, ''), 10); } else { lastPoints = null; } }, 1500); } } // 每 2 秒檢查一次 setInterval(() => { insertPanel(); checkAndClickChest(); watchPointsChange(); watchUrlChange(); }, 2000); // 初始也執行一次 setTimeout(() => { insertPanel(); const balanceSpan = document.querySelector('div[data-test-selector="copo-balance-string"] span'); if (balanceSpan) { lastPoints = parseInt(balanceSpan.textContent.replace(/,/g, ''), 10); } watchPointsChange(); }, 1000); })();