MyAnimeList(MAL) - Average Friends Score

Display next to the MAL score, the average score of your friends

当前为 2016-04-20 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         MyAnimeList(MAL) - Average Friends Score
// @version      1.0.0
// @description  Display next to the MAL score, the average score of your friends
// @author       Cpt_mathix
// @include      /^http:\/\/myanimelist\.net\/anime\/\d+\/.+/
// @include      /^http:\/\/myanimelist\.net\/manga\/\d+\/.+/
// @grant        none
// @namespace https://greasyfork.org/users/16080
// ==/UserScript==

(function($) {
    var url = document.location.href.match(/(^http:\/\/myanimelist\.net\/(anime|manga)\/\d+\/.+)/)[0];
    
    $.get(url + '/stats', function(data) {
    	var elements = $(data).find('table.table-recently-updated > tbody > tr:nth-child(n) > td:nth-child(2)').not('.borderClass.fw-b.ac');
    	
    	var sum = 0;
    	var count = 0;
    	$(elements).each( function() {
    		var score = $(this).text();
    		if(!isNaN(score)) {
    			sum += parseInt(score);
    			count += 1;
    		}
    	});
    	
    	var averageScore;
    	if (sum > 0) {
    		averageScore = (sum/count).toPrecision(3);
    	} else {
    		averageScore = '-';
    	}
    	
    	var scoreHolder = $('#content > table > tbody > tr > td.borderClass > div > .po-r.js-statistics-info.di-ib');
    	var newElement = document.createElement('div');
    	$(newElement).html('<span class="dark_text">Friend Score:</span> ' + averageScore);
    	$(newElement).addClass('spaceit');
    	$(newElement).attr('style', 'padding-top: 0px; padding-bottom: 0px; margin-bottom: 0px');
    	
    	$(newElement).insertAfter(scoreHolder[0]);
    	$(scoreHolder[1]).attr('style', 'padding-top: 0px; margin-top: 0px');
    });
})(jQuery);