-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpixiv-ranking-scatter-plot.js
80 lines (78 loc) · 2.78 KB
/
pixiv-ranking-scatter-plot.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
80
// ==UserScript==
// @name Pixiv ranking scatter plot
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Show a scatter plot of date versus rank
// @author cro
// @match https://www.pixiv.net/dashboard/report/ranking*
// @icon https://www.google.com/s2/favicons?sz=64&domain=pixiv.net
// @grant none
// @license MIT
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/chartjs-adapter-date-fns.bundle.min.js
// ==/UserScript==
/* jshint esversion: 6 */
(function() {
'use strict';
let zipwith = (a, b, f) => a.map((k, i) => f(k, b[i]));
let jpcn_regex = /(\d+)\D(\d+)\D(\d+)\D/;
let rank_regex = /\d+/;
let date_parse = function(str)
{
let match = str.match(jpcn_regex);
if (match)
{
str = `${match[1]} ${match[2]} ${match[3]}`;
}
return new Date(str);
};
let menubar = document.querySelector('section.analytics-menu-unit');
let div = document.createElement('div');
let canvas = document.createElement('canvas');
canvas.style.backgroundColor = 'white';
div.appendChild(canvas);
menubar.insertAdjacentElement('beforeBegin', div);
let dates = Array.from(document.querySelectorAll('h1.date')).map(x => date_parse(x.textContent));
let top_rank = function(n)
{
let crown = document.querySelector(`.crown${n}`);
return crown ? Array.from(crown.nextSibling.querySelectorAll('h1.date')).map(x => n) : [];
}
let top_ranks = [1,2,3].map(top_rank).flat();
let ranks = top_ranks.concat(Array.from(document.querySelectorAll('h1.rank')).map(x => parseInt(x.textContent.match(rank_regex))));
let data = {
datasets: [{
label: 'Date vs Rank',
data: zipwith(dates, ranks, (date, rank) => ({ x: date, y: rank })),
backgroundColor: 'black'
}]
};
let config = {
type: 'scatter',
data: data,
options: {
animation: false,
scales: {
x: {
type: 'time',
display: true,
title: {
display: true,
text: 'Date'
}
},
y: {
display: true,
title: {
display: true,
text: 'Rank'
},
reverse: true,
min: 0,
suggestedMax: 100,
}
}
}
};
let chart = new Chart(canvas, config);
})();