51Talk.辅助选老师-有效经验值|好评率|年龄|Top 5

有效经验值=所有标签数量相加后除以5;好评率=好评数/总评论数;年龄根据你的喜好选择。

目前為 2019-08-10 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         51Talk.辅助选老师-有效经验值|好评率|年龄|Top 5
// @version      0.0.16
// @namespace    tsharp.js.51talk_sort
// @description  有效经验值=所有标签数量相加后除以5;好评率=好评数/总评论数;年龄根据你的喜好选择。
// @author       jimbo
// @license      GPLv3
// @match        https://www.51talk.com/ReserveNew/index*
// @match        http://www.51talk.com/ReserveNew/index*
// @icon         https://avatars3.githubusercontent.com/u/25388328
// @grant        GM_xmlhttpRequest
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @require      https://code.jquery.com/ui/1.12.1/jquery-ui.min.js
// ==/UserScript==

(function () {
    'use strict';
    $("head").append(
        '<link '
        + 'href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" '
        + 'rel="stylesheet" type="text/css">'
    );
    function sleep(delay) {
        var start = (new Date()).getTime();
        while ((new Date()).getTime() - start < delay) {
            continue;
        }
    }
    //删除数组中的空元素
    Array.prototype.clean = function (deleteValue = "") {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == deleteValue) {
                this.splice(i, 1);
                i--;
            }
        }
        return this;
    };

    function teacher_sort(a, b) {
        return b - a;
    }
    /**
     * 提交运算函数到 document 的 fx 队列
     */
    var submit = function (fun) {
        //debugger;
        var queue = $.queue(document, "fx", fun);
        if (queue[0] == 'inprogress') {
            return;
        }
        $.dequeue(document);
    };
    let num = /[0-9]*/g;
    $.each($(".item-top-cont"), function (i, item) {
        item.innerHTML = item.innerHTML.replace('<!--', '').replace('-->', '');
    });
    let i_len = $(".item").length;
    let value = [];
    var callbacks = [];
    for (let i = 0; i < i_len; i++) {
        let j_len = $($(".item")[i]).find(".label").text().match(num).clean("").length;
        value[i] = 0;
        for (let j = 0; j < j_len; j++) {
            value[i] += Number($($(".item")[i]).find(".label").text().match(num).clean("")[j]);
        }
        value[i] = Math.ceil(value[i] / 5);
        $(".teacher-name")[i].innerText += "[" + value[i] + "]";
        $($(".item")[i]).attr('label', value[i]);
        callbacks.push({ 'index': i, 'tid': $(".teacher-details-link a")[i].href.replace("https://www.51talk.com/TeacherNew/info/", "").replace('http://www.51talk.com/TeacherNew/info/', '') });
    }

    $.each(callbacks, function (index, item) {
        submit(function (next) {
            // ajax 请求一定要包含在一个函数中
            var start = (new Date()).getTime();
            $.ajax({
                url: window.location.protocol + '//www.51talk.com/TeacherNew/teacherComment?tid=' + item.tid + '&type=bad&has_msg=1',
                type: 'GET',
                dateType: 'html',
                //headers:{'Access-Control-Allow-Origin': window.location.protocol+'//www.51talk.com/TeacherNew/info/'+item.tid,'reference':window.location.protocol+'//www.51talk.com'},
                success: function (r) {
                    if ($(".evaluate-content-left span", r) && $(".evaluate-content-left span", r).length >= 3) {
                        var thumbup = Number($(".evaluate-content-left span", r)[1].innerText.match(num).clean("")[0]);
                        var thumbdown = Number($(".evaluate-content-left span", r)[2].innerText.match(num).clean("")[0]);
                        var thumbupRate = ((thumbup + 0.00001) / (thumbdown + thumbup)).toFixed(2) * 100;
                        $(".teacher-name")[index].innerText += "[" + thumbupRate + "%]";
                        $($(".item")[index]).attr('thumbup', thumbup)
                            .attr('thumbdown', thumbdown)
                            .attr('thumbupRate', thumbupRate)

                            .attr('age', $($('.teacher-age')[index]).text().match(num).clean(""));
                    } else {
                        console.log('Teacher s detail info getting error:' + JSON.stringify(item) + ",error info:" + r);
                    }
                },
                error: function (data) { console.log("xhr error when getting teacher " + JSON.stringify(item) + ",error msg:" + JSON.stringify(data)); }
            }).always(function () {
                while ((new Date()).getTime() - start < 800) {
                    continue;
                }
                next();
            });
        });
    });
    function updateUI() {
        var l1 = $("#tLabelCount").slider('values', 0);
        var l2 = $("#tLabelCount").slider('values', 1);

        var rate1 = $("#thumbupRate").slider('values', 0);
        var rate2 = $("#thumbupRate").slider('values', 1);

        var age1 = $("#tAge").slider('values', 0);
        var age2 = $("#tAge").slider('values', 1);

        $('#_tAge').html(age1 + " - " + age2);
        $('#_tLabelCount').html(l1+ " - " + l2);
        $('#_thumbupRate').html(rate1 + "% - " + rate2+'%');

        let tcount=0;
        $.each($('.item'), function (i, item) {
            var node =$(item);
            var l = parseFloat(node.attr('label'));
            var rate = parseFloat(node.attr('thumbupRate'))
            var age = parseFloat(node.attr('age'))

            if ((rate >= rate1 && rate <= rate2) && l >= l1 && l <= l2 && age >= age1 && age <= age2) {

                if(node.is(':hidden')){  //如果node是隐藏的则显示node元素,否则隐藏
                    node.css('color','red').show();
                }else{
                    //nothing todo
                    //node.hide();
                }
                tcount++;
            } else {
                node.css('color','').hide();
            }
        });
        $('#tcount').text(tcount);
    }
    value.sort(teacher_sort);

    submit(function (next) {
        try {
            var dialog = $("<div id='dialogs' title='Teacher Filter by Jimbo'>当前可选教师<span id='tcount'>28</span>位<br />有效经验 <span id='_tLabelCount' /><br /><div id='tLabelCount'></div>好评率 <span id='_thumbupRate'/><br /><div id='thumbupRate'></div>年龄 <span id='_tAge' /><br /><div id='tAge'></div></div>");

            dialog.appendTo('body');
            $("#tLabelCount").slider({
                range: true,
                min: value[value.length-1],
                max: value[0],
                values: [ value[value.length-1], value[0]],
                slide:function(event,ui){

                    $('#_tLabelCount').html(ui.values[0]+ " - " + ui.values[1]);
                },
            }).on('slidestop', function (event, ui) {

                updateUI();
            });
            $("#thumbupRate").slider({
                range: true,
                min: 0,
                max: 100,
                values: [0, 100],
                slide:function(event,ui){
                    $('#_thumbupRate').html(ui.values[0] + "% - " + ui.values[1]+'%');
                },
            }).on('slidestop', function (event, ui) {

                updateUI();
            });
            $("#tAge").slider({
                range: true,
                min: 0,
                max: 110,
                values: [0, 110],
                slide:function(event,ui){
                    $('#_tAge').html(ui.values[0] + " - " + ui.values[1]);
                },
            }).on( "slidestop",function (event, ui) {
                updateUI();
            });
            dialog.dialog({
                // bgiframe: true,
                resizable: true,
                //height:300,
                zIndex: 5000,
            });
        } catch (ex) {
        }
        updateUI();
        next();
    });

})();