TsinghuaCourseConflictMarker

Tsinghua Course Time Confliction Marker

目前為 2020-08-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         TsinghuaCourseConflictMarker
// @namespace    https://github.com/ZenithalHourlyRate
// @homepageURL  https://github.com/ZenithalHourlyRate/thuservices
// @version      1.4
// @description  Tsinghua Course Time Confliction Marker
// @author       Zenithal
// @match        http://zhjwxk.cic.tsinghua.edu.cn/xkBks.vxkBksXkbBs.do?m=selectKc*
// @match        http://zhjwxkyw.cic.tsinghua.edu.cn/xkBks.vxkBksXkbBs.do?m=selectKc*
// @match        https://webvpn.tsinghua.edu.cn/http/*/xkBks.vxkBksXkbBs.do?m=selectKc*
// @grant        none
// ==/UserScript==


function courseConflict(){

var a=document.getElementById('iframe2').contentWindow.document.getElementsByClassName("trunk");// get the iframe of selected courses
var b=[];
for(var i=0;i!=a.length;++i){
  if(a[i].textContent.match(/.-.(.*)/gi)){ // get the span with time information
    var m=a[i].parentElement.previousElementSibling.previousElementSibling.textContent; // course name
    m=m.replace(/\s/g,'');
    if(a[i].title == ""){ // some text is abbrevated
      var c1=a[i].textContent.split(","); // some has multiple time
      for(var j1=0;j1!=c1.length;++j1){
        b.push([c1[j1],m]);
      }
    }else{
      var c2=a[i].title.split(","); // some has multiple time
      for(var j2=0;j2!=c2.length;++j2){
        b.push([c2[j2],m]);
      }
    }
  }
}

var d=document.getElementById('iframe1').contentWindow.document.getElementsByClassName("trunk");
for(i=0;i!=d.length;++i){
  if(d[i].textContent.match(/.-.(.*)/gi)){
    var e=""
    if(d[i].title == ""){
      e=d[i].textContent;
    } else {
      e=d[i].title;
    }
    var f=e.split(',');
    for(var j=0;j!=f.length;++j){
      for(var k=0;k!=b.length;++k){
        if(f[j][0]==b[k][0][0] && f[j][2]==b[k][0][2]){ // just comparison on time, no comparison on others
          d[i].style.color="#ff0000";
          d[i].title+=b[k][1];
        }
      }
    }
  }
}

}

(function() {
    document.getElementById('iframe1').onload=courseConflict;
    document.getElementById('iframe2').onload=courseConflict;
})();