// ==UserScript==
// @name 51Talk.教师评分|课程数|好评率|Top 5
// @version 0.0.13
// @namespace tsharp.js.51talk_sort
// @description 51Talk教师评分:评价量、好评比。 此脚本会在老师的名字后添加2个参数:1、教师标签评价量。2、教师的好评比率(0-100%)。 正在开发中功能:增加过滤功能,高亮显示Top 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++) {
console.log("count:"+i_len);
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]=(value[i] /5).toFixed(0);
$(".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){
console.log(index);
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(){
$.each($('.item'),function(i,item){
var l=parseFloat($(item).attr('label'));
var rate=parseFloat($(item).attr('thumbupRate'))
var age=parseFloat($(item).attr('age'))
console.log(l+":"+rate+":"+age);
if( parseFloat($(item).attr('label')) > $("#tLabelCount" ).slider('values',0) && parseFloat($(item).attr('label'))< $("#tLabelCount" ).slider('values',1)){
$(item).hide();
}
});
}
value.sort(teacher_sort);
console.log(value);
submit(function(next){
try{
var dialog=$("<div id='dialogs' title='Teacher Filter by Jimbo'>标签数量 <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>");
$('.s-t-list').before(dialog);
$("#tLabelCount" ).slider({
range: true,
min: 0,
max: value[0]+1,
values: [ value.length>5 ? value[value.length-5]:0, value[0]],
slide: function( event, ui ) {
$('#_tLabelCount').html (ui.values[0] + " - " +ui.values[1]);
updateUI();
}
});
$("#thumbupRate" ).slider({
range: true,
min: 0,
max: 100,
values: [ 90, 100 ],
slide: function( event, ui ) {
$('#_thumbupRate').html (ui.values[0] + " - " +ui.values[1]);
//$( "#amount" ).val( ui.value );
}
});
$("#tAge" ).slider({
range: true,
min: 0,
max: 110,
values: [ 18, 50 ],
slide: function( event, ui ) {
$('#_tAge').html (ui.values[0] + " - " +ui.values[1]);
//$( "#amount" ).val( ui.value );
}
});
dialog.dialog({
// bgiframe: true,
resizable: true,
//height:300,
zIndex: 5000,
});
}catch (ex){
}
next();
});
})();