'use strict'; function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } // ==UserScript== // @name 51talk选择最好最合适的老师-经验|好评率|年龄|收藏数 // @version 2019.12.31 // @namespace https://github.com/niubilityfrontend // @description 辅助选老师-排序显示,经验值计算|好评率|显示年龄|列表显示所有教师 // @author jimbo // @license OSL-3.0 // @supportURL https://github.com/niubilityfrontend/hunttingteacheron51talk // @match *://www.51talk.com/ReserveNew/index* // @match *://www.51talk.com/TeacherNew/* // @match *://www.51talk.com/user/* // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue // @grant GM_listValues // @grant GM_deleteValue // @grant GM_registerMenuCommand // @require http://code.jquery.com/jquery-3.4.1.min.js // @require https://code.jquery.com/ui/1.12.1/jquery-ui.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.5/i18n/grid.locale-cn.js // @require https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.15.5/jquery.jqgrid.min.js // @require https://greasyfork.org/scripts/388372-scrollfix/code/scrollfix.js?version=726657 // @require https://greasyfork.org/scripts/389774-gm-config-toolbar/code/gm_config_toolbar.js?version=730739 // @downloadURL none // ==/UserScript== (function () { 'use strict'; //重载类型方法 (function () { var _o; var getPaddedComp = function getPaddedComp(comp) { return parseInt(comp) < 10 ? '0' + comp : comp; }, o = (_o = { "[y|Y]{4}": function yY4(date) { return date.getFullYear(); }, // year "[y|Y]{2}": function yY2(date) { return date.getFullYear().toString().slice(2); }, // year "MM": function MM(date) { return getPaddedComp(date.getMonth() + 1); }, //month "M": function M(date) { return date.getMonth() + 1; }, //month "[d|D]{2}": function dD2(date) { return getPaddedComp(date.getDate()); }, //day "[d|D]{1}": function dD1(date) { return date.getDate(); }, //day "h{2}": function h2(date) { return getPaddedComp(date.getHours() > 12 ? date.getHours() % 12 : date.getHours()); }, //hour "h{1}": function h1(date) { return date.getHours() > 12 ? date.getHours() % 12 : date.getHours(); }, //hour "H{2}": function H2(date) { return getPaddedComp(date.getHours()); } }, _defineProperty(_o, 'h{1}', function h1(date) { return date.getHours(); }), _defineProperty(_o, "m{2}", function m2(date) { return getPaddedComp(date.getMinutes()); }), _defineProperty(_o, "m{1}", function m1(date) { return date.getMinutes(); }), _defineProperty(_o, "s+", function s(date) { return getPaddedComp(date.getSeconds()); }), _defineProperty(_o, "f+", function f(date) { return getPaddedComp(date.getMilliseconds()); }), _defineProperty(_o, "b+", function b(date) { return date.getHours() >= 12 ? 'PM' : 'AM'; }), _o); Date.prototype.toString = function (format) { var formattedDate = format; for (var k in o) { if (new RegExp("(" + k + ")").test(format)) { formattedDate = formattedDate.replace(RegExp.$1, o[k](this)); } } return formattedDate; }; //删除数组中的空元素 Array.prototype.clean = function () { var deleteValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; for (var i = 0; i < this.length; i++) { if (this[i] == deleteValue) { this.splice(i, 1); i--; } } return this; }; Number.prototype.toString = function () { return this.toFixed(2); }; String.prototype.toFloat = function () { return parseFloat(this); }; String.prototype.toInt = function () { return parseInt(this); }; String.prototype.startsWith = function (str) { return this.slice(0, str.length) == str; }; String.prototype.endsWith = function (str) { return this.slice(-str.length) == str; }; String.prototype.contains = function (str) { return this.indexOf(str) > -1; }; String.prototype.replaceAll = function (search, replacement) { var target = this; return target.replace(new RegExp(search, 'g'), replacement); }; })(); var config = GM_config([{ key: 'pagecount', label: '最大页数(自动获取时)', default: 20, type: 'dropdown', values: [0, 5, 10, 20, 50, 1000] }, { key: 'batchtimezoneMinutes', label: '预定耗费时间(分钟)', default: 60, type: 'dropdown', values: [5, 10, 20, 30, 50, 60, 90, 120, 300, 600, 1440, 10080] }, { key: 'version', type: 'hidden', default: 1 }]); var conf = config.load(); config.onsave = function (cfg) { conf = cfg; $('#autogetnextpage').text('自动获取' + getAutoNextPagesCount() + "页"); }; GM_registerMenuCommand('设置', config.setup); //*://www.51talk.com/ReserveNew/index* //https://www.51talk.com/TeacherNew/info/t26501111 //https://www.51talk.com/TeacherNew/teacherComment?tid=t26501111&type=all&has_msg=1 //https://www.51talk.com/TeacherNew/teacherComment?tid=t26501111&type=good&has_msg=1 //https://www.51talk.com/TeacherNew/teacherComment?tid=t26501111&type=bad&has_msg=1 //https://www.51talk.com/user/study_center_zx //https://www.51talk.com/user/study_center_zy //https://www.51talk.com/user/study_center_xx var url = window.location.href.toLocaleLowerCase(); var settings = { 'url': url, 'tid': url.match(/(t\d+)/g), 'pagecount': conf.pagecount, 'isDetailPage': url.contains("teachernew"), 'isListPage': url.contains('reservenew'), 'isCoursePage': url.contains('study_center') }; function gettid() { return settings.tid; } /** * 提交运算函数到 document 的 fx 队列 */ var submit = function submit(fun) { var queue = $.queue(document, "fx", fun); if (queue[0] == 'inprogress') { return; } $.dequeue(document); }; function getorAdd(key, func) { if (!(key in sessionStorage)) { var data = typeof func == 'function' ? func(key) : func; sessionStorage.setItem(key, data); return data; } return sessionStorage.getItem(key); } Pace.Options = { ajax: false, // disabled document: false, // disabled eventLag: false, // disabled elements: { selectors: ['#filterdialog'] } }; function sleep(delay) { var start = new Date().getTime(); while (new Date().getTime() - start < delay) { continue; } } var asc = function asc(a, b) { var av = $(a).attr('indicator'); var bv = $(b).attr('indicator'); if (!av || !bv) return 0; return $(a).attr('indicator').toFloat() > $(b).attr('indicator').toFloat() ? 1 : -1; }; var desc = function desc(a, b) { var av = $(a).attr('indicator'); var bv = $(b).attr('indicator'); if (!av || !bv) return 0; return $(a).attr('indicator').toFloat() > $(b).attr('indicator').toFloat() ? -1 : 1; }; var sortByIndicator = function sortByIndicator(sortBy) { var sortEle = $('.s-t-content.f-cb .item').sort(sortBy); $('.s-t-content.f-cb').empty().append(sortEle); }; function getBatchNumber() { var batchnumber = $("input[name='Date']").val() + $("input[name='selectTime']").val(); return getorAdd(batchnumber, function (key) { return new Date().getTime(); }); } function getLeftPageCount() { var pages = Number($('.s-t-page>.next-page:first').prev().text()); var curr = Number($('.s-t-page>.active:first').text()); if (pages) return pages - curr;else return 0; } function getAutoNextPagesCount() { var pages = getLeftPageCount(); if (settings.pagecount > pages) return pages;else return settings.pagecount; } $("head").append('\n\t\t'); $("head").append(''); var maxrate = 0, minrate = 99999, maxlabel = 0, minlabel = 9999999, maxfc = 0, minfc = 999999, maxage = 0, minage = 99999; var configExprMilliseconds = 3600000 * GM_getValue('tinfoexprhours', 168); //缓存7天小时 var num = /[0-9]*/g; function updateTeacherinfoToUI(jqel, tinfo) { if (tinfo.label > maxlabel) maxlabel = tinfo.label; if (tinfo.label < minlabel) minlabel = tinfo.label; if (tinfo.favoritesCount > maxfc) maxfc = tinfo.favoritesCount; if (tinfo.favoritesCount < minfc) minfc = tinfo.favoritesCount; if (tinfo.thumbupRate > maxrate) maxrate = tinfo.thumbupRate; if (tinfo.thumbupRate < minrate) minrate = tinfo.thumbupRate; if (tinfo.age > maxage) maxage = tinfo.age; if (tinfo.age < minage) minage = tinfo.age; jqel.attr("teacherinfo", JSON.stringify(tinfo)); jqel.find(".teacher-name").html(jqel.find(".teacher-name").text() + "
[" + tinfo.label + "|" + tinfo.thumbupRate + "%|" + tinfo.favoritesCount + "]"); jqel.find(".teacher-age").html(jqel.find(".teacher-age").text() + " | "); jqel //.attr('thumbup', tinfo.thumbup) //.attr('thumbdown', tinfo.thumbdown) //.attr('thumbupRate', tinfo.thumbupRate) //.attr('age', tinfo.age) //.attr('label', tinfo.label) .attr('indicator', tinfo.indicator); } function executeFilters(uifilters) { var tcount = 0, hidecount = 0; $.each($('.item'), function (i, item) { var node = $(item); var tinfojson = node.attr("teacherinfo"); if (!tinfojson) { return true; } var tinfo = JSON.parse(tinfojson); if (tinfo.thumbupRate >= uifilters.rate1 && tinfo.thumbupRate <= uifilters.rate2 && tinfo.label >= uifilters.l1 && tinfo.label <= uifilters.l2 && tinfo.age >= uifilters.age1 && tinfo.age <= uifilters.age2 && tinfo.favoritesCount >= uifilters.fc1 && tinfo.favoritesCount <= uifilters.fc2) { if (node.is(':hidden')) { //如果node是隐藏的则显示node元素,否则隐藏 node.show(); node.animate({ left: "+=50" }, 3500).animate({ left: "-=50" }, 3500); } else { //nothing todo } tcount++; } else { node.css('color', 'white').hide(); hidecount++; } }); $('#tcount').text(tcount); $('#thidecount').text(hidecount); } function getUiFilters() { var l1 = $("#tlabelslider").slider('values', 0); var l2 = $("#tlabelslider").slider('values', 1); var rate1 = $("#thumbupRateslider").slider('values', 0); var rate2 = $("#thumbupRateslider").slider('values', 1); var age1 = $("#tAgeSlider").slider('values', 0); var age2 = $("#tAgeSlider").slider('values', 1); var fc1 = $("#fcSlider").slider('values', 0); var fc2 = $("#fcSlider").slider('values', 1); return { l1: l1, l2: l2, rate1: rate1, rate2: rate2, age1: age1, age2: age2, fc1: fc1, fc2: fc2 }; } function getinfokey() { return 'tinfo-' + gettid(); }; if (settings.isListPage) { var getTeacherInfoInList = function getTeacherInfoInList(jqel) { var age = Number(jqel.find(".teacher-age").text().match(num).clean("")[0]); var label = function () { var j_len = jqel.find(".label").text().match(num).clean("").length; var l = 0; for (var j = 0; j < j_len; j++) { l += Number(jqel.find(".label").text().match(num).clean("")[j]); } l = Math.ceil(l / 5); return l; }(); var name = jqel.find(".teacher-name").text(); var type = $('.s-t-top-list .li-active').text(); var effectivetime = getBatchNumber(); if (type == '收藏外教') { var isfavorite = true; return { age: age, label: label, name: name, effectivetime: effectivetime, isfavorite: isfavorite }; } else return { age: age, label: label, name: name, effectivetime: effectivetime, type: type }; }; //获取列表中数据 $(".item-top-cont").prop('innerHTML', function (i, val) { return val.replaceAll('', ''); }); $(".s-t-days-list>li").click(function () { var batchnumber = $("input[name='Date']").val() + $("input[name='selectTime']").val(); sessionStorage.setItem(batchnumber, new Date().getTime()); }); $(".condition-type-time>li").click(function () { var batchnumber = $("input[name='Date']").val() + $("input[name='selectTime']").val(); sessionStorage.setItem(batchnumber, new Date().getTime()); }); $(".s-t-top-list>li>a").click(function () { var batchnumber = $("input[name='Date']").val() + $("input[name='selectTime']").val(); sessionStorage.setItem(batchnumber, new Date().getTime()); }); // 自动获取时,显示停止按钮 submit(function (next) { var autonextpage = GM_getValue('autonextpage', 1); if (autonextpage > 0 && $('.s-t-page>.next-page').length > 0) { var dialog = $('
\n\t\t\t

\n\t\t\t\u70B9\u51FB\u7ACB\u5373\u505C\u6B62\uFF0C \u5C06\u505C\u6B62\u83B7\u53D6\u540E\u7EED\u6559\u5E08\n\t\t\t

\n\t\t\t
'); dialog.appendTo('body'); dialog.dialog({ resizable: false, height: "auto", width: 400, modal: false, buttons: { "立即停止": function _() { sessionStorage.setItem('times', ''); GM_setValue('autonextpage', 0); $(this).dialog("close"); } // [`取后${(autonextpage*0.25).toFixed(0)}页`]: function() { // sessionStorage.setItem('times', ''); // GM_setValue('autonextpage', (autonextpage * 0.25).toFixed(0)); // $(this).dialog("close"); // }, // [`取后${(autonextpage*0.5).toFixed(0)}页`]: function() { // sessionStorage.setItem('times', ''); // GM_setValue('autonextpage', (autonextpage * 0.5).toFixed(0)); // $(this).dialog("close"); // }, // [`取后${(autonextpage*0.75).toFixed(0)}页`]: function() { // sessionStorage.setItem('times', ''); // GM_setValue('autonextpage', (autonextpage * 0.75).toFixed(0)); // $(this).dialog("close"); // } } }); } next(); }); $(".item").each(function (index, el) { submit(function (next) { Pace.track(function () { var jqel = $(el); var tid = jqel.find(".teacher-details-link a").attr('href').replace("https://www.51talk.com/TeacherNew/info/", "").replace('http://www.51talk.com/TeacherNew/info/', ''); var tinfokey = 'tinfo-' + tid; var teacherlistinfo = getTeacherInfoInList(jqel); var tinfo = GM_getValue(tinfokey); if (tinfo) { var now = new Date().getTime(); if (!tinfo.expire) { tinfo.expire = new Date(1970, 1, 1).getTime(); } tinfo = $.extend(tinfo, teacherlistinfo); GM_setValue(tinfokey, tinfo); if (now - tinfo.expire < configExprMilliseconds) { updateTeacherinfoToUI(jqel, tinfo); next(); return true; } } // ajax 请求一定要包含在一个函数中 var start = new Date().getTime(); $.ajax({ url: window.location.protocol + '//www.51talk.com/TeacherNew/teacherComment?tid=' + tid + '&type=bad&has_msg=1', type: 'GET', dateType: 'html', success: function success(r) { var jqr = $(r); if (jqr.find('.teacher-name-tit').length > 0) { var tempitem = jqr.find('.teacher-name-tit')[0]; tempitem.innerHTML = tempitem.innerHTML.replace('', ''); } if (jqr.find(".evaluate-content-left span").length >= 3) { var thumbup = Number(jqr.find(".evaluate-content-left span:eq(1)").text().match(num).clean("")[0]); var thumbdown = Number(jqr.find(".evaluate-content-left span:eq(2)").text().match(num).clean("")[0]); var thumbupRate = ((thumbup + 0.00001) / (thumbdown + thumbup)).toFixed(2) * 100; var favoritesCount = Number(jqr.find(".clear-search").text().match(num).clean("")[0]); var isfavorite = jqr.find(".go-search.cancel-collection").length > 0; var tage = Number(jqr.find(".teacher-name-tit > .age.age-line").text().match(num).clean("")[0]); var slevel = jqr.find('.sui-students').text(); jqr.remove(); var tinfo = { 'slevel': slevel, 'tage': tage, 'thumbup': thumbup, 'thumbdown': thumbdown, 'thumbupRate': thumbupRate, 'indicator': Math.ceil(teacherlistinfo.label * thumbupRate / 100) + favoritesCount, 'favoritesCount': favoritesCount, 'isfavorite': isfavorite, 'expire': new Date().getTime() }; tinfo = $.extend(tinfo, teacherlistinfo); GM_setValue(tinfokey, tinfo); updateTeacherinfoToUI(jqel, tinfo); } else { console.log('Teacher s detail info getting error:' + JSON.stringify(jqel) + ",error info:" + r); } }, error: function error(data) { console.log("xhr error when getting teacher " + JSON.stringify(jqel) + ",error msg:" + JSON.stringify(data)); } }).always(function () { while (new Date().getTime() - start < 600) { continue; } next(); }); }); }); }); submit(function (next) { //翻页 var autonextpage = GM_getValue('autonextpage', 0); if (autonextpage > 0) { GM_setValue('autonextpage', autonextpage - 1); if ($('.s-t-page>.next-page').length == 0) { GM_setValue('autonextpage', 0); if (isStopAndAutoGetNextTimeTeachers()) return; } else { $('.s-t-page .next-page')[0].click(); return false; } } else { if (isStopAndAutoGetNextTimeTeachers()) return; } next(); }); } function isStopAndAutoGetNextTimeTeachers() { var str = sessionStorage.getItem('times'); if (!str) return false; var times = JSON.parse(str); console.log(times); var cur = times.shift(); if (cur) { GM_setValue('autonextpage', 500); sessionStorage.setItem('times', JSON.stringify(times)); $('form[name="searchform"]>input[name="selectTime"]').val(cur); $('form[name="searchform"]>input[name="pageID"]').val(1); $('.go-search').click(); return true; } return false; } if (settings.isDetailPage) { var processTeacherDetailPage = function processTeacherDetailPage(jqr) { jqr.find('.teacher-name-tit').prop('innerHTML', function (i, val) { return val.replaceAll('', ''); }); var tinfo = GM_getValue(getinfokey(), {}); tinfo.label = function () { var l = 0; $.each(jqr.find(".t-d-label").text().match(num).clean(""), function (i, val) { l += Number(val); }); l = Math.ceil(l / 5); return l; }(); if (window.location.href.toLocaleLowerCase().contains("teachercomment")) { tinfo.thumbup = Number(jqr.find(".evaluate-content-left span:eq(1)").text().match(num).clean("")[0]); tinfo.thumbdown = Number(jqr.find(".evaluate-content-left span:eq(2)").text().match(num).clean("")[0]); tinfo.thumbupRate = ((tinfo.thumbup + 0.00001) / (tinfo.thumbdown + tinfo.thumbup)).toFixed(2) * 100; tinfo.indicator = Math.ceil(tinfo.label * tinfo.thumbupRate / 100) + tinfo.favoritesCount; tinfo.slevel = jqr.find('.sui-students').text(); tinfo.expire = new Date().getTime(); } tinfo.favoritesCount = Number(jqr.find(".clear-search").text().match(num).clean("")[0]); tinfo.isfavorite = jqr.find(".go-search.cancel-collection").length > 0; tinfo.age = Number(jqr.find(".age.age-line:eq(0)").text().match(num).clean("")[0]); tinfo.name = jqr.find(".t-name").text().trim(); //无法获取type //tinfo.type = $('.s-t-top-list .li-active').text().trim(); tinfo.tage = Number(jqr.find(".teacher-name-tit > .age.age-line:eq(1)").text().match(num).clean("")[0]); GM_setValue(getinfokey(), tinfo); jqr.find(".teacher-name-tit").prop('innerHTML', function (i, val) { return val + '\n\t\t\t\u6307\u6807' + tinfo.indicator + '\n\t\t\t\u7387' + tinfo.thumbupRate + '%\n\t\t\t\u8D5E' + tinfo.thumbup + '\n\t\t\t\u8E29' + tinfo.thumbdown + '\n\t\t\t\u6807\u7B7E\u6570' + tinfo.label + '\n\t\t\t'; }); }; submit(function (next) { processTeacherDetailPage($(document)); next(); }); } function addCheckbox(val, lbl, group) { var container = $('#timesmutipulecheck'); var inputs = container.find('input'); var id = inputs.length + 1; $('', { type: 'checkbox', id: 'cb' + id, value: val, name: group }).appendTo(container); $('