-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpful_flag_percentage.user.js
79 lines (68 loc) · 3.04 KB
/
helpful_flag_percentage.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// ==UserScript==
// @name Stack Exchange Helpful Flag Percentage
// @namespace http://floern.com/
// @version 1.1
// @description Helpful flag percentage for the flag summary page
// @author enki / Floern
// @match *://*.stackexchange.com/users/flag-summary/*
// @match *://*.stackoverflow.com/users/flag-summary/*
// @match *://*.superuser.com/users/flag-summary/*
// @match *://*.serverfault.com/users/flag-summary/*
// @match *://*.askubuntu.com/users/flag-summary/*
// @match *://*.stackapps.com/users/flag-summary/*
// @match *://*.mathoverflow.net/users/flag-summary/*
// @updateURL https://raw.githubusercontent.com/Floern/stackoverflow/master/userscripts/helpful_flag_percentage.meta.js
// @downloadURL https://raw.githubusercontent.com/Floern/stackoverflow/master/userscripts/helpful_flag_percentage.user.js
// ==/UserScript==
$(function () {
'use strict';
var helpfulFlags = 0;
$("li div:contains('helpful')").next().each(function () {
helpfulFlags += parseInt($(this).text().replace(",",""));
});
var declinedFlags = 0;
$("li div:contains('declined')").next().each(function () {
declinedFlags += parseInt($(this).text().replace(",",""));
});
if (helpfulFlags > 0) {
var percentHelpful = (helpfulFlags / (helpfulFlags + declinedFlags)) * 100;
var decimals = percentHelpful >= 99.9 ? 3 : (percentHelpful >= 90 ? 2 : 1);
percentHelpful = Number(Math.round(percentHelpful + 'e' + decimals) + 'e-' + decimals);
if (percentHelpful > 100) {
percentHelpful = 100;
}
var percentColor;
if (percentHelpful >= 90) {
percentColor = "limegreen";
} else if (percentHelpful >= 80) {
percentColor = "darkorange";
} else {
percentColor = "red";
}
var css = "<style>\
#progress {\
background: #ccc;\
height: 10px;\
width: auto;\
margin: 6px 0;\
padding: 0px;\
}\
#progress:after {\
content: '';\
display: block;\
background: " + percentColor + ";\
width: " + percentHelpful + "%;\
height: 100%;\
}\
#percentHelpful {\
margin-bottom: 5px;\
}\
</style>";
$('head').append(css);
$("#flag-summary-filter").after("<div id='percentHelpfulFrame' class='s-sidebarwidget--header'></div>");
$("#percentHelpfulFrame").append("<h3 id='percentHelpful' title='pending, aged away and disputed" +
" flags are not counted'><span id='percent'>" + percentHelpful + "%</span> helpful</h3>");
$("span#percent").css("color", percentColor);
$("#percentHelpfulFrame").append("<div id='progress'></div>");
}
});