学习通阻止暂停播放

学习通

  1. // ==UserScript==
  2. // @name 学习通阻止暂停播放
  3. // @namespace https://hognbin.xyz/
  4. // @version 0.4
  5. // @description 学习通
  6. // @author 宏斌
  7. // @match https://mooc1.chaoxing.com/mycourse/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=chaoxing.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. var video;
  16. function stopPause() {
  17. video = document.querySelectorAll('iframe')[0].contentWindow.document.querySelectorAll('iframe')[0].contentWindow.document.querySelector('video');
  18. video.pause = () => {
  19. console.log('他想暂停播放');
  20. }
  21. }
  22.  
  23. function handleMute() {
  24. video = document.querySelectorAll('iframe')[0].contentWindow.document.querySelectorAll('iframe')[0].contentWindow.document.querySelector('video');
  25. video.volume = 0;
  26. }
  27.  
  28. const button = document.createElement('button');
  29. button.className = 'h_Bbutton';
  30. button.innerHTML = '阻止暂停播放';
  31. document.body.appendChild(button);
  32. Object.assign(button.style, {
  33. width: '120px',
  34. });
  35. const style = document.createElement('style');
  36. style.innerHTML = `
  37. .h_Bbutton{
  38. transition: all 0.3s linear;
  39. position: fixed;
  40. padding: 10px;
  41. border: none;
  42. background: linear-gradient(45deg, #0219f2, #c804ea);
  43. color: #fffae5;
  44. border-radius: 5px;
  45. bottom: 30px;
  46. left: 20px;
  47. box-shadow: 8px 4px 10px 3px #ccc;
  48. cursor: pointer;
  49. font-weight: bold;
  50. }
  51. .h_Bbutton:active{
  52. transform: translateY(2px);
  53. }
  54. .h_Bbutton:hover{
  55. opacity:0.8;
  56. }
  57. .h_Bbutton svg path{
  58. fill: #fffae5;
  59. }
  60. .bottom_text{
  61. position:fixed;
  62. bottom: 0;
  63. left: 0;
  64. background-color: #51f;
  65. color:#fffae5;
  66. padding: 3px 5px;
  67. font-size: 12px;
  68. border-radius: 3px;
  69. }
  70. `
  71. document.head.appendChild(style);
  72. button.onclick = verify(stopPause);
  73. /**
  74. * 添加静音按钮
  75. */
  76.  
  77. const icon = `<svg t="1647347534277" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3042" width="32" height="32"><path d="M290.133333 921.6c-3.413333 0-10.24 0-13.653333-3.413333-17.066667-6.826667-23.893333-27.306667-17.066667-44.373334l307.2-699.733333c6.826667-17.066667 23.893333-30.72 40.96-37.546667 17.066667-6.826667 37.546667-3.413333 54.613334 6.826667C757.76 194.56 819.2 296.96 819.2 409.6v201.386667l34.133333 133.12c3.413333 10.24 0 20.48-6.826666 30.72-6.826667 3.413333-17.066667 10.24-27.306667 10.24h-139.946667c-17.066667 78.506667-85.333333 136.533333-167.253333 136.533333-30.72 0-58.026667-6.826667-85.333333-23.893333-17.066667-10.24-20.48-30.72-13.653334-47.786667 10.24-17.066667 30.72-20.48 47.786667-13.653333 17.066667 10.24 34.133333 13.653333 51.2 13.653333 47.786667 0 88.746667-34.133333 98.986667-81.92 6.826667-34.133333 34.133333-54.613333 68.266666-54.613333h95.573334l-23.893334-92.16V409.6c0-85.333333-47.786667-167.253333-122.88-208.213333l-307.2 699.733333c-3.413333 10.24-17.066667 20.48-30.72 20.48zM238.933333 757.76l34.133334-136.533333V409.6c0-119.466667 88.746667-221.866667 208.213333-235.52 17.066667-3.413333 30.72-20.48 30.72-40.96-3.413333-17.066667-20.48-30.72-40.96-30.72C320.853333 122.88 204.8 256 204.8 409.6v201.386667l-34.133333 133.12c-3.413333 17.066667 6.826667 37.546667 23.893333 40.96h6.826667c17.066667 0 34.133333-10.24 37.546666-27.306667z" fill="#3E2AD1" p-id="3043"></path></svg>`
  78. const muteButton = document.createElement('button');
  79. muteButton.className = 'h_Bbutton';
  80. muteButton.innerHTML = icon;
  81. muteButton.style['left'] = '150px';
  82. muteButton.style['padding'] = '3px';
  83. muteButton.style['background'] = 'linear-gradient(45deg, #f50404, #e2ec0a)';
  84.  
  85. document.body.appendChild(muteButton);
  86. muteButton.onclick = verify(handleMute);
  87.  
  88. const autoToggleButton = document.createElement('button');
  89. autoToggleButton.className = 'h_Bbutton';
  90. autoToggleButton.innerHTML = '自动切换下集';
  91. Object.assign(autoToggleButton.style, {
  92. bottom: '80px'
  93. })
  94. autoToggleButton.onclick = verify(autoToggleNextVideo);
  95. document.body.appendChild(autoToggleButton);
  96.  
  97. function autoToggleNextVideo() {
  98. if (!video) {
  99. video = document.querySelectorAll('iframe')[0].contentWindow.document.querySelectorAll('iframe')[0].contentWindow.document.querySelector('video');
  100. }
  101. const curr = document.querySelectorAll('h4.currents')[0]
  102. if (!curr) return console.warn('获取当前活跃item失败');
  103. const nextA = curr.parentElement.nextElementSibling.querySelector('a');
  104. if (!nextA) return;
  105. video.addEventListener('ended', () => {
  106. nextA.click();
  107. });
  108. autoToggleButton.style.display = 'none';
  109.  
  110. const nextVideoText = document.createElement('span');
  111. nextVideoText.className = 'bottom_text';
  112. document.body.appendChild(nextVideoText);
  113.  
  114. const r = () => {
  115. nextVideoText.innerText = `下集:${nextA.children[0].innerText}`;
  116. setTimeout(r, 5000);
  117. }
  118. r();
  119.  
  120. }
  121.  
  122. function verify(callback) {
  123. return () => {
  124. try {
  125. callback();
  126. } catch (e) {
  127. console.error('出错!', e);
  128. alert('确保已经点开视频');
  129. }
  130. }
  131. }
  132.  
  133. })();

QingJ © 2025

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