Last active
September 2, 2022 07:07
-
-
Save supersonictw/81535219f2505a29b4787935c851d6ed to your computer and use it in GitHub Desktop.
NKUST 衝堂過濾腳本
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 取得基本課表資料 | |
// @namespace https://gist.github.com/supersonictw/81535219f2505a29b4787935c851d6ed | |
// @version 0.1.7 | |
// @description 把高科課表轉為JSON資料型態 | |
// @author SuperSonic (https://github.com/supersonictw) | |
// @match https://mobile.nkust.edu.tw/Student/Course* | |
// @license MIT License | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
function exporter() { | |
const translation = { | |
"(一)": "Mon", | |
"(二)": "Tue", | |
"(三)": "Wed", | |
"(四)": "Thu", | |
"(五)": "Fri", | |
}; | |
const storage = {}; | |
document.querySelectorAll("tr.odd, tr.even").forEach((dom) => | |
Array.from(dom.childNodes) | |
.filter( | |
(node) => | |
node.textContent.match(/([1-9])[\-]([1-9])/gm) && | |
node.textContent.trim().length === 6 | |
) | |
.forEach((node) => { | |
const dayName = node.textContent.trim(); | |
const itemKey = translation[dayName.substring(0, 3)]; | |
if (!(itemKey in storage)) { | |
storage[itemKey] = []; | |
} | |
storage[itemKey].push( | |
dayName | |
.substring(3) | |
.split("-") | |
.map((value) => parseInt(value)) | |
); | |
}) | |
); | |
prompt("您的基本課表資料:", JSON.stringify(storage)); | |
} | |
const notice = document.createTextNode("輸出基本課表資料"); | |
const trigger = document.createElement("div"); | |
trigger.style.background = "#fff"; | |
trigger.style.boxShadow = "0 0 3px #777"; | |
trigger.style.borderRadius = "50px"; | |
trigger.style.position = "absolute"; | |
trigger.style.padding = "10px 5px"; | |
trigger.style.zIndex = "36"; | |
trigger.style.cursor = "pointer"; | |
trigger.style.right = "33px"; | |
trigger.style.top = "70px"; | |
trigger.appendChild(notice); | |
trigger.addEventListener("click", exporter); | |
document.body.appendChild(trigger); | |
})(); |
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 衝堂過濾腳本 | |
// @namespace https://gist.github.com/supersonictw/81535219f2505a29b4787935c851d6ed | |
// @version 0.1.3 | |
// @description 把衝堂的課程變成透明 | |
// @author SuperSonic (https://github.com/supersonictw) | |
// @include /^https://aais[0-9].nkust.edu.tw/selcrs_std/FirstSelect/SelectPage*/ | |
// @license MIT License | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
"use strict"; | |
function datetimeExporter(item) { | |
const [day, time] = item.split("."); | |
const [minTime, maxTime] = time.split("-").map((value) => parseInt(value)); | |
return { day, time, minTime, maxTime }; | |
} | |
function filter() { | |
if (!("fixData" in window)) { | |
const rawData = prompt("請輸入基本課表資料:"); | |
window.fixData = JSON.parse(rawData); | |
} | |
if (window.fixData === null) { | |
document.removeEventListener("click", executor); | |
return; | |
} | |
document.querySelectorAll("tr.odd, tr.even").forEach((dom) => | |
Array.from(dom.childNodes) | |
.filter((node) => | |
node.textContent.match(/[A-Z][a-z][a-z].[0-9]\-[0-9]/) | |
) | |
.forEach((node) => { | |
const dateData = datetimeExporter(node.textContent); | |
if (dateData.day in window.fixData) { | |
window.fixData[dateData.day].forEach((item) => { | |
if ( | |
(item[0] <= dateData.minTime && item[1] >= dateData.maxTime) || | |
(item.includes(dateData.minTime) || item.includes(dateData.maxTime)) | |
) { | |
dom.style.opacity = "0.5"; | |
} | |
}); | |
} | |
}) | |
); | |
} | |
function executor() { | |
setTimeout(filter, 500); | |
} | |
document.addEventListener("click", executor); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment