// ==UserScript== // @name Colorful Course // @namespace http://tampermonkey.net/ // @version 0.2.1 // @description Try and see // @author Ajax // @match http://zhjwxk.cic.tsinghua.edu.cn/xkBks.vxkBksXkbBs.do?m=xkqkSearch* // @icon https://www.google.com/s2/favicons?sz=64&domain=tsinghua.edu.cn // @grant none // @license MIT // @downloadURL none // ==/UserScript== function colorOne(td, sum, available) { var l = td.text.split(","); if (l[0][0] === '(') { l = l[0].substr(1, l[0].length - 1).split(")").concat(l.slice(1)); } var html = ""; for (var i=0; i available) { html += `${l[i]},`; } else if ((sum += l[i]) > available) { html += `${l[i]},`; } else { html += `${l[i]},`; } } td.innerHTML = html.substr(0, html.length - 1); return sum; } function setOneWidth(tr) { /* tr.children[0].setAttribute("width", "70"); tr.children[1].setAttribute("width", "40"); tr.children[2].setAttribute("width", "440"); tr.children[3].setAttribute("width", "70"); tr.children[4].setAttribute("width", "50"); tr.children[5].setAttribute("width", "50"); tr.children[6].setAttribute("width", "100"); tr.children[7].setAttribute("width", "100"); tr.children[8].setAttribute("width", "100"); */ } (function() { 'use strict'; var regular = document.getElementsByName("top")[0]; setInterval(function() { var doc = regular.contentDocument; if (doc.colored === true) { return; } setOneWidth(doc.getElementsByClassName("trr1")[0]); doc.getElementsByClassName("trr2").forEach((tr) => { setOneWidth(tr); var available = Number(tr.children[4].text); var total = Number(tr.children[5].text); var sum = 0; sum = colorOne(tr.children[6], sum, available); sum = colorOne(tr.children[7], sum, available); sum = colorOne(tr.children[8], sum, available); }); doc.colored = true; }, 1000); var pe = document.getElementsByName("bottom")[0]; setInterval(function() { var doc = pe.contentDocument; if (doc.colored === true) { return; } doc.getElementsByClassName("trr2").forEach((tr) => { var available = Number(tr.children[3].text); var total = Number(tr.children[4].text); var sum = 0; sum = colorOne(tr.children[5], sum, available); }); doc.colored = true; }, 1000); })();