rate shower

nowcoder.com通过率与通过人数切换

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         rate shower
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  nowcoder.com通过率与通过人数切换
// @author       Ygy
// @match        https://ac.nowcoder.com/acm/contest/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=nowcoder.com
// @require      https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    $(window).on('load',function () {
    let $tableHeadTrs = $(".table-hover>thead>tr>th")
    let $tableBodyTrs = $(".table-hover>tbody>tr")
    let $fixedMenu = $(".fixed-menu>ul")

    // $tableHead.append($('<th width="10%">通过率</th>'))

    let $a1 = $('<a id="a1" class="qq"></a>')
    $a1.css('background','url("")')
    // let $a1 = $('<a id="a1" class="qq" style="background: url("")"></a>')
    let $li1 = $('<li></li>').append($a1)
    $fixedMenu.append($li1)

    let flag = 1
    let columnIndex = 2
    let oriList = []
    let rateList = []


    //获取通过率列号
    columnIndex = getColumnIndex()

    console.log(columnIndex)


    //生成列表
    rateListGen(oriList, rateList)

    console.log(oriList)
    console.log(rateList)

    //绑定点击事件
    $("#a1").on('click', change)

    function change() {
        console.log("I'm clicked....")
        $tableBodyTrs.each(function (index, element) {
            let $tableBodyTds = $(element).children('td')
            // console.log($tableBodyTds[2].textContent)
            if (flag < 0) {
                $tableBodyTds[columnIndex].innerHTML = oriList[index]
            } else {
                $tableBodyTds[columnIndex].innerHTML = rateList[index]
            }
        })
        flag *= -1
    }


    //生成两列表,原始与计算后
    function rateListGen(li1, li2) {
        $tableBodyTrs.each(function (index, element) {
            let $tableBodyTds = $(element).children('td')
            // console.log($tableBodyTds[2].textContent)
            let str = $tableBodyTds[columnIndex].textContent
            li1.push(str)
            // console.log(toPercent(rateCal(str)))
            li2.push(toPercent(rateCal(str)))
        })
    }

    //计算比率
    function rateCal(str) {
        let nums = str.split('/');
        if (nums.length !== 2) return 'error!'
        let num1 = parseInt(nums[0])
        let num2 = parseInt(nums[1])
        if (num2 === 0) return 0
        else return num1 / num2
    }

    //转成百分数
    function toPercent(point) {
        let str = Number(point * 100).toFixed(2);
        str += "%";
        return str;
    }

    //获取通过率所在列
    function getColumnIndex() {
        let idx = 2
        $tableHeadTrs.each(function (index, element) {
            let str = element.innerText
            if ("通过率"===str){
                idx = index
                return false
            }
        })
        return idx
    }
});
    // Your code here...
})();