Greasy Fork

来自缓存

Greasy Fork is available in English.

超星 - 修复活动页面顶栏

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        超星 - 修复活动页面顶栏
// @description 因为使用不安全的 HTTP 协议加载跨域的顶栏脚本,超星课程的活动页面(比如各种签到页面)的顶栏会而加载不出来;即使使用 HTTPS 协议加载顶栏脚本,又会因为跨域脚本不能使用不安全的 document.writeln() 方法而毫无作用。本脚本修复了此问题。
// @namespace   UnKnown
// @author      UnKnown
// @icon        https://imgsrc.baidu.com/forum/pic/item/6a63f6246b600c33c3d714d61c4c510fd9f9a106.jpg
// @version     1.0
// @match       https://mobilelearn.chaoxing.com/widget/*
// @grant       none
// @inject-into content
// @run-at      document-end
// ==/UserScript==

"use strict";

/*
<div id="header">
	<!-- <iframe src="/widget/pcpick/main/header" width="100%" scrolling="no" frameborder="0" height="44px"></iframe> -->
	<script id="pcPassPort" type="text/javascript" charset="utf-8" xml:space="preserve" src="http://www.fanya.chaoxing.com/passport/allHead.shtml"></script>
</div>
*/

const header = document.getElementById("header");

header !== null &&
header.querySelector(
	':scope > script[src="http://www.fanya.chaoxing.com/passport/allHead.shtml"]'
) !== null &&
fetch(
	"https://fanya.chaoxing.com/passport/allHead.shtml", {
		method      : "GET",
		mode        : "cors",
		credentials : "include"
	}
).then(
	response => response.text()
).then(

	text => text
		.match( /(?<=document\.writeln\(')[^']+(?='\);)/g )
		.filter( line => !/^\s+$/.test(line) )
		.join("\n")

).then(

	html => html.replace(
		/http:\/\/photo\.chaoxing\.com\//, "https://photo.chaoxing.com/"
	) + "<style>.zt_u_abs:hover > .zt_u_bg { display: block; }</style>"

).then(

	// 不执行内联脚本
	html => header.innerHTML = html

	// 执行内联脚本,无必要勿用;请自行了解和判断安全风险
	/* html => {
		header.innerHTML = "";
		header.appendChild(
			document.createRange().createContextualFragment(html)
		);
	} */

);