Greasy Fork

Greasy Fork is available in English.

华南师大快速登陆

当你未登录时,帮你自动进入统一认证登陆页面,免去点击各种登陆按钮。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         华南师大快速登陆
// @version      1.2
// @description  当你未登录时,帮你自动进入统一认证登陆页面,免去点击各种登陆按钮。
// @author       LittleboyHarry
// @match        *://moodle.scnu.edu.cn/*
// @match        https://ssp.scnu.edu.cn/*
// @match        *://www.scholat.com/*
// @grant        none
// @namespace http://greasyfork.icu/users/457866
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    const storageKeyForRecoverHref = '#scnu_qucik_login.save_href'

const tipsElementDefaultStyle = `
background: #00000055;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 32;
display: flex;
justify-content: center;
align-items: center;
font-size: 32px;
color: white;
text-shadow: 0 0 8px black;
`

/** @summary 只在这些站点启动自动 URL 保存 */
const hostnames = ["www.scholat.com"]

function prepareJump() {
	return new Promise(resolve => {
		//#region 提示自动跳转
		const tipsElement = document.createElement("div");
		tipsElement.style = tipsElementDefaultStyle;
		tipsElement.innerText = "… 自动跳转 …";
		document.body.appendChild(tipsElement);
		//#endregion

		//#region 保存 href
		if (hostnames.indexOf(location.hostname) !== -1)
			if (!sessionStorage.getItem(storageKeyForRecoverHref))
				sessionStorage.setItem(storageKeyForRecoverHref, location.href)
		//#endregion

		resolve();
	})
}

//#region 会话恢复控制
/** @summary 不要在这些页面恢复 */
const loginPaths = ["/login.html"]

const recoverHref = sessionStorage.getItem(storageKeyForRecoverHref)
if (recoverHref && loginPaths.indexOf(location.pathname) === -1)
	prepareJump().then(() => {
		sessionStorage.removeItem(storageKeyForRecoverHref)
		location.href = recoverHref
	})
//#endregion

/** @type {?HTMLAnchorElement} */
const { hostname } = location
switch (hostname) {
	case 'moodle.scnu.edu.cn':
		{
			const loginButton = document.querySelector(
				'.profileblock a[href$="login/index.php"]'
			);

			if (loginButton)
				prepareJump().then(() => {
					loginButton.click();
				})
			else if (location.pathname === "/login/index.php") {
				const frameHook = () => {
					const ssoButton = document.getElementById("ssobtn");
					if (ssoButton)
						prepareJump().then(() => {
							ssoButton.click();
						})
					else requestAnimationFrame(frameHook);
				};
				frameHook();
			}
		}
		break;
	case 'ssp.scnu.edu.cn':
		{
			const loginSpanElement = document.getElementById('gologin')
			if (loginSpanElement)
				prepareJump().then(() => {
					loginSpanElement.children[1].click();
				})
		}
		break;
	case 'www.scholat.com':
		{
			const loginButton = document.getElementById('loginHref')
			const loginBox = document.getElementById('portal_nologin')
			if (loginBox && loginBox.style.display === 'none') loginButton = null
			if (loginButton)
				prepareJump().then(() => {
					loginButton.click();
				});
		}
		break;
}


})();