Ex124OJ

Extend 124OJ!

当前为 2022-12-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Ex124OJ
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.7.5
  5. // @description Extend 124OJ!
  6. // @author Sukwants
  7. // @license MIT
  8. // @match http://124.221.194.184
  9. // @match http://124.221.194.184/*
  10. // @icon https://www.imageoss.com/images/2022/11/29/ex124OJba563861978a769d.png
  11. // @grant GM_addStyle
  12. // @grant GM_xmlhttpRequest
  13. // @connect ex124oj.netlify.app
  14. // ==/UserScript==
  15.  
  16.  
  17. /* ==User Settings== */
  18.  
  19. // Special Period
  20. const WhenMourn = false;
  21. // Change Page Background. (Image URL, Opacity)
  22. const BackgroundSettings = [];
  23. // Change Site Icon. (Image URL)
  24. const SiteIconImage = 'https://www.imageoss.com/images/2022/11/29/ex124OJba563861978a769d.png';
  25. // Change username color.
  26. const NameColorList = {'Sukwants':['#8e44ad'],'Star32':['#e74c3c'],'2745518585':['#996600'],'syysongyuyang':['#ffc116'],'zsq147258369':['#52c41a'],'zhouchuan':['#e74c3c','#000000']};
  27. // Add CCF level badge.
  28. const CCFBadgeList = {'zsq147258369':'#52c41a','syysongyuyang':'#ffc116'};
  29. // Add name tag badge.
  30. const TagBadgeList = {'Sukwants':['#8e44ad','旅客'],'Star32':['#e74c3c','陌生人'],'2745518585':['#996600','作弊者'],'syysongyuyang':['#ffc116','原批'],'zsq147258369':['#52c41a','boring'],'zhouchuan':['#e74c3c','Feyn']};
  31.  
  32.  
  33. const HomepageRegExp = /^http:\/\/124.221.194.184(\/){0,1}(\?.*){0,1}$/;
  34. function isHomepage() {
  35. return HomepageRegExp.test(window.location.href);
  36. }
  37. const submissionRegExp = /^http:\/\/124.221.194.184\/submission\/\d{1,}/;
  38. function isSubmission() {
  39. return submissionRegExp.test(window.location.href);
  40. }
  41. const ProblemRegExp = /^http:\/\/124.221.194.184.*\/problem\/(\d{1,})(\?.*){0,1}$/;
  42. function isProblem() {
  43. return ProblemRegExp.test(window.location.href);
  44. }
  45. const UserProfileRegExp = /^http:\/\/124.221.194.184\/user\/profile\/.{1,}/;
  46. function isUserProfile() {
  47. return UserProfileRegExp.test(window.location.href);
  48. }
  49. const BlogRegExp = /^http:\/\/124.221.194.184\/blog\/.{1,}/;
  50. function isBlog() {
  51. return BlogRegExp.test(window.location.href);
  52. }
  53.  
  54. function whenMourn() {
  55. if (WhenMourn && isHomepage()) {
  56. GM_addStyle('\
  57. html {\
  58. -webkit-filter: grayscale(100%);\
  59. -moz-filter: grayscale(100%);\
  60. -ms-filter: grayscale(100%);\
  61. -o-filter: grayscale(100%);\
  62. filter: grayscale(100%);\
  63. filter: gray;\
  64. }');
  65. }
  66. }
  67.  
  68. const TrollingArticle = ['巨大的灰色乌云笼罩在灰色的、各式各样的建筑之上,炫目的LED灯管被竖直放置于C市的各个角落。深灰的马路上粉刷着浅灰的虚线和实线,引导着川流不息、来来往往的车辆与人群。\n\
  69. C市的一天,便这样开始了。',
  70. '2050年,地球环境进一步恶化,人类生存资源濒临枯竭,即使科技再高速发展也无济于事。但此时,人类的基因已经完全破译,每个区段每一对碱基对控制着什么形状早已能够被识别、控制与修改。为了维护社会秩序,掌管C市的P党在该技术萌芽时便花重金将专利从相关公司手中买下,垄断了这一技术。所以,这达成了P党内部核心人员一个心照不宣的秘密。',
  71. '15年前。巨大的双链DNA模型在房间内投影出来,右旋的优美轮廓让在场的所有科学家都赞叹不已。喧哗声中,一个人走上演讲台,调试好麦克风,开始了它的发言。\n\
  72. “大家好。正如大家所知,人的眼睛是根据所看见光的波长来识别颜色的,而可见光谱中的大部分颜色可以由三种基本色光红、绿、蓝按不同比例混合而成,形成了连续的可视光谱。人类肉眼能区分其中的几百万至一千万种。经过十余年的研究,我们发现人类基因中关于色彩识别的区段较为冗长;为降低生活成本,我代表P党在此宣布自今年1100:00起将C市所有居民基因中的色彩识别区段删除,仅保留黑白两种基本色光。同时,相关政策也将陆续实施,感谢各位的理解与支持。”\n\
  73. ……',
  74. '20341231日,23:58。此时,C市的广大人民群众还不知道他们即将面临什么,有的已早早入睡,有的还在五彩斑斓的繁华都市中享受着绚烂多彩的生活。市中心高楼上的始终嘀嗒,分针逐渐指向了12的正下方。\n\
  75. 00:00\n\
  76. 所有还醒着的人们的记忆模块被完全刷新。\n\
  77. “这是一个非黑即白的世界。”\n\
  78. “灰色由不同比例的黑白色组成,是最常见的一种颜色。”\n\
  79. “自古以来便是这样。”\n\
  80. 所以,这场历史性的革命在悄无声息中圆满完成了。没有骚动,没有恐慌。',
  81. '与此同时,电子课本、电子词典被同步刷新。颜料标签被迅速替换。文字与影像资料被大幅度删改,相关学科被取消。红、黄、绿灯依次换为圆形、方形、三角形灯。颜色引导标识改为黑白点线面组合引导标识。\n\
  82. ……\n\
  83. 一切的一切,归零。\n\
  84. 生活照常。',
  85. '2030年,C市成为E国少数几个未通过《全可视区段色彩使用法案》的国家。P党声称此法案与C市传统颜色阶级制度价值观不符,不利于人口增长,可能引发社会混乱。此前,C市已出现多次因争取全区段可视色彩使用权而导致舆论风波的现象,重重封锁也无济于事。同时,其声称外部势力也在对C市青少年以各种潜移默化的方式渗透色彩多元化共存理论,造成了巨大影响。为了彻底解决这一问题,P党最后做出了取消色彩可视化这一决定,才有了这场看似荒谬的颜色革命。',
  86. '雨后,晴空。天边罕见地出现了一道彩虹,只是再也无法被C市的孩子们看见了。但他们还从课本上了解过这一自然景观,它被称为“灰虹”,天空中呈现了七种不同深浅的黑白色条带,蔚为壮观。\n\
  87. 小朋友们发出天真无邪的笑声,在浅灰的草坪上和父母一起欣赏美丽的灰虹。\n\
  88. 风也轻轻。\n\
  89. ……',
  90. '但那无法被看见色彩的彩虹,它还存在着啊。幸好,C市的科学还没有发展到能将彩虹粉刷为黑白的地步,幸好,它改变的只是我们人类本身。不论你是否承认彩虹的赤橙黄绿青蓝紫,它都存在着,从古至今。只是对C市的人来说,看不见了罢。\n\
  91. 带着无色的双眼去看待这个世界,世界当然是没有颜色的啊。',
  92. '或许会问,为什么那些所谓的“外部势力”没有到C市来宣传呢?\n\
  93. 因为C市早已故步自封了呢。C市早已在城郊筑好了高墙,外部势力很难进入,内部民众也难以出去。大家的梯子都被没收了,那可是违法的啊。\n\
  94. 从前,颜色是有阶级限制的,P党内部核心人员身穿黄色,大官穿紫色,小吏穿青绿色,平民穿灰白色。倘若僭越,是要遭来杀身之祸的。现在可好,民主、自由、平等,大家都一样,没人管你穿什么颜色,只是深深浅浅罢了。果然,社会进步,百姓安康。',
  95. '深夜,高楼。P党那位发表演讲的科学家站在窗边,望着依旧五光十色的建筑,冷笑一声,又走进无边的黑暗。\n\
  96. ……\n\
  97. “又经过几年的研究,我们发现人类基因中关于色彩识别的区段没有其存在的必要性。为进一步降低生活生产成本,我代表P党在此宣布自今年1100:00起将C市所有居民基因中色彩识别区段全部删除。同时,相关政策也将陆续实施。”“感谢各位的理解与支持。”',
  98. '00:00\n\
  99. C市的人全都瞎了。\n\
  100. 没有骚动,没有恐慌。'];
  101. function trollForAmusement() {
  102. console.log(TrollingArticle[Math.floor(Math.random() * TrollingArticle.length)]);
  103. }
  104.  
  105. function getBackground() {
  106. if (BackgroundSettings[0]) return BackgroundSettings[0];
  107. else return '';
  108. }
  109. function getOpacity() {
  110. if (BackgroundSettings[1]) return BackgroundSettings[1];
  111. else return '0.85';
  112. }
  113. function BackgroundImage() {
  114. if (BackgroundSettings[0]) {
  115. document.getElementsByClassName('navbar-brand')[0].innerHTML = '<img src="http://124.221.194.184/images/logo_small.png" alt="Logo" class="img-rounded" style="width:39px; height:39px;">';
  116. document.getElementsByClassName('container')[0].children[0].children[1].innerHTML = document.getElementsByClassName('container')[0].children[0].children[1].innerHTML.match(/(.*> ){0,1}(.*)/)[2];
  117. GM_addStyle('\
  118. body {\
  119. background: url("' + getBackground() + '");\
  120. background-repeat: no-repeat;\
  121. background-attachment: fixed;\
  122. background-position: 50% 50%;\
  123. background-size: cover;\
  124. }\
  125. .uoj-content {\
  126. background-color: #fff;\
  127. margin: 16px -16px;\
  128. padding: 16px 16px;\
  129. opacity: ' + getOpacity() + ';\
  130. border-radius: 8px;\
  131. }\
  132. .navbar {\
  133. margin: 16px -16px;\
  134. padding: 8px 16px;\
  135. opacity: ' + getOpacity() + ';\
  136. border-radius: 8px;\
  137. }');
  138. }
  139. }
  140.  
  141. function getIcon() {
  142. if (SiteIconImage) return SiteIconImage;
  143. else return '/images/logo.png';
  144. }
  145. const LogoURLExp = /^.*\/images\/logo(_small){0,1}.png$/;
  146. function changeIcon() {
  147. var Links = document.getElementsByTagName('link');
  148. for (var link in Links) {
  149. if (Links[link] && Links[link].nodeType && Links[link].getAttribute('rel') == 'shortcut icon') {
  150. Links[link].setAttribute('href', getIcon());
  151. }
  152. }
  153. var Icons = document.getElementsByTagName('img');
  154. for (var icon in Icons) {
  155. if (Icons[icon] && Icons[icon].nodeType && LogoURLExp.test(Icons[icon].getAttribute('src'))) {
  156. Icons[icon].setAttribute('src', getIcon());
  157. if (!Icons[icon].getAttribute('style')) Icons[icon].setAttribute('style', 'width:100%;height:auto;object-fit:cover');
  158. }
  159. }
  160. }
  161.  
  162. function HomepageEntrance() {
  163. var ent = document.createElement('li');
  164. ent.setAttribute('class', 'nav-item');
  165. ent.innerHTML = '<a href="https://ex124oj.netlify.app" style="padding: 0.5rem 1rem"><span style="background-color: #28adca;padding:0.2em 0.6em;border-radius: 1em;color:#fff;font-size: 0.7em;font-weight:bold;display:inline-block;position: relative;top: 50%;transform: translate(0,-50%);">Ex124OJ</span></a>';
  166. document.getElementsByClassName('container')[0].children[0].children[0].children[0].before(ent);
  167. }
  168.  
  169. const HtmlBodyInnerExp = /^[\s\S]*<div id="archives">([\s\S]*)<\/div>\s*?<footer id="footer">[\s\S]*$/;
  170. const WrittenByExp = /^by (.*)$/;
  171. const DateTimeExp = /^(.*?) .*$/;
  172. function exAnnouncements() {
  173. GM_xmlhttpRequest({
  174. method: "GET",
  175. url: "https://ex124oj.netlify.app/archives/",
  176. onload: function(data) {
  177. var Announcements = document.getElementsByClassName('uoj-content')[0].children[0].children[0].children[0].children[0].children[0];
  178. Announcements.children[0].children[0].innerHTML = '<th style="width:30%">公告</th><th style="width:10%"></th><th style="width:10%"></th><th style="width:30%">Ex 公告</th><th style="width:10%"></th><th style="width:10%"></th>';
  179. var trs = Announcements.children[1].getElementsByTagName('tr');
  180. for (var tr = 0; tr < trs.length - 1; ++tr) {
  181. if (trs[tr].innerHTML) {
  182. trs[tr].innerHTML = (trs[tr].children.length > 2 ? trs[tr].innerHTML : '<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>') + '<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>';
  183. if (WrittenByExp.test(trs[tr].children[1] && trs[tr].children[1].innerHTML)) {
  184. trs[tr].children[1].innerHTML = trs[tr].children[1].innerHTML.match(WrittenByExp)[1];
  185. }
  186. if (DateTimeExp.test(trs[tr].children[2] && trs[tr].children[2].innerHTML)) {
  187. trs[tr].children[2].innerHTML = trs[tr].children[2].innerHTML.match(DateTimeExp)[1];
  188. }
  189. }
  190. }
  191. Announcements.children[1].children[Announcements.children[1].children.length - 1].innerHTML = '<td class="text-right" colspan="3"><a href="/announcements">所有公告……</a></td><td class="text-right" colspan="3"><a href="https://ex124oj.netlify.app/archives/">所有公告……</a></td>';
  192. var Posts = document.createElement('div');
  193. Posts.innerHTML = data.responseText.match(HtmlBodyInnerExp)[1];
  194. for (var i = 0; i < Posts.children.length && i < 5; ++i) {
  195. Announcements.children[1].children[i].children[3].innerHTML = '<a href="https://ex124oj.netlify.app' + Posts.children[i].children[0].children[0].children[1].getAttribute('href') + '">' + Posts.children[i].children[0].children[0].children[1].children[0].innerHTML.match(/^\s*(.*?)\s*$/)[1] + '</a>';
  196. Announcements.children[1].children[i].children[4].innerHTML = '<a class="uoj-username" href="https://ex124oj.netlify.app" style="color:rgb(40,173,202)">Ex124OJ</a>';
  197. var Date = Posts.children[i].children[0].children[0].children[0].innerHTML.match(/^(\d*)\/(\d*)\/(\d*)$/);
  198. if (Date[2].length < 2) Date[2] = '0' + Date[2];
  199. if (Date[3].length < 2) Date[3] = '0' + Date[3];
  200. Announcements.children[1].children[i].children[5].innerHTML = '<small>' + Date[1] + '-' + Date[2] + '-' + Date[3] + '</small>'
  201. }
  202. }
  203. });
  204. }
  205.  
  206. function DiscussionCard() {
  207. var discrd = document.createElement('div');
  208. discrd.setAttribute('class', 'giscus');
  209. document.getElementsByClassName('uoj-footer')[0].before(discrd);
  210. var script = document.createElement('script');
  211. script.setAttribute('src', 'https://giscus.app/client.js');
  212. script.setAttribute('data-repo', 'Sukwants/Discuss124OJ');
  213. script.setAttribute('data-repo-id', 'R_kgDOImiZLA');
  214. script.setAttribute('data-category', 'Ideas');
  215. script.setAttribute('data-category-id', 'DIC_kwDOImiZLM4CTCIj');
  216. script.setAttribute('data-mapping', 'pathname');
  217. script.setAttribute('data-strict', '0');
  218. script.setAttribute('data-reactions-enabled', '1');
  219. script.setAttribute('data-emit-metadata', '0');
  220. script.setAttribute('data-input-position', 'top');
  221. script.setAttribute('data-theme', 'preferred_color_scheme');
  222. script.setAttribute('data-lang', 'zh-CN');
  223. script.setAttribute('crossorigin', 'anonymous');
  224. script.setAttribute('async', '');
  225. document.getElementsByTagName('body')[0].appendChild(script);
  226. GM_addStyle('\
  227. .giscus {\
  228. margin-top: 20px;\
  229. }');
  230. }
  231.  
  232. const ManageStatementExp = /^.*\/manage\/statement(\?.*){0,1}$/
  233. function CodeBlock() {
  234. GM_addStyle('\
  235. @import url(https://cdn.jsdelivr.net/npm/firacode@6.2.0/distr/fira_code.css);\
  236. code {\
  237. font-family: "Fira Code";\
  238. }\
  239. code.sh_cpp>span {\
  240. font-style: normal !important;\
  241. font-weight: 400 !important;\
  242. }\
  243. code.sh_cpp>span.sh_preproc,\
  244. code.sh_cpp>span.sh_keyword,\
  245. code.sh_cpp>span.sh_type {\
  246. color: #8959a8;\
  247. }\
  248. code.sh_cpp>span.sh_string {\
  249. color: #718c00;\
  250. }\
  251. code.sh_cpp>span.sh_cbracket {\
  252. color: #4d4d4c;\
  253. }\
  254. code.sh_cpp>span.sh_symbol {\
  255. color: #3e999f;\
  256. }\
  257. code.sh_cpp>span.sh_number {\
  258. color: #f5871f;\
  259. }\
  260. code.sh_cpp>span.sh_function {\
  261. color: #4271ae;\
  262. }\
  263. code.sh_cpp>span.sh_comment {\
  264. color: #8e908c;\
  265. }\
  266. .copybutton {\
  267. float: right;\
  268. background-color: rgb(0,0,0,.1);\
  269. padding: .25em .625em;\
  270. border: 0 solid transparent;\
  271. border-radius: .28571429rem;\
  272. }\
  273. .copybutton:hover {\
  274. background-color: rgb(0,0,0,.2);\
  275. }\
  276. .copybutton:focus {\
  277. background-color: rgb(0,0,0,.2);\
  278. outline: none;\
  279. }');
  280. if (!ManageStatementExp.test(window.location.href)) {
  281. setTimeout(function(){
  282. var CodeBlocks = document.getElementsByTagName('pre');
  283. for (var cb in CodeBlocks) {
  284. if (CodeBlocks[cb] && CodeBlocks[cb].nodeType) {
  285. var Content = CodeBlocks[cb].textContent;
  286. var InputId = Math.round(Math.random() * 998244353);
  287. var ButtonId = Math.round(Math.random() * 998244353);
  288. CodeBlocks[cb].innerHTML = '<button class="copybutton" id = "' + ButtonId + '" onclick="\
  289. var ib = document.getElementById(\'' + InputId + '\');\
  290. ib.setAttribute(\'style\', \'display:initial\');\
  291. ib.value = \'' + Content.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/'/g, '\\&#39;').replace(/"/g, '&#34;') + '\';\
  292. ib.select();\
  293. document.execCommand(\'copy\');\
  294. ib.setAttribute(\'style\', \'display:none\');\
  295. var ic = document.getElementById(\'' + ButtonId + '\');\
  296. ic.innerHTML = \'已复制\';\
  297. setTimeout(function() { ic.innerHTML = \'复制\'; }, 500);">复制</button>' + CodeBlocks[cb].innerHTML;
  298. var InputBox = document.createElement('textarea');
  299. InputBox.setAttribute('id', InputId);
  300. InputBox.setAttribute('style', 'display:none');
  301. CodeBlocks[cb].appendChild(InputBox);
  302. }
  303. }
  304.  
  305. }, 30);
  306. }
  307. }
  308.  
  309. function NameColor() {
  310. var Names = document.getElementsByClassName('uoj-username');
  311. var NeedsRepeat = false;
  312. for (var i in Names) {
  313. if (Names[i].innerHTML && NameColorList[Names[i].innerHTML]) {
  314. Names[i].style = 'color:' + NameColorList[Names[i].innerHTML][0];
  315. var resN = '';
  316. for (var charN = 1; charN < NameColorList[Names[i].innerHTML].length; ++charN) {
  317. resN = resN + '<font style="color:' + NameColorList[Names[i].innerHTML][charN] + '">' + Names[i].innerHTML.substring(charN - 1, charN) + '</font>';
  318. }
  319. Names[i].innerHTML = resN + Names[i].innerHTML.substring(NameColorList[Names[i].innerHTML].length - 1);
  320. if (Names[i].parentElement.getAttribute('class') == 'legendLabel') {
  321. NeedsRepeat = true;
  322. }
  323. }
  324. }
  325. if (NeedsRepeat) {
  326. setInterval(function(){
  327. var Names = document.getElementsByClassName('uoj-username');
  328. for (var i in Names) {
  329. if (Names[i].innerHTML && Names[i].parentElement.getAttribute('class') == 'legendLabel' && NameColorList[Names[i].innerHTML]) {
  330. Names[i].style = 'color:' + NameColorList[Names[i].innerHTML][0];
  331. var resN = '';
  332. for (var charN = 1; charN < NameColorList[Names[i].innerHTML].length; ++charN) {
  333. resN = resN + '<font style="color:' + NameColorList[Names[i].innerHTML][charN] + '">' + Names[i].innerHTML.substring(charN - 1, charN) + '</font>';
  334. }
  335. Names[i].innerHTML = resN + Names[i].innerHTML.substring(NameColorList[Names[i].innerHTML].length - 1);
  336. }
  337. }
  338. }, 200);
  339. }
  340. var Honors = document.getElementsByClassName('uoj-honor');
  341. for (var j in Honors) {
  342. if (Honors[j].innerHTML && NameColorList[Honors[j].innerHTML]) {
  343. Honors[j].style = 'color:' + NameColorList[Honors[j].innerHTML][0];
  344. var resH = '';
  345. for (var charH = 1; charH < NameColorList[Honors[j].innerHTML].length; ++charH) {
  346. resH = resH + '<font style="color:' + NameColorList[Honors[j].innerHTML][charH] + '">' + Honors[j].innerHTML.substring(charH - 1, charH) + '</font>';
  347. }
  348. Honors[j].innerHTML = resH + Honors[j].innerHTML.substring(NameColorList[Honors[j].innerHTML].length - 1);
  349. }
  350. }
  351. }
  352.  
  353. const NameExp = /^(.{1,}?)( .*){0,1}$/;
  354. function CCFBadge() {
  355. var Names = document.getElementsByClassName('uoj-username');
  356. for (var i in Names) {
  357. if (!Names[i].innerHTML || !NameExp.test(Names[i].textContent)) continue;
  358. var name = Names[i].textContent.match(NameExp)[1];
  359. if (CCFBadgeList[name] && Names[i].parentElement.getAttribute('class') != 'legendLabel') {
  360. Names[i].innerHTML = Names[i].innerHTML + ' <svg width="1em" height="1em" data-v-303bbf52="" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="badge-check" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="margin-bottom:.25em!important;bottom:10px;--fa-primary-color:#fff;--fa-secondary-color:' + CCFBadgeList[name] + ';--fa-secondary-opacity:1;"><g data-v-303bbf52="" class="fa-group"><path data-v-303bbf52="" fill="var(--fa-secondary-color)" d="M512 256a88 88 0 0 0-57.1-82.4A88 88 0 0 0 338.4 57.1a88 88 0 0 0-164.8 0A88 88 0 0 0 57.1 173.6a88 88 0 0 0 0 164.8 88 88 0 0 0 116.5 116.5 88 88 0 0 0 164.8 0 88 88 0 0 0 116.5-116.5A88 88 0 0 0 512 256zm-144.8-44.25l-131 130a11 11 0 0 1-15.55-.06l-75.72-76.33a11 11 0 0 1 .06-15.56L171 224a11 11 0 0 1 15.56.06l42.15 42.49 97.2-96.42a11 11 0 0 1 15.55.06l25.82 26a11 11 0 0 1-.08 15.56z" class="fa-secondary"></path></g></svg>';
  361. }
  362. }
  363. var Honors = document.getElementsByClassName('uoj-honor');
  364. for (var j in Honors) {
  365. if (!Honors[j].innerHTML || !NameExp.test(Honors[j].textContent)) continue;
  366. var honor = Honors[j].textContent.match(NameExp)[1];
  367. if (CCFBadgeList[honor]) {
  368. Honors[j].innerHTML = Honors[j].innerHTML + ' <svg width="1em" height="1em" data-v-303bbf52="" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="badge-check" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="margin-bottom:.25em!important;bottom:10px;--fa-primary-color:#fff;--fa-secondary-color:' + CCFBadgeList[honor] + ';--fa-secondary-opacity:1;"><g data-v-303bbf52="" class="fa-group"><path data-v-303bbf52="" fill="var(--fa-secondary-color)" d="M512 256a88 88 0 0 0-57.1-82.4A88 88 0 0 0 338.4 57.1a88 88 0 0 0-164.8 0A88 88 0 0 0 57.1 173.6a88 88 0 0 0 0 164.8 88 88 0 0 0 116.5 116.5 88 88 0 0 0 164.8 0 88 88 0 0 0 116.5-116.5A88 88 0 0 0 512 256zm-144.8-44.25l-131 130a11 11 0 0 1-15.55-.06l-75.72-76.33a11 11 0 0 1 .06-15.56L171 224a11 11 0 0 1 15.56.06l42.15 42.49 97.2-96.42a11 11 0 0 1 15.55.06l25.82 26a11 11 0 0 1-.08 15.56z" class="fa-secondary"></path></g></svg>';
  369. }
  370. }
  371. }
  372. function TagBadge() {
  373. var Names = document.getElementsByClassName('uoj-username');
  374. for (var i in Names) {
  375. if (!Names[i].innerHTML || !NameExp.test(Names[i].textContent)) continue;
  376. var name = Names[i].textContent.match(NameExp)[1];
  377. if (TagBadgeList[name] && Names[i].parentElement.getAttribute('class') != 'legendLabel') {
  378. Names[i].innerHTML = Names[i].innerHTML + ' <span style="background-color:' + TagBadgeList[name][0] + ';padding:0.2em 0.6em;border-radius:.2em;color:#fff;font-size:0.7em;font-weight:bold;display:inline-block">' + TagBadgeList[name][1] + '</span>';
  379. }
  380. }
  381. var Honors = document.getElementsByClassName('uoj-honor');
  382. for (var j in Honors) {
  383. if (!Honors[j].innerHTML || !NameExp.test(Honors[j].textContent)) continue;
  384. var honor = Honors[j].textContent.match(NameExp)[1];
  385. if (TagBadgeList[honor]) {
  386. Honors[j].innerHTML = Honors[j].innerHTML + ' <span style="background-color:' + TagBadgeList[honor][0] + ';padding:0.2em 0.6em;border-radius:.2em;color:#fff;font-size:0.7em;font-weight:bold;display:inline-block">' + TagBadgeList[honor][1] + '</span>';
  387. }
  388. }
  389. }
  390.  
  391. function TableStyle() {
  392. var Tables = document.getElementsByTagName('table');
  393. for (var table in Tables) {
  394. if (Tables[table].nodeType && Tables[table].parentNode.getAttribute('class') != 'legend' && !Tables[table].classList.length) {
  395. Tables[table].classList.add('table', 'table-bordered');
  396. }
  397. }
  398. var ths = document.getElementsByTagName('th');
  399. for (var th in ths) {
  400. if (ths[th].nodeType && ths[th].getAttribute('align')) {
  401. ths[th].setAttribute('style', 'text-align:' + ths[th].getAttribute('align'));
  402. }
  403. }
  404. }
  405.  
  406. function SubmissionCard() {
  407. setTimeout(function() {
  408. var Content = document.getElementsByClassName('uoj-content')[0];
  409. if (Content.childElementCount == 3) {
  410. var Table = Content.children[0];
  411. var TabList = document.createElement('ul');
  412. TabList.setAttribute('class', 'nav nav-tabs');
  413. TabList.setAttribute('role', 'tablist');
  414. TabList.innerHTML = '<li class="nav-item"><a class="nav-link active" href="#test-cases" role="tab" data-toggle="tab" aria-selected="true"><span class="glyphicon glyphicon-check"></span> 测试点信息</a></li><li class="nav-item"><a class="nav-link" href="#source" role="tab" data-toggle="tab" aria-selected="false"><span class="glyphicon glyphicon-file"></span> 源代码</a></li>';
  415. var TabContent = document.createElement('div');
  416. TabContent.setAttribute('class', 'tab-content');
  417. TabContent.innerHTML = '<div class="tab-pane card active" id="test-cases"><div class="card-body">' + Content.children[2].children[1].innerHTML + '</div></div><div class="tab-pane card" id="source"><div class="card-body">' + Content.children[1].children[1].innerHTML + '</div></div>';
  418. Content.innerHTML = "";
  419. Content.appendChild(Table);
  420. Content.appendChild(TabList);
  421. Content.appendChild(TabContent);
  422. }
  423. }, 50);
  424. }
  425.  
  426. function downloadData() {
  427. var DownloadTag = document.createElement('a');
  428. DownloadTag.setAttribute('role', 'button');
  429. DownloadTag.setAttribute('class', 'btn btn-primary float-right');
  430. DownloadTag.setAttribute('href', '/download.php?type=problem&id=' + window.location.href.match(ProblemRegExp)[1]);
  431. DownloadTag.setAttribute('target', '_blank');
  432. DownloadTag.innerHTML = '<span class="glyphicon glyphicon-download-alt"></span> 下载数据';
  433. document.getElementsByClassName("btn btn-info float-right")[0].after(DownloadTag);
  434. }
  435.  
  436. const GravatarURLRegExp = /\/\/cn.gravatar.com\/avatar\/(.*)$/;
  437. function changeGravatarURL() {
  438. var Gravatar = document.getElementsByClassName('img-thumbnail')[0];
  439. if (Gravatar && Gravatar.nodeType){
  440. console.log(Gravatar);
  441. Gravatar.setAttribute('src', '//gravatar.loli.net/avatar/' + Gravatar.getAttribute('src').match(GravatarURLRegExp)[1]);
  442. }
  443. var Gravatars = document.getElementsByClassName('img-rounded');
  444. for (var gravatar in Gravatars) {
  445. if (Gravatars[gravatar] && Gravatars[gravatar].nodeType && GravatarURLRegExp.test(Gravatars[gravatar].getAttribute('src'))) {
  446. Gravatars[gravatar].setAttribute('src', '//gravatar.loli.net/avatar/' + Gravatars[gravatar].getAttribute('src').match(GravatarURLRegExp)[1]);
  447. }
  448. }
  449. }
  450.  
  451. (function() {
  452. 'use strict';
  453. whenMourn();
  454. trollForAmusement()
  455. BackgroundImage();
  456. changeIcon();
  457. HomepageEntrance();
  458. DiscussionCard();
  459. CodeBlock();
  460. NameColor();
  461. CCFBadge();
  462. TagBadge();
  463. TableStyle();
  464. if (isHomepage()) exAnnouncements();
  465. if (isSubmission()) SubmissionCard();
  466. if (isProblem()) downloadData();
  467. if (isUserProfile() || isBlog()) changeGravatarURL();
  468. })();