AtCoderCharacterColorizer

Colorize kanji meaning color in statements

Verze ze dne 31. 07. 2021. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name AtCoderCharacterColorizer
  3. // @namespace https://satanic0258.github.io/
  4. // @version 0.1.2
  5. // @description Colorize kanji meaning color in statements
  6. // @author satanic0258
  7. // @match https://atcoder.jp/contests/*/tasks/*
  8. // @grant none
  9. // @copyright 2021, satanic0258 (https://satanic0258.github.io/)
  10. // @license MIT License; https://opensource.org/licenses/MIT
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14.  
  15. function background(c, r, g, b, a) {
  16. return "<span style='background-color:rgba("+r+","+g+","+b+","+a+");'>"+c+"</span>";
  17. }
  18. function white(c) {
  19. return "<span style='color:#fff;text-shadow:1px 0px 1px #000,0px 1px 1px #000,-1px 0px 1px #000,0px -1px 1px #000;'>"+c+"</span>";
  20. }
  21. function colorize(obj) {
  22. obj.innerHTML = obj.innerHTML
  23. .replace(/黒/g, background('黒', 0, 0, 0, 0.3))
  24. .replace(/ブラック/g, background('ブラック', 0, 0, 0, 0.3))
  25. .replace(/青([^木])/g, background('青', 0, 0, 255, 0.3) + '$1')
  26. .replace(/緑/g, background('緑', 0, 255, 0, 0.3))
  27. .replace(/水/g, background('水', 0, 255, 255, 0.3))
  28. .replace(/藍/g, background('藍', 15, 84, 116, 0.3))
  29. .replace(/灰/g, background('灰', 127, 127, 127, 0.3))
  30. .replace(/銀/g, background('銀', 127, 127, 127, 0.3))
  31. .replace(/紫/g, background('紫', 162, 96, 191, 0.4))
  32. .replace(/茶/g, background('茶', 184, 115, 51, 0.4))
  33. .replace(/銅/g, background('銅', 184, 115, 51, 0.4))
  34. .replace(/桃/g, background('桃', 240, 145, 153, 0.4))
  35. .replace(/ピンク/g, background('ピンク', 240, 145, 153, 0.4))
  36. .replace(/赤/g, background('赤', 255, 0, 0, 0.3))
  37. .replace(/橙/g, background('橙', 255, 127, 0, 0.3))
  38. .replace(/オレンジ/g, background('オレンジ', 255, 127, 0, 0.3))
  39. .replace(/黄/g, background('黄', 255, 255, 0, 0.5))
  40. .replace(/金/g, background('金', 255, 255, 0, 0.5))
  41. .replace(/白/g, white('白'))
  42. .replace(/ホワイト/g, white('ホワイト'));
  43. }
  44. function recColorize(obj) {
  45. // <section>直下の要素のみ色づけする
  46. if(obj.tagName === "SECTION") {
  47. for(const chi of obj.children) {
  48. // copy機能が壊れるため関連する部分は色付けしない
  49. if(chi.tagName === "H3" || chi.tagName === "PRE") continue;
  50. if(chi.tagName === "DIV" && chi.classList.includes("div-btn-copy")) continue;
  51. colorize(chi);
  52. }
  53. }
  54. else {
  55. for(const chi of obj.children) recColorize(chi);
  56. }
  57. }
  58. recColorize(document.getElementById("task-statement"));
  59. })();