超星 - 修复活动页面顶栏

因为使用不安全的 HTTP 协议加载跨域的顶栏脚本,超星课程的活动页面(比如各种签到页面)的顶栏会而加载不出来;即使使用 HTTPS 协议加载顶栏脚本,又会因为跨域脚本不能使用不安全的 document.writeln() 方法而毫无作用。本脚本修复了此问题。

  1. // ==UserScript==
  2. // @name 超星 - 修复活动页面顶栏
  3. // @description 因为使用不安全的 HTTP 协议加载跨域的顶栏脚本,超星课程的活动页面(比如各种签到页面)的顶栏会而加载不出来;即使使用 HTTPS 协议加载顶栏脚本,又会因为跨域脚本不能使用不安全的 document.writeln() 方法而毫无作用。本脚本修复了此问题。
  4. // @namespace UnKnown
  5. // @author UnKnown
  6. // @icon https://imgsrc.baidu.com/forum/pic/item/6a63f6246b600c33c3d714d61c4c510fd9f9a106.jpg
  7. // @version 1.0
  8. // @match https://mobilelearn.chaoxing.com/widget/*
  9. // @grant none
  10. // @inject-into content
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. "use strict";
  15.  
  16. /*
  17. <div id="header">
  18. <!-- <iframe src="/widget/pcpick/main/header" width="100%" scrolling="no" frameborder="0" height="44px"></iframe> -->
  19. <script id="pcPassPort" type="text/javascript" charset="utf-8" xml:space="preserve" src="http://www.fanya.chaoxing.com/passport/allHead.shtml"></script>
  20. </div>
  21. */
  22.  
  23. const header = document.getElementById("header");
  24.  
  25. header !== null &&
  26. header.querySelector(
  27. ':scope > script[src="http://www.fanya.chaoxing.com/passport/allHead.shtml"]'
  28. ) !== null &&
  29. fetch(
  30. "https://fanya.chaoxing.com/passport/allHead.shtml", {
  31. method : "GET",
  32. mode : "cors",
  33. credentials : "include"
  34. }
  35. ).then(
  36. response => response.text()
  37. ).then(
  38.  
  39. text => text
  40. .match( /(?<=document\.writeln\(')[^']+(?='\);)/g )
  41. .filter( line => !/^\s+$/.test(line) )
  42. .join("\n")
  43.  
  44. ).then(
  45.  
  46. html => html.replace(
  47. /http:\/\/photo\.chaoxing\.com\//, "https://photo.chaoxing.com/"
  48. ) + "<style>.zt_u_abs:hover > .zt_u_bg { display: block; }</style>"
  49.  
  50. ).then(
  51.  
  52. // 不执行内联脚本
  53. html => header.innerHTML = html
  54.  
  55. // 执行内联脚本,无必要勿用;请自行了解和判断安全风险
  56. /* html => {
  57. header.innerHTML = "";
  58. header.appendChild(
  59. document.createRange().createContextualFragment(html)
  60. );
  61. } */
  62.  
  63. );

QingJ © 2025

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