Greasy Fork is available in English.

虎扑论坛评分计算

专区贴子的评分计算

// ==UserScript==
// @name         虎扑论坛评分计算
// @namespace    https://greasyfork.org/zh-CN/users/193133-pana
// @homepage     https://www.sailboatweb.com
// @version      1.2.0
// @description  专区贴子的评分计算
// @author       pana
// @include      http*://bbs.hupu.com/*
// @grant        none
// ==/UserScript==

(function() {
	'use strict';
	const TITLE_STR = $("head title").text();
	const VALUE_REG = /\(([0-9\.]+)%\)$/i;
	const HUPU_ARRAY = {
		NBA: [0.1, 0.09, 0.08, 0.07, 0.06, 0.05],
		QMS: [0.1, 0.09, 0.08, 0.07, 0.06, 0.05, 0.04, 0.03, 0.02, 0.01],
		YPR: [0.1, 0.09, 0.08, 0.07, 0.06, 0.04, 0.02, 0.01],
		HPMXB: [1, 0.8, 0.6, 0.4, 0.2],
		HPCP: [1, 0.8, 0.6, 0.4, 0.2, 0.01],
	};

	function after_Game_Score(score_array, fixed_num) {
		$("div#tpc table.case div.vote_box a.blue").each(function() {
			if ($(this).parent().find("u.avgText").length === 0) {
				let score_sum = 0;
				$(this).parents("div.vote_box").find("div.votebox_w a").each(function(j) {
					let value_text = VALUE_REG.exec($(this).text())[1];
					score_sum = score_sum + (Number(value_text) * score_array[j])
				});
				let avg_text = '<u class="avgText" style="margin-left: 20px;">平均分: ' + score_sum.toFixed(fixed_num) + '</u>';
				$(this).after(avg_text)
			}
		})
	}
	function video_Score(score_array, fixed_num) {
		$("div#tpc table.case div.vote_box a.blue").each(function() {
			if ($(this).parent().find("u.avgText").length === 0) {
				let score_sum = 0;
				let null_num = 0;
				let vote_box = $(this).parents("div.vote_box").find("div.votebox_w a");
				let vote_num = vote_box.length;
				let avg_text = '';
				if (score_array.length === vote_box.length) {
					for (let j = vote_num - 1; j >= 0; j--) {
						if (j === vote_num - 1) {
							null_num = Number(VALUE_REG.exec(vote_box.eq(j).text())[1]);
							null_num = null_num * score_array[j]
						} else {
							let value_text = VALUE_REG.exec(vote_box.eq(j).text())[1];
							score_sum = score_sum + (Number(value_text) / (1 - null_num) * score_array[j])
						}
					}
					avg_text = '<u class="avgText" style="margin-left: 20px;">平均分: ' + score_sum.toFixed(fixed_num) + '</u>'
				} else if (score_array.length - 1 === vote_box.length) {
					vote_box.each(function(j) {
						let value_text = VALUE_REG.exec($(this).text())[1];
						score_sum = score_sum + (Number(value_text) * score_array[j])
					});
					avg_text = '<u class="avgText" style="margin-left: 20px;">平均分: ' + score_sum.toFixed(fixed_num) + '</u>'
				} else {
					avg_text = '<u class="avgText" style="margin-left: 20px;">平均分: 计算出错</u>'
				}
				$(this).after(avg_text)
			}
		})
	}
	function calc_Score(score_array, fixed_num, callback) {
		callback(score_array, fixed_num);
		$("div#tpc table.case div.vote_box input[type='button']").on('click', function() {
			setTimeout(function() {
				callback(score_array, fixed_num)
			}, 1000)
		})
	}
	function init() {
		if (TITLE_STR.indexOf("赛后评分") !== -1) {
			calc_Score(HUPU_ARRAY.NBA, 3, after_Game_Score)
		} else if (TITLE_STR.indexOf("秋名山论美") !== -1) {
			calc_Score(HUPU_ARRAY.QMS, 3, after_Game_Score)
		} else if (TITLE_STR.indexOf("影评人") !== -1) {
			calc_Score(HUPU_ARRAY.YPR, 3, video_Score)
		} else if ((TITLE_STR.indexOf("虎扑明星榜") !== -1) || (TITLE_STR.indexOf("虎扑名将榜") !== -1)) {
			calc_Score(HUPU_ARRAY.HPMXB, 1, after_Game_Score)
		} else if (TITLE_STR.indexOf("虎扑车评") !== -1) {
			calc_Score(HUPU_ARRAY.HPCP, 1, video_Score)
		} else if (TITLE_STR.indexOf("鉴星榜") !== -1) {
			calc_Score(HUPU_ARRAY.QMS, 1, after_Game_Score)
		}
	}
	init()
})();