Skip to content

Instantly share code, notes, and snippets.

@NightFeather
Last active April 24, 2020 06:00
Show Gist options
  • Save NightFeather/59a14a0beed3e427c1dba4514b4bb7e0 to your computer and use it in GitHub Desktop.
Save NightFeather/59a14a0beed3e427c1dba4514b4bb7e0 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name 逢甲微學分選課為啥不標禮拜幾
// @namespace https://gist.github.com/NightFeather/59a14a0beed3e427c1dba4514b4bb7e0
// @description 逢甲微學分選課為啥不標禮拜幾
// @author Nightfeather
// @copyright Nightfeather (https://github.com/Nightfeather)
// @liscense MIT (https://mit-license.org/)
// @version 0.4.1
// @downloadURL https://gist.github.com/NightFeather/59a14a0beed3e427c1dba4514b4bb7e0/raw/micro-timestamp.user.js
// @updateURL https://gist.github.com/NightFeather/59a14a0beed3e427c1dba4514b4bb7e0/raw/micro-timestamp.user.js
// @include https://myfcu.fcu.edu.tw/main/S3204/S3204_micro_credit.aspx
// @grant none
// ==/UserScript==
(function() {
function addWeekDay(mutRecs,obs) {
mutRecs.forEach(function(mutRec) {
if(!mutRec.addedNodes || mutRec.addedNodes.length <= 0) { return }
let weekday = "日一二三四五六".split("")
let matchDate = /\d{4}\/\d{2}\/\d{2}/
mutRec.addedNodes.forEach(function(node) {
if(!(node instanceof HTMLTableRowElement)) {
return
}
let el = null
if (node.children.length == 10)
el = node.querySelector('td:nth-child(9)')
else if (node.children.length == 7)
el = node.querySelector('td:nth-child(7)')
if(!el) { return }
let t = el.innerText
let m = t.match(matchDate)
if(m) {
let d = new Date(m[0])
el.innerText = t.replace(m[0], `${m[0]} (${weekday[d.getDay()]})`)
}
})
})
}
function setup(ev) {
if(typeof DPDate != 'undefined') { return } // well, why the datepicker is an iframe of same uri!?
if(document.readyState == 'interactive' || document.readyState == 'complete'){
let mode = document.querySelector('.container > select').value
let modename = document.querySelector(`.container > select option[value="${mode}"]`).label.trim()
if(!mode || modename != '通識微學分') {
console.debug(`not in general credit mode, not interested. current: ${modename}`)
document.querySelector('.container > select').addEventListener('change', checkMode)
return
}
let mut = new MutationObserver(addWeekDay)
mut.observe(document.querySelector('.container > div'), { childList: true, subtree: true })
document.remoteEventListener('readystatechange', setup)
}
}
function checkMode(ev) {
let mode = document.querySelector('.container > select').value
let modename = document.querySelector(`.container > select option[value="${mode}"]`).label.trim()
if(!mode || modename != '通識微學分') {
console.debug(`not in general credit mode, not interested. current: ${modename}`)
return
}
console.debug(`in general credit mode, setup.`)
document.querySelector('.container > select').removeEventListener('change', checkMode)
setup()
}
document.addEventListener('readystatechange', setup)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment