Beautification Tools for Luogu

Make the ugly UI become more beautiful!

  1. // ==UserScript==
  2. // @name Beautification Tools for Luogu
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.0
  5. // @description Make the ugly UI become more beautiful!
  6. // @author disangan233
  7. // @match https://*.luogu.com.cn/*
  8. // @grant none
  9. // @require https://code.jquery.com/jquery-1.12.4.min.js
  10. // ==/UserScript==
  11.  
  12. var photo = "url(http://imgs.aixifan.com/live/1483416293981/1483416293981.jpg)";
  13. var style = "no-repeat fixed center; background-size:cover;";
  14. var opa = "0.82";
  15.  
  16. $(window).load(function()
  17. {
  18. 'use strict';
  19.  
  20. var colors = ['rgb(191, 191, 191)', 'rgb(254, 76, 97)', 'rgb(243, 156, 17)', 'rgb(255, 193, 22)', 'rgb(82, 196, 26)', 'rgb(52, 152, 219)', 'rgb(157, 61, 207)', 'rgb(14, 29, 105)'];
  21. function updBGC(x, color, opa) {x.style.backgroundColor = color; x.style.opacity = opa;}
  22. function SetBGC(x, y, z = "1", l = x.length)
  23. {
  24. for(var i = 0; i < l; i++) updBGC(x[i], y, z);
  25. }
  26. function updC(x, color, opa) {x.style.color = color; x.style.opacity = opa;}
  27. function SetC(x, y, z = "1", l = x.length)
  28. {
  29. for(var i = 0; i < l; i++) updC(x[i], y, z);
  30. }
  31. function sort(x)
  32. {
  33. var i, str, l, arr = [], y = x.getElementsByClassName("problem-id");
  34. for(i = 0; i < y.length; i++)
  35. {
  36. arr.push(y[i]);
  37. str = arr[i].getElementsByClassName("color-default").item("innerText").innerText, l = str.length;
  38. if(str[0] == 'C')
  39. {
  40. if(l == 7 || l == 8 && (str[l-1] == '1' || str[l-1] == '2')) continue;
  41. else if(l == 6 || l == 7 && (str[l-1] == '1' || str[l-1] == '2')) {str = "CF0" + str.split("CF")[1];}
  42. else if(l == 5 || l == 6 && (str[l-1] == '1' || str[l-1] == '2')) {str = "CF00" + str.split("CF")[1];}
  43. else {str = "CF000" + str.split("CF")[1];}
  44. }
  45. if(str[0] == 'S')
  46. {
  47. if(l == 7) continue;
  48. else if(l == 6) {str = "SP0" + str.split("SP")[1];}
  49. else if(l == 5) {str = "SP00" + str.split("SP")[1];}
  50. else if (l == 4) { str = "SP000" + str.split("SP")[1]; }
  51. else {str = "SP0000" + str.split("SP")[1];}
  52. }
  53. if(str[0] == 'U')
  54. {
  55. if(l == 8) continue;
  56. else if(l == 7) {str = "UVA0" + str.split("UVA")[1];}
  57. else {str = "UVA00" + str.split("UVA")[1];}
  58. }
  59. arr[i].getElementsByClassName("color-default").item("innerText").innerText = str;
  60. }
  61. arr.sort(function(a,b){return a.innerText.localeCompare(b.innerText);});
  62. for(i = 0; i < arr.length; i++)
  63. {
  64. str = arr[i].getElementsByClassName("color-default").item("innerText").innerText, l = str.length;
  65. var res, j;
  66. if(str[0] == 'C')
  67. {
  68. res = "CF", j = 2; while(str[j] == '0') j++;
  69. for(; j < l; j++) res += str[j];
  70. str = res;
  71. }
  72. if(str[0] == 'S')
  73. {
  74. res = "SP", j = 2; while(str[j] == '0') j++;
  75. for(; j < l; j++) res += str[j];
  76. str = res;
  77. }
  78. if(str[0] == 'U')
  79. {
  80. res = "UVA", j = 3; while(str[j] == '0') j++;
  81. for(; j < l; j++) res += str[j];
  82. str = res;
  83. }
  84. arr[i].getElementsByClassName("color-default").item("innerText").innerText = str;
  85. }
  86. for(i = 0; i < arr.length; i++) x.appendChild(arr[i]);
  87. }
  88. document.body.style = "background:rgba(0, 0, 0, 0)" + photo + style;
  89. SetBGC(document.getElementsByClassName("lfe-body"), "rgba(0, 0, 0, 0)");
  90. SetBGC(document.getElementsByClassName("mdblog-article-container mdui-shadow-2 mdui-hoverable"), "#FFF", opa);
  91. updBGC(document.getElementsByClassName("lfe-body")[0], "#FFF", opa);
  92. SetC(document.getElementsByClassName("color-none"), "#3498DB", opa, 5);
  93. SetC(document.getElementsByClassName("popup-button"), "#3498DB", opa);
  94. document.getElementsByClassName("lfe-body")[3].style.opacity = opa;
  95. document.getElementsByClassName("wrapped lfe-body")[1].style.opacity = opa;
  96.  
  97. var posi = document.getElementsByClassName("problems");
  98. for(var i = 0; i < 2; i++) sort(posi[i]);
  99.  
  100. var problems = [];
  101. for(var passed of window._feInjection.currentData.passedProblems) problems.push({pid: passed.pid, dif: passed.difficulty, rendered: false});
  102. for(var tryed of window._feInjection.currentData.submittedProblems) problems.push({pid: tryed.pid, dif: tryed.difficulty, rendered: false});
  103.  
  104. setInterval(() =>
  105. {
  106. if(window.location.href.split("#").length == 2 && window.location.href.split("#")[1] == 'practice')
  107. {
  108. for(var i = 0; i < problems.length; i++) if(!problems[i].rendered)
  109. {
  110. var elements = document.querySelectorAll('a');
  111. for(var el of elements) if(el.textContent == problems[i].pid)
  112. {
  113. if (el.classList) el.classList.remove("color-default");
  114. else el.className = el.className.replace('color-default', ' ');
  115. problems[i].rendered = true;
  116. el.style.color = colors[problems[i].dif];
  117. break;
  118. }
  119. }
  120. }
  121. else for(var j = 0; j < problems.length; j++) problems[j].rendered = false;
  122. }, 1000);
  123.  
  124. });