Created
June 21, 2026 03:55
-
-
Save dodola/a633c4a09eb05d5552038e8be4802fec to your computer and use it in GitHub Desktop.
englishsponge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name EnglishSponge 视频跳转修复 | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.3 | |
| // @description 点击锁定视频直接跳转 YouTube 播放 | |
| // @author You | |
| // @match https://englishsponge.com/* | |
| // @grant GM_addStyle | |
| // @run-at document-idle | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| GM_addStyle(` | |
| div[style*="rgba(0, 0, 0, 0.3)"] { pointer-events: none !important; } | |
| .z-30 { pointer-events: none !important; } | |
| `); | |
| // 从缩略图提取 YouTube ID | |
| function getYoutubeId(card) { | |
| const img = card.querySelector('img[src*="youtube.com"]'); | |
| if (img) { | |
| const match = img.src.match(/\/vi\/([^/]+)\//); | |
| if (match) return match[1]; | |
| } | |
| return null; | |
| } | |
| // 从 React fiber 提取 | |
| function getYoutubeIdFromReact(card) { | |
| for (const key of Object.keys(card)) { | |
| if (key.startsWith('__reactFiber$')) { | |
| let fiber = card[key]; | |
| for (let i = 0; i < 15; i++) { | |
| if (!fiber) break; | |
| const props = fiber.memoizedProps || fiber.pendingProps; | |
| if (props?.item?.link) return props.item.link; | |
| if (props?.link && props.link.length === 11) return props.link; | |
| if (props?.data?.link) return props.data.link; | |
| fiber = fiber.return; | |
| } | |
| } | |
| } | |
| return null; | |
| } | |
| // 打开 YouTube | |
| function openYoutube(videoId) { | |
| if (!videoId) { | |
| alert('无法获取视频 ID'); | |
| return; | |
| } | |
| const url = `https://www.youtube.com/watch?v=${videoId}`; | |
| console.log('[ES Fix] 打开 YouTube:', url); | |
| window.open(url, '_blank'); | |
| } | |
| // 移除 Premium 弹窗 | |
| function removePremiumPopup() { | |
| document.querySelectorAll('[class*="modal"], [class*="Modal"], [role="dialog"]').forEach(el => { | |
| if (el.textContent.includes('Premium')) { | |
| el.remove(); | |
| } | |
| }); | |
| document.querySelectorAll('h2, h3, p, span').forEach(el => { | |
| if (el.textContent.includes('Join EnglishSponge Premium')) { | |
| let p = el; | |
| for (let i = 0; i < 8; i++) { | |
| if (!p.parentElement) break; | |
| p = p.parentElement; | |
| const s = window.getComputedStyle(p); | |
| if (s.position === 'fixed' || s.position === 'absolute' || parseInt(s.zIndex) > 100) { | |
| p.remove(); | |
| break; | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| // 拦截点击 | |
| document.addEventListener('click', function(e) { | |
| const card = e.target.closest('[class*="cursor-pointer"]'); | |
| if (!card) return; | |
| const hasLock = card.querySelector('div[style*="rgba(0, 0, 0, 0.3)"]') || card.querySelector('.z-30'); | |
| if (!hasLock) return; | |
| e.preventDefault(); | |
| e.stopPropagation(); | |
| removePremiumPopup(); | |
| const videoId = getYoutubeIdFromReact(card) || getYoutubeId(card); | |
| console.log('[ES Fix] YouTube ID:', videoId); | |
| setTimeout(() => openYoutube(videoId), 100); | |
| }, true); | |
| // 定期清理弹窗 | |
| setInterval(removePremiumPopup, 500); | |
| // 监听 DOM 变化 | |
| new MutationObserver(removePremiumPopup).observe(document.body, { childList: true, subtree: true }); | |
| // 提示 | |
| const tip = document.createElement('div'); | |
| tip.textContent = '✓ 点击锁定视频将直接打开 YouTube'; | |
| tip.style.cssText = 'position:fixed;bottom:20px;left:50%;transform:translateX(-50%);background:#4ade80;color:#000;padding:10px 20px;border-radius:8px;font-weight:bold;z-index:999999;box-shadow:0 4px 12px rgba(0,0,0,0.3);'; | |
| document.body.appendChild(tip); | |
| setTimeout(() => { tip.style.transition='opacity 0.5s'; tip.style.opacity='0'; setTimeout(()=>tip.remove(),500); }, 3000); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment