Created
March 28, 2020 13:19
-
-
Save ZeppLu/cad854e33a707f33cffd553a0872aea8 to your computer and use it in GitHub Desktop.
点击智慧教室按钮,直接打开直播页面,再也无需繁琐的跳转与新窗口
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name UCAS Live Classroom Shortcut | |
// @name:zh-CN UCAS 智慧教室一键直达 | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author Zepp | |
// @match http://course.ucas.ac.cn/portal/site/* | |
// @match https://course.ucas.ac.cn/portal/site/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// 左边侧栏的智慧教室按钮,及链接到的URL | |
const button = document.querySelector("a[title='智慧教室 - 智慧教室']"); | |
const doorUUID = button.onclick.toString().match(/[-0-9a-f]{36}/); | |
const doorURL = `https://course.ucas.ac.cn/portal/page/${doorUUID}`; | |
console.log(`doorURL: ${doorURL}`); | |
// fetch()是异步方法,返回一个Promise,which将返回一个Response(继承自Body) | |
// Response.text()返回的也是Promise,所以后面还需要套一层then()才能处理文本 | |
// SEE: https://developer.mozilla.org/en-US/docs/Web/API/Response | |
fetch(doorURL).then(r => r.text()).then( text => { | |
// 直播页面真正的URL | |
// match()返回的第0个元素是匹配到的串,后面则是按顺序的各个group | |
const roomUUID = text.match(/<a class="Mrphs-toolTitleNav__link--inline" href=".*([-0-9a-f]{36})/)[1]; | |
const roomURL = `https://course.ucas.ac.cn/portal/tool/${roomUUID}/main/room`; | |
console.log(`roomURL: ${roomURL}`); | |
// 修改页面 | |
button.href = roomURL; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment