AtcoderDevotionGraph

Overlay your devoiting graph on your rating graph

Versión del día 23/11/2020. Echa un vistazo a la versión más reciente.

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