AtcoderDevotionGraph

精進グラフを、通常のグラフの上に重ねて表示します

  1. // ==UserScript==
  2. // @name AtcoderDevotionGraph
  3. // @namespace http://atcoder.jp/
  4. // @version 1.0.2
  5. // @description 精進グラフを、通常のグラフの上に重ねて表示します
  6. // @author kemkemG0
  7. // @include *://atcoder.jp/users*
  8. // @exclude *://atcoder.jp/users/*?graph=rank
  9. // @exclude *://atcoder.jp/users/*?graph=dist
  10. // @exclude *://atcoder.jp/users/*/history*
  11. // @grant none
  12. // @require https://code.jquery.com/jquery-1.8.0.min.js
  13. //@run-at document-end
  14.  
  15. // ==/UserScript==
  16.  
  17. "use strict";
  18.  
  19. let scriptsArray = $('script');
  20. scriptsArray[14].remove(); // 対象のタグを消す記述 x[14]がグラフを読み込むjs
  21. //なんでこれ必要?? -->>一度読み込んだscriptタグはDOMから消しても効果は残るからそれを消すため
  22. let copyPage = $("html").clone().html();
  23. $("html").remove();
  24. document.write(copyPage);
  25.  
  26. //##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##
  27.  
  28.  
  29. {
  30. const element = document.getElementsByClassName('btn-text-group')[document.getElementsByClassName('btn-text-group').length - 1];
  31. const insertButton = Object.assign(document.createElement('button'), {
  32. className: '',
  33. id: 'shoujinButtonID',
  34. style: '\
  35. margin-left:100px;\
  36. appearance: none;\
  37. border: 0;\
  38. border-radius: 5px;\
  39. background: #20b2aa;\
  40. color: #fff;\
  41. padding: 5px 10px;\
  42. font-size: 16px;\
  43. '
  44. }
  45. );
  46. insertButton.textContent = "精進"
  47. element.appendChild(insertButton)
  48. }
  49.  
  50. // const
  51. const MARGIN_VAL_X = 86400 * 30;
  52. const MARGIN_VAL_Y_LOW = 100;//
  53. const MARGIN_VAL_Y_HIGH = 300;//自分の最高レート+表示する領域
  54. const OFFSET_X = 50;//グラフの位置?
  55. const OFFSET_Y = 5;
  56. const DEFAULT_WIDTH = 640;
  57. let canvas_status = document.getElementById("ratingStatus");
  58. // <canvas id="ratingStatus" width="1280" height="160"
  59. // style="max-width: 640px; max-height: 80px; height: 100%; width: 100%;"></canvas>
  60. const STATUS_WIDTH = canvas_status.width - OFFSET_X - 10;
  61. const STATUS_HEIGHT = canvas_status.height - OFFSET_Y - 5;
  62. let canvas_graph = document.getElementById("ratingGraph");
  63. /* <canvas id="ratingGraph"
  64. width="1280" height="720"
  65. style="max-width: 640px; max-height: 360px; height: 100%; width: 100%;"></canvas>*/
  66. const PANEL_WIDTH = canvas_graph.width - OFFSET_X - 10;
  67. const PANEL_HEIGHT = canvas_graph.height - OFFSET_Y - 30;
  68. //HIGHEST:932 とかの吹き出しのサイズ
  69. const HIGHEST_WIDTH = 80;
  70. const HIGHEST_HEIGHT = 20;
  71. const LABEL_FONT = "12px Lato";
  72. const START_YEAR = 2010;
  73. const MONTH_NAMES = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  74. const YEAR_SEC = 86400 * 365;
  75. const STEP_SIZE = 400;//グラフのy軸のステップ数
  76. const COLORS = [
  77. [0, "#808080", 0.15],
  78. [400, "#804000", 0.15],
  79. [800, "#008000", 0.15],
  80. [1200, "#00C0C0", 0.2],
  81. [1600, "#0000FF", 0.1],
  82. [2000, "#C0C000", 0.25],
  83. [2400, "#FF8000", 0.2],
  84. [2800, "#FF0000", 0.1]
  85. ];
  86.  
  87. //??????????????????
  88. const STAR_MIN = 3200;
  89. const PARTICLE_MIN = 3;
  90. const PARTICLE_MAX = 20;
  91. const LIFE_MAX = 30;
  92. const EPS = 1e-9;
  93.  
  94. let cj = createjs;
  95. let stage_graph, stage_status;
  96. // graph
  97. let panel_shape, border_shape;
  98. let chart_container, line_shape, vertex_shapes, highest_shape;
  99. let n, x_min, x_max, y_min, y_max;
  100.  
  101. //devoting graph
  102. let devoting_panel_shape, devoting_border_shape;
  103. let devoting_chart_container, devoting_line_shape, devoting_vertex_shapes, devoting_highest_shape;
  104. let devoting_n, devoting_x_min, devoting_x_max, devoting_y_min, devoting_y_max;
  105. let devoting_rating_history = []
  106.  
  107. // status
  108. let border_status_shape;
  109. let rating_text, place_text, diff_text, date_text, contest_name_text;
  110. let particles;
  111. let standings_url;
  112. const username = document.getElementsByClassName("username")[0].textContent;
  113. //クリエイトjsとやらをつかっている
  114. //いい感じにキャンバスの大きさを設定してマウスオーバーもONにする
  115. function initStage(stage, canvas) {
  116. let width = canvas.getAttribute('width');// <canvas width="">を取得
  117. let height = canvas.getAttribute('height');
  118.  
  119. //最悪、なくても画質悪くなったが動いた よくわからん
  120. if (window.devicePixelRatio) {//ピクセル比 によって解像度を変える 本来は2のときに1にしたらぼやけた
  121. //縦横の設定
  122. canvas.setAttribute('width', Math.round(width * window.devicePixelRatio));//Math.round()は四捨五入
  123. canvas.setAttribute('height', Math.round(height * window.devicePixelRatio));
  124. stage.scaleX = stage.scaleY = window.devicePixelRatio;
  125. }
  126. //最大のキャンパスサイズ=もとのキャンバスサイズにする
  127. canvas.style.maxWidth = width + "px";
  128. canvas.style.maxHeight = height + "px";
  129. canvas.style.width = canvas.style.height = "100%";
  130. stage.enableMouseOver();
  131. }
  132. //parent===stageに図形を追加し、その図形をreturnで参照渡し
  133. function newShape(parent) {
  134. let s = new cj.Shape();
  135. parent.addChild(s);
  136. return s;
  137. }
  138. //上のテキストバージョン
  139. function newText(parent, x, y, font) {
  140. let t = new cj.Text("", font, "#000");
  141. t.x = x;
  142. t.y = y;
  143. t.textAlign = "center";
  144. t.textBaseline = "middle";
  145. parent.addChild(t);
  146. return t;
  147. }
  148. //多分一番の大元
  149. function init() {
  150. //rating_history はHTML内で取得してある
  151. //rating_history=[{"EndTime":時間(単位不明),"NewRating":11,"OldRating":0,"Place":5200,"ContestName":"コンテスト名","StandingsUrl":"/contests/m-solutions2020/standings?watching=kemkemG0"}];
  152. n = rating_history.length;
  153. devoting_n = devoting_rating_history.length;
  154. if (n == 0 ) return;
  155.  
  156. //土台のステージ これに図形とかを追加していくイメージ
  157. stage_graph = new cj.Stage("ratingGraph");// Stage("canvasのID");
  158. stage_status = new cj.Stage("ratingStatus");
  159. initStage(stage_graph, canvas_graph);
  160. initStage(stage_status, canvas_status);
  161.  
  162. //グラフのサイズ決定
  163. x_min = 100000000000;
  164. x_max = 0;
  165. y_min = 10000;
  166. y_max = 0;
  167. for (let i = 0; i < n; i++) {
  168. x_min = Math.min(x_min, rating_history[i].EndTime);
  169. x_max = Math.max(x_max, rating_history[i].EndTime);
  170. y_min = Math.min(y_min, rating_history[i].NewRating);
  171. y_max = Math.max(y_max, rating_history[i].NewRating);
  172. }
  173. x_min -= MARGIN_VAL_X;//最初にコンテストに参加した日ー1ヶ月
  174. x_max += MARGIN_VAL_X;//最後にコンテストに参加した日+1ヶ月
  175. y_min = Math.min(1500, Math.max(0, y_min - MARGIN_VAL_Y_LOW));//いい感じに高さも設定
  176. y_max += MARGIN_VAL_Y_HIGH;
  177.  
  178. //精進グラフのサイズ決定
  179. devoting_x_min = 100000000000;
  180. devoting_x_max = 0;
  181. devoting_y_min = 10000;
  182. devoting_y_max = 0;
  183. for (let i = 0; i < devoting_rating_history.length; i++) {
  184. devoting_x_min = Math.min(devoting_x_min, devoting_rating_history[i].epoch_second);
  185. devoting_x_max = Math.max(devoting_x_max, devoting_rating_history[i].epoch_second);
  186. devoting_y_min = Math.min(devoting_y_min, devoting_rating_history[i].point);
  187. devoting_y_max = Math.max(devoting_y_max, devoting_rating_history[i].point);
  188. }
  189. devoting_x_min -= MARGIN_VAL_X;//最初にコンテストに参加した日ー1ヶ月
  190. devoting_x_max += MARGIN_VAL_X;//最後にコンテストに参加した日+1ヶ月
  191. devoting_y_min = Math.min(1500, Math.max(0, devoting_y_min - MARGIN_VAL_Y_LOW));//いい感じに高さも設定
  192. devoting_y_max += MARGIN_VAL_Y_HIGH;
  193.  
  194. //形を決める
  195. y_min = Math.min(y_min, devoting_y_min);
  196. y_max = Math.max(y_max, devoting_y_max);
  197. x_min = Math.min(x_min, devoting_x_min);
  198. x_max = Math.max(x_max, devoting_x_max);
  199.  
  200. initBackground();//背景の描画
  201. initChart();//プロットと直線の描画
  202. initDevotingChart()
  203. stage_graph.update();
  204.  
  205. initStatus();//グラフの上のコンテスト情報とかの描画
  206. stage_status.update();
  207. //マウスオーバー時のほわほわの管理
  208. cj.Ticker.setFPS(60);
  209. cj.Ticker.addEventListener("tick", handleTick);
  210. function handleTick(event) {
  211. updateParticles();
  212. stage_status.update();
  213. }
  214. }
  215.  
  216. function getPer(x, l, r) {
  217. return (x - l) / (r - l);
  218. }
  219. function getColor(x) {
  220. for (let i = COLORS.length - 1; i >= 0; i--) {
  221. if (x >= COLORS[i][0]) return COLORS[i];
  222. }
  223. return [-1, "#000000", 0.1];
  224. }
  225. function initBackground() {
  226.  
  227. panel_shape = newShape(stage_graph);//stage_graphに図形を追加、また panel_shapeはstage_graphの内部とつながってる(オブジェクトは参照渡し)
  228. panel_shape.x = OFFSET_X;
  229. panel_shape.y = OFFSET_Y;
  230. panel_shape.alpha = 0.3;
  231.  
  232. border_shape = newShape(stage_graph);
  233. border_shape.x = OFFSET_X;
  234. border_shape.y = OFFSET_Y;
  235.  
  236. //左の軸のレートの設定
  237. function newLabelY(s, y) {
  238. let t = new cj.Text(s, LABEL_FONT, "#000");
  239. t.x = OFFSET_X - 10;//理解
  240. t.y = OFFSET_Y + y;
  241. t.textAlign = "right";
  242. t.textBaseline = "middle";
  243. stage_graph.addChild(t);
  244. }
  245. //上と同様にX軸のラベルの設定
  246. function newLabelX(s, x, y) {
  247. let t = new cj.Text(s, LABEL_FONT, "#000");
  248. t.x = OFFSET_X + x;
  249. t.y = OFFSET_Y + PANEL_HEIGHT + 2 + y;
  250. t.textAlign = "center";
  251. t.textBaseline = "top";
  252. stage_graph.addChild(t);
  253. }
  254.  
  255. //https://createjs.com/docs/easeljs/classes/Graphics.html Graphics Classのドキュメント
  256. let y1 = 0;
  257. // グラフの中の正方形のパネルを色を設定
  258. for (let i = COLORS.length - 1; i >= 0; i--) {
  259. let y2 = PANEL_HEIGHT - PANEL_HEIGHT * getPer(COLORS[i][0], y_min, y_max);
  260. if (y2 > 0 && y1 < PANEL_HEIGHT) {
  261. y1 = Math.max(y1, 0); //rect ( x, y, w , h )
  262. panel_shape.graphics.beginFill(COLORS[i][1]).rect(0, y1, PANEL_WIDTH, Math.min(y2, PANEL_HEIGHT) - y1);
  263. }
  264. y1 = y2;
  265. }
  266. //Y軸ラベルの設定
  267. for (let i = 0; i <= y_max; i += STEP_SIZE) {
  268. if (i >= y_min) {
  269. let y = PANEL_HEIGHT - PANEL_HEIGHT * getPer(i, y_min, y_max);
  270. newLabelY(String(i), y);
  271. border_shape.graphics.beginStroke("#FFF").setStrokeStyle(0.5);
  272. if (i == 2000) border_shape.graphics.beginStroke("#000");
  273. border_shape.graphics.moveTo(0, y).lineTo(PANEL_WIDTH, y);
  274. }
  275. }
  276. border_shape.graphics.beginStroke("#FFF").setStrokeStyle(0.5);
  277.  
  278. let month_step = 6;
  279. for (let i = 3; i >= 1; i--) {
  280. if (x_max - x_min <= YEAR_SEC * i + MARGIN_VAL_X * 2) month_step = i;//初めてすぐの人は短めに
  281. }
  282.  
  283. //X軸ラベルの設定
  284. let first_flag = true;
  285. for (let i = START_YEAR; i < 3000; i++) {
  286. let break_flag = false;
  287. for (let j = 0; j < 12; j += month_step) {
  288. let month = ('00' + (j + 1)).slice(-2);
  289. let unix = Date.parse(String(i) + "-" + month + "-01T00:00:00") / 1000;
  290. if (x_min < unix && unix < x_max) {
  291. let x = PANEL_WIDTH * getPer(unix, x_min, x_max);
  292. if (j == 0 || first_flag) {
  293. newLabelX(MONTH_NAMES[j], x, 0);
  294. newLabelX(String(i), x, 13);
  295. first_flag = false;
  296. } else {
  297. newLabelX(MONTH_NAMES[j], x, 0);
  298. }
  299. border_shape.graphics.mt(x, 0).lt(x, PANEL_HEIGHT)
  300. }
  301. if (unix > x_max) { break_flag = true; break; }
  302. }
  303. if (break_flag) break;
  304. }
  305. border_shape.graphics.s("#888").ss(1.5).rr(0, 0, PANEL_WIDTH, PANEL_HEIGHT, 2);
  306. }
  307.  
  308. function initChart() {
  309. chart_container = new cj.Container();//コンテナでまとめると、同時に動かせたりして良い
  310. stage_graph.addChild(chart_container);
  311. chart_container.shadow = new cj.Shadow("rgba(0,0,0,0.3)", 1, 2, 3);//チャートの下に影
  312.  
  313. line_shape = newShape(chart_container);
  314. highest_shape = newShape(chart_container);
  315. vertex_shapes = new Array();
  316.  
  317. //マウスおいたら丸が大きくなるやつ
  318. function mouseoverVertex(e) {
  319. vertex_shapes[e.target.i].scaleX = vertex_shapes[e.target.i].scaleY = 1.2;
  320. stage_graph.update();
  321. setStatus(rating_history[e.target.i], true);
  322. };
  323. function mouseoutVertex(e) {
  324. vertex_shapes[e.target.i].scaleX = vertex_shapes[e.target.i].scaleY = 1;
  325. stage_graph.update();
  326. };
  327.  
  328. let highest_i = 0;
  329. for (let i = 0; i < n; i++) {
  330. if (rating_history[highest_i].NewRating < rating_history[i].NewRating) {
  331. highest_i = i;
  332. }
  333. }
  334. //historyの数だけ配列にpushしてイベントリスナーも設定
  335. for (let i = 0; i < n; i++) {
  336. vertex_shapes.push(newShape(chart_container));
  337. vertex_shapes[i].graphics.beginStroke("#FFF");
  338. if (i == highest_i) vertex_shapes[i].graphics.s("#000");//Highestなら外枠を黒に
  339. vertex_shapes[i].graphics.setStrokeStyle(0.5).beginFill(getColor(rating_history[i].NewRating)[1]).dc(0, 0, 3.5);
  340.  
  341. vertex_shapes[i].x = OFFSET_X + PANEL_WIDTH * getPer(rating_history[i].EndTime, x_min, x_max);
  342. vertex_shapes[i].y = OFFSET_Y + (PANEL_HEIGHT - PANEL_HEIGHT * getPer(rating_history[i].NewRating, y_min, y_max));
  343.  
  344. vertex_shapes[i].i = i;//なにこれ??
  345.  
  346. let hitArea = new cj.Shape();
  347. hitArea.graphics.f("#000").dc(1.5, 1.5, 6);
  348. vertex_shapes[i].hitArea = hitArea;
  349. vertex_shapes[i].addEventListener("mouseover", mouseoverVertex);
  350. vertex_shapes[i].addEventListener("mouseout", mouseoutVertex);
  351. }
  352.  
  353. {//highest 関連
  354. let dx = 80;
  355. if ((x_min + x_max) / 2 < rating_history[highest_i].EndTime) dx = -80;
  356. let x = vertex_shapes[highest_i].x + dx;
  357. let y = vertex_shapes[highest_i].y - 16;
  358. highest_shape.graphics.s("#FFF").mt(vertex_shapes[highest_i].x, vertex_shapes[highest_i].y).lt(x, y);
  359. highest_shape.graphics.s("#888").f("#FFF").rr(x - HIGHEST_WIDTH / 2, y - HIGHEST_HEIGHT / 2, HIGHEST_WIDTH, HIGHEST_HEIGHT, 2);
  360. highest_shape.i = highest_i;
  361. let highest_text = newText(stage_graph, x, y, "12px Lato");
  362. highest_text.text = "Highest: " + rating_history[highest_i].NewRating;
  363. highest_shape.addEventListener("mouseover", mouseoverVertex);
  364. highest_shape.addEventListener("mouseout", mouseoutVertex);
  365. }
  366.  
  367.  
  368. for (let j = 0; j < 2; j++) {
  369. if (j == 0) line_shape.graphics.s("#AAA").ss(2);
  370. else line_shape.graphics.s("#FFF").ss(0.5);//線の種類を変えてる? よくわからん
  371.  
  372. line_shape.graphics.mt(vertex_shapes[0].x, vertex_shapes[0].y);
  373. for (let i = 0; i < n; i++) {
  374. line_shape.graphics.lt(vertex_shapes[i].x, vertex_shapes[i].y);
  375. }
  376. }
  377. }
  378. function initDevotingChart() {
  379. devoting_chart_container = new cj.Container();//コンテナでまとめると、同時に動かせたりして良い
  380. stage_graph.addChild(devoting_chart_container);//これは devoting_じゃない
  381. devoting_chart_container.shadow = new cj.Shadow("rgba(0,0,0,0.3)", 1, 2, 3);//チャートの下に影
  382.  
  383. devoting_line_shape = newShape(devoting_chart_container);
  384. devoting_highest_shape = newShape(devoting_chart_container);
  385. devoting_vertex_shapes = new Array();
  386.  
  387. //historyの数だけ配列にpushしてイベントリスナーも設定
  388. for (let i = 0; i < devoting_n; i++) {
  389. devoting_vertex_shapes.push(newShape(devoting_chart_container));
  390. devoting_vertex_shapes[i].graphics.beginStroke("#FFF");
  391. if (i == devoting_n - 1) {
  392. devoting_vertex_shapes[i].graphics.s("#000");
  393. devoting_vertex_shapes[i].graphics.setStrokeStyle(1).beginFill(getColor(devoting_rating_history[i].point)[1]).dc(0, 0, 2.5);
  394. }
  395. else {
  396. devoting_vertex_shapes[i].graphics.setStrokeStyle(0.5).beginFill(getColor(devoting_rating_history[i].point)[1]).dc(0, 0, 2);
  397. }
  398. devoting_vertex_shapes[i].x = OFFSET_X + PANEL_WIDTH * getPer(devoting_rating_history[i].epoch_second, x_min, x_max);//devotingじゃないほうに合わせる?
  399. devoting_vertex_shapes[i].y = OFFSET_Y + (PANEL_HEIGHT - PANEL_HEIGHT * getPer(devoting_rating_history[i].point, y_min, y_max));
  400. devoting_vertex_shapes[i].i = i;
  401. let hitArea = new cj.Shape();
  402. hitArea.graphics.f("#000").dc(1.5, 1.5, 6);
  403. devoting_vertex_shapes[i].hitArea = hitArea;
  404. }
  405. //チャートの線関連
  406. for (let index = 0; index < 2; index++) {
  407. if (index == 0) devoting_line_shape.graphics.s("#AAA").ss(2);
  408. else devoting_line_shape.graphics.s("#FFF").ss(0.5);
  409. devoting_line_shape.graphics.mt(devoting_vertex_shapes[0].x, devoting_vertex_shapes[0].y);
  410. for (let i = 0; i < devoting_rating_history.length; i++) {
  411. devoting_line_shape.graphics.lt(devoting_vertex_shapes[i].x, devoting_vertex_shapes[i].y);
  412. }
  413. }
  414. }
  415. function initStatus() {
  416. border_status_shape = newShape(stage_status);
  417. rating_text = newText(stage_status, OFFSET_X + 75, OFFSET_Y + STATUS_HEIGHT / 2, "48px 'Squada One'");
  418. place_text = newText(stage_status, OFFSET_X + 160, OFFSET_Y + STATUS_HEIGHT / 2.7, "16px Lato");
  419. diff_text = newText(stage_status, OFFSET_X + 160, OFFSET_Y + STATUS_HEIGHT / 1.5, "11px Lato");
  420. diff_text.color = '#888';
  421. date_text = newText(stage_status, OFFSET_X + 200, OFFSET_Y + STATUS_HEIGHT / 4, "14px Lato");
  422. contest_name_text = newText(stage_status, OFFSET_X + 200, OFFSET_Y + STATUS_HEIGHT / 1.6, "20px Lato");
  423. date_text.textAlign = contest_name_text.textAlign = "left";
  424. contest_name_text.maxWidth = STATUS_WIDTH - 200 - 10;
  425. {
  426. let hitArea = new cj.Shape(); hitArea.graphics.f("#000").r(0, -12, contest_name_text.maxWidth, 24);
  427. contest_name_text.hitArea = hitArea;
  428. contest_name_text.cursor = "pointer";
  429. contest_name_text.addEventListener("click", function () {
  430. location.href = standings_url;
  431. });
  432. }
  433. particles = new Array();
  434. for (let i = 0; i < PARTICLE_MAX; i++) {
  435. particles.push(newText(stage_status, 0, 0, "64px Lato"));
  436. particles[i].visible = false;
  437. }
  438. setStatus(rating_history[rating_history.length - 1], false);
  439. }
  440.  
  441. function getRatingPer(x) {
  442. let pre = COLORS[COLORS.length - 1][0] + STEP_SIZE;
  443. for (let i = COLORS.length - 1; i >= 0; i--) {
  444. if (x >= COLORS[i][0]) return (x - COLORS[i][0]) / (pre - COLORS[i][0]);
  445. pre = COLORS[i][0];
  446. }
  447. return 0;
  448. }
  449. //@#//@#//@#//@#//@#//@#//@#// 関係ない //@#//@#//@#//@#//@#//@#//@#//@#//@#//@#
  450. function getOrdinal(x) {
  451. let s = ["th", "st", "nd", "rd"], v = x % 100;
  452. return x + (s[(v - 20) % 10] || s[v] || s[0]);
  453. }
  454. function getDiff(x) {
  455. let sign = x == 0 ? 'ツア' : (x < 0 ? '-' : '+');
  456. return sign + Math.abs(x);
  457. }
  458. function setStatus(data, particle_flag) {
  459. let date = new Date(data.EndTime * 1000);
  460. let rating = data.NewRating, old_rating = data.OldRating;
  461. let place = data.Place;
  462. let contest_name = data.ContestName;
  463. let tmp = getColor(rating); let color = tmp[1], alpha = tmp[2];
  464. border_status_shape.graphics.c().s(color).ss(1).rr(OFFSET_X, OFFSET_Y, STATUS_WIDTH, STATUS_HEIGHT, 2);
  465. rating_text.text = rating;
  466. rating_text.color = color;
  467. place_text.text = getOrdinal(place);
  468. diff_text.text = getDiff(rating - old_rating);
  469. date_text.text = date.toLocaleDateString();
  470. contest_name_text.text = contest_name;
  471. if (particle_flag) {
  472. let particle_num = parseInt(Math.pow(getRatingPer(rating), 2) * (PARTICLE_MAX - PARTICLE_MIN) + PARTICLE_MIN);
  473. setParticles(particle_num, color, alpha, rating);
  474. }
  475. standings_url = data.StandingsUrl;
  476. }
  477. //Particle は マウスオーバー時のくるくるのやつw
  478. function setParticle(particle, x, y, color, alpha, star_flag) {
  479. particle.x = x;
  480. particle.y = y;
  481. let ang = Math.random() * Math.PI * 2;
  482. let speed = Math.random() * 4 + 4;
  483. particle.vx = Math.cos(ang) * speed;
  484. particle.vy = Math.sin(ang) * speed;
  485. particle.rot_speed = Math.random() * 20 + 10;
  486. particle.life = LIFE_MAX;
  487. particle.visible = true;
  488. particle.color = color;
  489.  
  490. if (star_flag) {
  491. particle.text = "★";
  492. } else {
  493. particle.text = "@";
  494. }
  495. particle.alpha = alpha;
  496. }
  497. function setParticles(num, color, alpha, rating) {
  498. for (let i = 0; i < PARTICLE_MAX; i++) {
  499. if (i < num) {
  500. setParticle(particles[i], rating_text.x, rating_text.y, color, alpha, rating >= STAR_MIN);
  501. } else {
  502. particles[i].life = 0;
  503. particles[i].visible = false;
  504. }
  505. }
  506. }
  507. function updateParticle(particle) {
  508. if (particle.life <= 0) {
  509. particle.visible = false;
  510. return;
  511. }
  512. particle.x += particle.vx;
  513. particle.vx *= 0.9;
  514. particle.y += particle.vy;
  515. particle.vy *= 0.9;
  516. particle.life--;
  517. particle.scaleX = particle.scaleY = particle.life / LIFE_MAX;
  518. particle.rotation += particle.rot_speed;
  519. }
  520. function updateParticles() {
  521. for (let i = 0; i < PARTICLE_MAX; i++) {
  522. if (particles[i].life > 0) {
  523. updateParticle(particles[i]);
  524. }
  525. }
  526. }
  527. //@#//@#//@#//@#//@#//@#//@#// 関係ない //@#//@#//@#//@#//@#//@#//@#//@#//@#//@#
  528.  
  529. //##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##//##
  530.  
  531. async function main() {
  532. //get json
  533. let allJson;
  534. try {
  535. const res = await fetch("https://kenkoooo.com/atcoder/atcoder-api/results?user=" + username);
  536. allJson = await res.json()
  537. console.log(allJson.length)
  538. } catch (reaseon) { console.log('try失敗') }
  539. {
  540. let isExist = {};
  541. for (let i = 0; i < allJson.length; i++) {//なぜか負のポイントがあったから追加
  542. if (allJson[i].result === 'AC' && 0 <= allJson[i].point && allJson[i].point <= 3000 && isExist[allJson[i].problem_id] === undefined) {
  543. devoting_rating_history.push({ ...allJson[i] });
  544. isExist[allJson[i].problem_id] = 0;
  545. }
  546. }
  547. }
  548. function compare(a, b) { return a.epoch_second - b.epoch_second; }//比較関数
  549. devoting_rating_history.sort(compare);//時間順にソート
  550.  
  551. for (let i = 0; i < devoting_rating_history.length - 1; i++) {//合計の累積和的な
  552. devoting_rating_history[i + 1].point += devoting_rating_history[i].point;
  553. devoting_rating_history[i].point /= 100;
  554. }
  555. devoting_rating_history[devoting_rating_history.length - 1].point /= 100;
  556. //今までの累積和/100 が高さ
  557.  
  558. let shoujinButtonID = document.getElementById('shoujinButtonID');
  559. shoujinButtonID.addEventListener('click', function () {
  560. devoting_chart_container.visible = !devoting_chart_container.visible;
  561. stage_graph.update();
  562. });
  563.  
  564. init();
  565.  
  566. }
  567.  
  568. main();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址