Počítání váženého průměru bakaláři

Počítání váženého průměru známek bakaláři

当前为 2016-06-02 提交的版本,查看 最新版本

// ==UserScript==
// @name         Počítání váženého průměru bakaláři
// @namespace    none
// @version      1.2
// @description  Počítání váženého průměru známek bakaláři
// @author       Tomáš Falešník (2015)
// @match        http://znamky.zsunesco.cz/*
// @grant        none
// ==/UserScript==

WEIGHT_MAP = {
  'D': 6,
  'M': 4,
  'F': 3,
  'T': 2,
  'C': 10,
  'O': 3,
  'P': 6,
  'L': 4,
  'A': 1,
};

MARKS_TO_SKIP = ['A', 'X', '?', 'N'];

//Created by Tomáš Falešník 2015 (see the license file)
function $x(path){
  var xpath = document.evaluate(path, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  var temp = [];

  for (var i = xpath.snapshotLength - 1; i >= 0; i--) {
    temp.push(xpath.snapshotItem(i));
  }
return temp;
}

  
  var subjects = $x("//div[@class='nazevprdiv']/a");
  var subjectWrapp = $x("//div[@class='nazevprdiv']");
  

  //Here starts the loop that cycles trought subjects 
  for(var i = 0; subjects.length > i; i++){
    var weightedMarks = 0;
    var summedWeights = 0;

    var subjectName = subjects[i].innerHTML;
    var marks = $x("//div[@class='nazevprdiv' and ./a[text()='" + subjectName + "']]/../../td/table/tbody/tr[@class='detznamka']/td");
    var weights = $x("//div[@class='nazevprdiv' and ./a[text()='" + subjectName + "']]/../../td/table/tbody/tr[@class='typ']/td");  

    //Here starts the loop that cycles trought marks of selected subject
    for(var o = 0; marks.length > o; o++){
      var crrWeight = WEIGHT_MAP[weights[o].innerHTML];
      var crrMark = marks[o].innerHTML;

      if(crrWeight === undefined) {
        // Badly specified weight, skip it
        continue;
      }

      if(MARKS_TO_SKIP.indexOf(crrMark) != -1){
        //Skips the math process if the mark is A, X, ? or N
        continue;
      }else{
        //the math process
        weightedMarks += parseInt(crrWeight) * parseInt(crrMark);
        summedWeights += parseInt(crrWeight);
      }
    }
  //Counts the weighted average and adds it to the document
  var result = Math.round((parseInt(weightedMarks) / parseInt(summedWeights)) * 100) / 100;
  subjectWrapp[i].innerHTML += '<div class="nazevpr" style="text-align:left;font-size:9pt;text-decoration:none;">' + result + '</div>';
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址