-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmyscript.js
57 lines (50 loc) · 1.85 KB
/
myscript.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
function patch(){
var honestify = function(score) {
var honest;
if (score >= 4.0) {
honest = 5.0;
} else if (score >= 3.5) {
honest = 4.5;
} else if (score >= 3.4) {
honest = 4.0;
} else if (score >= 3.3) {
honest = 3.5;
} else if (score >= 3.1) {
honest = 3.0;
} else if (score >= 3.0) {
honest = 2.0;
} else {
honest = 1.0;
}
console.log("Original score: " + score.toFixed(2) + ", Honest score: " + honest);
return honest;
};
$(".rdheader-data").each(function() {
var parent = this;
$('[rel="v:rating"] span', parent).each(function(index, element) {
var score = parseFloat($(element).text());
if (isNaN(score)) return;
var honest = honestify(score);
$(element).html(honest.toFixed(1) + ' <span class="tabelog-score">(' + score.toFixed(2) + ")</span>");
var rate = $(".tb-rating", parent)[0];
rate.className = rate.className.replace(/tb-rating--val\d\d/, "tb-rating--val" + honest * 10);
});
});
$(".list-rst").each(function() {
var parent = this;
$(".tb-rating__val", parent).each(function(index, element) {
var score = parseFloat($(element).text());
if (isNaN(score)) return;
var honest = honestify(score);
$(element).html(honest.toFixed(1) + ' <span class="tabelog-score">(' + score.toFixed(2) + ")</span>");
var rate = $(".tb-rating", parent)[0];
rate.className = rate.className.replace(/tb-rating--val\d\d/, "tb-rating--val" + honest * 10);
});
});
}
var style = document.createElement('style');
style.appendChild(document.createTextNode('.tabelog-score { font-weight: normal; font-size: 60%; color: #bbb }'));
document.body.appendChild(style);
var script = document.createElement('script');
script.appendChild(document.createTextNode('('+patch+')();'));
document.body.appendChild(script);