Ex124OJ

Extend 124OJ!

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

  1. // ==UserScript==
  2. // @name Ex124OJ
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.7.4
  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. function exAnnouncements() {
  170. GM_xmlhttpRequest({
  171. method: "post",
  172. url: 'https://ex124oj.netlify.app',
  173. headers: { "Content-Type": "application/x-www-form-urlencoded" },
  174. onload: function(r) {
  175. console.log(r);
  176. }
  177. });
  178. }
  179.  
  180. function DiscussionCard() {
  181. var discrd = document.createElement('div');
  182. discrd.setAttribute('class', 'giscus');
  183. document.getElementsByClassName('uoj-footer')[0].before(discrd);
  184. var script = document.createElement('script');
  185. script.setAttribute('src', 'https://giscus.app/client.js');
  186. script.setAttribute('data-repo', 'Sukwants/Discuss124OJ');
  187. script.setAttribute('data-repo-id', 'R_kgDOImiZLA');
  188. script.setAttribute('data-category', 'Ideas');
  189. script.setAttribute('data-category-id', 'DIC_kwDOImiZLM4CTCIj');
  190. script.setAttribute('data-mapping', 'pathname');
  191. script.setAttribute('data-strict', '0');
  192. script.setAttribute('data-reactions-enabled', '1');
  193. script.setAttribute('data-emit-metadata', '0');
  194. script.setAttribute('data-input-position', 'top');
  195. script.setAttribute('data-theme', 'preferred_color_scheme');
  196. script.setAttribute('data-lang', 'zh-CN');
  197. script.setAttribute('crossorigin', 'anonymous');
  198. script.setAttribute('async', '');
  199. document.getElementsByTagName('body')[0].appendChild(script);
  200. GM_addStyle('\
  201. .giscus {\
  202. margin-top: 20px;\
  203. }');
  204. }
  205.  
  206. const ManageStatementExp = /^.*\/manage\/statement(\?.*){0,1}$/
  207. function CodeBlock() {
  208. GM_addStyle('\
  209. @import url(https://cdn.jsdelivr.net/npm/firacode@6.2.0/distr/fira_code.css);\
  210. code {\
  211. font-family: "Fira Code";\
  212. }\
  213. code.sh_cpp>span {\
  214. font-style: normal !important;\
  215. font-weight: 400 !important;\
  216. }\
  217. code.sh_cpp>span.sh_preproc,\
  218. code.sh_cpp>span.sh_keyword,\
  219. code.sh_cpp>span.sh_type {\
  220. color: #8959a8;\
  221. }\
  222. code.sh_cpp>span.sh_string {\
  223. color: #718c00;\
  224. }\
  225. code.sh_cpp>span.sh_cbracket {\
  226. color: #4d4d4c;\
  227. }\
  228. code.sh_cpp>span.sh_symbol {\
  229. color: #3e999f;\
  230. }\
  231. code.sh_cpp>span.sh_number {\
  232. color: #f5871f;\
  233. }\
  234. code.sh_cpp>span.sh_function {\
  235. color: #4271ae;\
  236. }\
  237. code.sh_cpp>span.sh_comment {\
  238. color: #8e908c;\
  239. }\
  240. .copybutton {\
  241. float: right;\
  242. background-color: rgb(0,0,0,.1);\
  243. padding: .25em .625em;\
  244. border: 0 solid transparent;\
  245. border-radius: .28571429rem;\
  246. }\
  247. .copybutton:hover {\
  248. background-color: rgb(0,0,0,.2);\
  249. }\
  250. .copybutton:focus {\
  251. background-color: rgb(0,0,0,.2);\
  252. outline: none;\
  253. }');
  254. if (!ManageStatementExp.test(window.location.href)) {
  255. setTimeout(function(){
  256. var CodeBlocks = document.getElementsByTagName('pre');
  257. for (var cb in CodeBlocks) {
  258. if (CodeBlocks[cb] && CodeBlocks[cb].nodeType) {
  259. var Content = CodeBlocks[cb].textContent;
  260. var InputId = Math.round(Math.random() * 998244353);
  261. var ButtonId = Math.round(Math.random() * 998244353);
  262. CodeBlocks[cb].innerHTML = '<button class="copybutton" id = "' + ButtonId + '" onclick="\
  263. var ib = document.getElementById(\'' + InputId + '\');\
  264. ib.setAttribute(\'style\', \'display:initial\');\
  265. ib.value = \'' + Content.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/'/g, '\\&#39;').replace(/"/g, '&#34;') + '\';\
  266. ib.select();\
  267. document.execCommand(\'copy\');\
  268. ib.setAttribute(\'style\', \'display:none\');\
  269. var ic = document.getElementById(\'' + ButtonId + '\');\
  270. ic.innerHTML = \'已复制\';\
  271. setTimeout(function() { ic.innerHTML = \'复制\'; }, 500);">复制</button>' + CodeBlocks[cb].innerHTML;
  272. var InputBox = document.createElement('textarea');
  273. InputBox.setAttribute('id', InputId);
  274. InputBox.setAttribute('style', 'display:none');
  275. CodeBlocks[cb].appendChild(InputBox);
  276. }
  277. }
  278.  
  279. }, 30);
  280. }
  281. }
  282.  
  283. function NameColor() {
  284. var Names = document.getElementsByClassName('uoj-username');
  285. var NeedsRepeat = false;
  286. for (var i in Names) {
  287. if (Names[i].innerHTML && NameColorList[Names[i].innerHTML]) {
  288. Names[i].style = 'color:' + NameColorList[Names[i].innerHTML][0];
  289. var resN = '';
  290. for (var charN = 1; charN < NameColorList[Names[i].innerHTML].length; ++charN) {
  291. resN = resN + '<font style="color:' + NameColorList[Names[i].innerHTML][charN] + '">' + Names[i].innerHTML.substring(charN - 1, charN) + '</font>';
  292. }
  293. Names[i].innerHTML = resN + Names[i].innerHTML.substring(NameColorList[Names[i].innerHTML].length - 1);
  294. if (Names[i].parentElement.getAttribute('class') == 'legendLabel') {
  295. NeedsRepeat = true;
  296. }
  297. }
  298. }
  299. if (NeedsRepeat) {
  300. setInterval(function(){
  301. var Names = document.getElementsByClassName('uoj-username');
  302. for (var i in Names) {
  303. if (Names[i].innerHTML && Names[i].parentElement.getAttribute('class') == 'legendLabel' && NameColorList[Names[i].innerHTML]) {
  304. Names[i].style = 'color:' + NameColorList[Names[i].innerHTML][0];
  305. var resN = '';
  306. for (var charN = 1; charN < NameColorList[Names[i].innerHTML].length; ++charN) {
  307. resN = resN + '<font style="color:' + NameColorList[Names[i].innerHTML][charN] + '">' + Names[i].innerHTML.substring(charN - 1, charN) + '</font>';
  308. }
  309. Names[i].innerHTML = resN + Names[i].innerHTML.substring(NameColorList[Names[i].innerHTML].length - 1);
  310. }
  311. }
  312. }, 200);
  313. }
  314. var Honors = document.getElementsByClassName('uoj-honor');
  315. for (var j in Honors) {
  316. if (Honors[j].innerHTML && NameColorList[Honors[j].innerHTML]) {
  317. Honors[j].style = 'color:' + NameColorList[Honors[j].innerHTML][0];
  318. var resH = '';
  319. for (var charH = 1; charH < NameColorList[Honors[j].innerHTML].length; ++charH) {
  320. resH = resH + '<font style="color:' + NameColorList[Honors[j].innerHTML][charH] + '">' + Honors[j].innerHTML.substring(charH - 1, charH) + '</font>';
  321. }
  322. Honors[j].innerHTML = resH + Honors[j].innerHTML.substring(NameColorList[Honors[j].innerHTML].length - 1);
  323. }
  324. }
  325. }
  326.  
  327. const NameExp = /^(.{1,}?)( .*){0,1}$/;
  328. function CCFBadge() {
  329. var Names = document.getElementsByClassName('uoj-username');
  330. for (var i in Names) {
  331. if (!Names[i].innerHTML || !NameExp.test(Names[i].textContent)) continue;
  332. var name = Names[i].textContent.match(NameExp)[1];
  333. if (CCFBadgeList[name] && Names[i].parentElement.getAttribute('class') != 'legendLabel') {
  334. 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>';
  335. }
  336. }
  337. var Honors = document.getElementsByClassName('uoj-honor');
  338. for (var j in Honors) {
  339. if (!Honors[j].innerHTML || !NameExp.test(Honors[j].textContent)) continue;
  340. var honor = Honors[j].textContent.match(NameExp)[1];
  341. if (CCFBadgeList[honor]) {
  342. 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>';
  343. }
  344. }
  345. }
  346. function TagBadge() {
  347. var Names = document.getElementsByClassName('uoj-username');
  348. for (var i in Names) {
  349. if (!Names[i].innerHTML || !NameExp.test(Names[i].textContent)) continue;
  350. var name = Names[i].textContent.match(NameExp)[1];
  351. if (TagBadgeList[name] && Names[i].parentElement.getAttribute('class') != 'legendLabel') {
  352. 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>';
  353. }
  354. }
  355. var Honors = document.getElementsByClassName('uoj-honor');
  356. for (var j in Honors) {
  357. if (!Honors[j].innerHTML || !NameExp.test(Honors[j].textContent)) continue;
  358. var honor = Honors[j].textContent.match(NameExp)[1];
  359. if (TagBadgeList[honor]) {
  360. 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>';
  361. }
  362. }
  363. }
  364.  
  365. function TableStyle() {
  366. var Tables = document.getElementsByTagName('table');
  367. for (var table in Tables) {
  368. if (Tables[table].nodeType && Tables[table].parentNode.getAttribute('class') != 'legend' && !Tables[table].classList.length) {
  369. Tables[table].classList.add('table', 'table-bordered');
  370. }
  371. }
  372. var ths = document.getElementsByTagName('th');
  373. for (var th in ths) {
  374. if (ths[th].nodeType && ths[th].getAttribute('align')) {
  375. ths[th].setAttribute('style', 'text-align:' + ths[th].getAttribute('align'));
  376. }
  377. }
  378. }
  379.  
  380. function SubmissionCard() {
  381. setTimeout(function() {
  382. var Content = document.getElementsByClassName('uoj-content')[0];
  383. if (Content.childElementCount == 3) {
  384. var Table = Content.children[0];
  385. var TabList = document.createElement('ul');
  386. TabList.setAttribute('class', 'nav nav-tabs');
  387. TabList.setAttribute('role', 'tablist');
  388. 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>';
  389. var TabContent = document.createElement('div');
  390. TabContent.setAttribute('class', 'tab-content');
  391. 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>';
  392. Content.innerHTML = "";
  393. Content.appendChild(Table);
  394. Content.appendChild(TabList);
  395. Content.appendChild(TabContent);
  396. }
  397. }, 50);
  398. }
  399.  
  400. function downloadData() {
  401. var DownloadTag = document.createElement('a');
  402. DownloadTag.setAttribute('role', 'button');
  403. DownloadTag.setAttribute('class', 'btn btn-primary float-right');
  404. DownloadTag.setAttribute('href', '/download.php?type=problem&id=' + window.location.href.match(ProblemRegExp)[1]);
  405. DownloadTag.setAttribute('target', '_blank');
  406. DownloadTag.innerHTML = '<span class="glyphicon glyphicon-download-alt"></span> 下载数据';
  407. document.getElementsByClassName("btn btn-info float-right")[0].after(DownloadTag);
  408. }
  409.  
  410. const GravatarURLRegExp = /\/\/cn.gravatar.com\/avatar\/(.*)$/;
  411. function changeGravatarURL() {
  412. var Gravatar = document.getElementsByClassName('img-thumbnail')[0];
  413. if (Gravatar && Gravatar.nodeType){
  414. console.log(Gravatar);
  415. Gravatar.setAttribute('src', '//gravatar.loli.net/avatar/' + Gravatar.getAttribute('src').match(GravatarURLRegExp)[1]);
  416. }
  417. var Gravatars = document.getElementsByClassName('img-rounded');
  418. for (var gravatar in Gravatars) {
  419. if (Gravatars[gravatar] && Gravatars[gravatar].nodeType && GravatarURLRegExp.test(Gravatars[gravatar].getAttribute('src'))) {
  420. Gravatars[gravatar].setAttribute('src', '//gravatar.loli.net/avatar/' + Gravatars[gravatar].getAttribute('src').match(GravatarURLRegExp)[1]);
  421. }
  422. }
  423. }
  424.  
  425. (function() {
  426. 'use strict';
  427. whenMourn();
  428. trollForAmusement()
  429. BackgroundImage();
  430. changeIcon();
  431. HomepageEntrance();
  432. exAnnouncements();
  433. DiscussionCard();
  434. CodeBlock();
  435. NameColor();
  436. CCFBadge();
  437. TagBadge();
  438. TableStyle();
  439. if (isSubmission()) SubmissionCard();
  440. if (isProblem()) downloadData();
  441. if (isUserProfile() || isBlog()) changeGravatarURL();
  442. })();