// ==UserScript== // @name 软通视频自动播放 // @namespace http://tampermonkey.net/ // @version 0.8 // @description 免责声明:此程序只供学习和研究使用,不得用于商业或者非法用途,否则后果自负。本程序的开发者不承担任何法律责任。使用本程序造成的一切后果由使用者自行承担,与本程序的开发者无关。使用本程序即表示您已经接受了本声明。 // @author zxpzdtom // @match https://*.issedu365.com/application/appcoursedetail/* // @icon https://eco.issedu365.com/ouselres/dashboard/static/frontend/img/favicon.ico // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; // 播放按钮特征与弹窗按钮选择器 const PLAY_IMAGES = ['image.c7eab1877a.png', 'image.8e7adf217a.png']; const PLAY_SVG = { viewBox: '0 0 70 70', path: 'M576,363L810,512L576,661' }; const DIALOGS = [ 'body > div.el-dialog__wrapper > div > div.el-dialog__footer > span > button', 'body > div.el-message-box__wrapper > div > div.el-message-box__btns > button', ]; const isVisible = el => el && el.isConnected && el.getBoundingClientRect().width > 0; const isPlaySvg = svg => { const vb = (svg.getAttribute('viewBox') || '').replace(/\s+/g, ' ').trim(); const path = svg.querySelector('path[transform]'); return vb === PLAY_SVG.viewBox && !!(path && (path.getAttribute('d') || '').indexOf(PLAY_SVG.path) !== -1); }; // 点击元素及其可见父级(事件常绑定在外层容器) const clickWithParent = el => { try { el.click(); } catch (e) {} let p = el.parentElement; for (let i = 0; p && p !== el.ownerDocument.body && i < 3; i++, p = p.parentElement) { if (isVisible(p)) { try { p.click(); } catch (e) {} } } }; // 强制播放(muted 防止被自动播放策略拦截) const forcePlay = v => { v.muted = true; if (v.paused) v.play().catch(() => {}); }; // 顶层 + 所有同域 iframe(视频在 iframe 内) const getDocs = () => { const docs = [document]; document.querySelectorAll('iframe').forEach(f => { try { const d = f.contentDocument; if (d && d !== document) docs.push(d); } catch (e) {} }); return docs; }; const tick = doc => { // 点击播放按钮(背景图 / title / SVG 三种方式) doc.querySelectorAll('*').forEach(el => { if (!isVisible(el)) return; const bg = window.getComputedStyle(el).backgroundImage; if (bg && PLAY_IMAGES.some(n => bg.indexOf(n) !== -1)) clickWithParent(el); }); doc.querySelectorAll('[title*="Play video" i], [aria-label*="Play video" i]').forEach(el => { if (isVisible(el)) clickWithParent(el); }); doc.querySelectorAll('svg').forEach(svg => { if (isVisible(svg) && isPlaySvg(svg)) clickWithParent(svg); }); // 强制播放并绑定暂停自动恢复 doc.querySelectorAll('video').forEach(v => { forcePlay(v); if (!v.dataset.aixAutoPlay) { v.dataset.aixAutoPlay = '1'; v.addEventListener('pause', () => forcePlay(v)); } }); }; // 监听新出现的 video new MutationObserver(() => tick(document)).observe(document.body, { childList: true, subtree: true }); // 自动退出全屏 document.addEventListener('fullscreenchange', () => { if (document.fullscreenElement) document.exitFullscreen(); }); // 主轮询 setInterval(() => { getDocs().forEach(tick); DIALOGS.forEach(s => { const b = document.querySelector(s); if (b) b.click(); }); }, 2000); })();