Beautiful OpenJudge

使用 BootStrap 库美化 OpenJudge

当前为 2023-03-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Beautiful OpenJudge
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.12
  5. // @description 使用 BootStrap 库美化 OpenJudge
  6. // @author Guyutongxue
  7. // @match http://*.openjudge.cn/*
  8. // @match http://*.test.openjudge.org/*
  9. // @exclude http://*.openjudge.cn/admin/*
  10. // @grant none
  11. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js
  12. // @require https://cdn.bootcdn.net/ajax/libs/jquery.form/4.3.0/jquery.form.min.js
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Load BootStrap 4
  19. document.head.innerHTML += `<meta name="viewport" content="width=device-width, initial-scale=1">
  20. <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css">
  21. <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script>
  22. <style>
  23. /* Fix styles*/
  24. /* Titles*/
  25. h4{font-size:inherit;}
  26. h2,h3{font-size:18px;}
  27. h1,h2,h3{font-weight:bold;}
  28. h1{font-size:2em}
  29. /*Headers*/
  30. #headerTop{background:initial;}
  31. #headerTop a{color:initial;}
  32. #userToolbar, #headerTop .logo {font-size: inherit;}
  33. #headerTop #userToolbar .current a.link{background:initial;}
  34. .practice-search button{background:#545b62;font-size:12px;width:25px;padding:0px;}
  35. #groupBigLogo,#groupBigLogo img{max-width: 100%;height: auto;}
  36. #pageTitle{padding-bottom:0px;border-bottom:0px;margin-bottom:0px;}
  37. .wrapper{width:initial;margin:0 10%;}
  38. .appli-group{height:auto;}
  39. /*Contest title*/
  40. .recently-update, .over-time{position:relative;}
  41. .label h3, .current-contest h3{border-bottom:0;}
  42. .group-setting{font-size:smaller;}
  43. /*Tables*/
  44. table{line-height:initial;font-size:smaller;}
  45. .my-solutions td.result{line-height:2.5em;}
  46. #problemsList table tr{font-size:inherit;line-height:inherit}
  47. .my-solutions{font-size:smaller;}
  48. .my-solutions .time{width:auto;}
  49. .practice-info table tr td{padding:.5em;}
  50. table th{font-weight:bold;}
  51. table thead tr{background:initial;}
  52. /*Personal Page*/
  53. .recently-submit table td{padding:.3rem;}
  54. .recently-submit .contest{width:auto;}
  55. .all-group li{float:left; overflow: initial;}
  56. .my-group-logo{margin-right:15px;}
  57. /*Problem*/
  58. .problem-content pre {margin-bottom:0;}
  59. .problem-content dd {margin-bottom:0;}
  60. </style>`;
  61. // Dealing with main header
  62. $("#headerTop").addClass('bg-light');
  63. $("#userToolbar").css('margin-bottom','0');
  64. $("#userToolbar").addClass('btn-group btn-group-sm');
  65. $("#userToolbar li").addClass('btn btn-sm btn-light');
  66. $(".account-list li").attr('class', 'btn btn-sm btn-link');
  67. $(".search-form").addClass('inline-form');
  68. $(".search-form input").addClass('form-control').attr('value','').attr('placeholder','题目ID, 标题, 描述');
  69. $("button").addClass('btn btn-secondary');
  70. $(".search-form button").html("&#10140;"); // right arrow
  71.  
  72. // Dealing with main container
  73. $("#pagebody,#sitePagebody,#footer .wrapper").attr('class','container');
  74. $("#pagebody .wrapper,#sitePagebody .wrapper").attr('class','row mt-3');
  75. $(".col-2").removeClass('col-2').addClass('col-md-2');
  76. $(".col-3").removeClass('col-3').addClass('col-md-3');
  77. $(".col-4").removeClass('col-4').addClass('col-md-4');
  78. $(".col-8").removeClass('col-8').addClass('col-md-8');
  79. $(".col-9").removeClass('col-9').addClass('col-md-9');
  80. $(".col-10").removeClass('col-10').addClass('col-md-10');
  81. $(".problem-page").removeClass('problem-page');
  82. $(".problem-statistics").removeClass('problem-statistics');
  83. $(".problem-status").removeClass('problem-status');
  84. $(".problem-my-statistics").removeClass('problem-my-statistics');
  85.  
  86. // Dealing with problem header
  87. $("#header").addClass("mb-4");
  88.  
  89. // Group index page
  90. $(".contest-info").removeClass('contest-info').addClass('d-flex justify-content-lg-between flex-lg-row flex-column').css('border-bottom','1px dotted #666666');
  91. $(".recently-update").remove();
  92. $(".practice-info h3,.coming-contest h3,.past-contest h3").css('border-bottom','1px dotted #666666');
  93. // console.log($(".group-setting").children().text().replace(/\s+/g, ""));
  94. // If I'm in this group, then change it's style
  95. if($(".group-setting").children().text().replace(/\s+/g, "")!=""){
  96. $(".group-setting").html('\
  97. <ul class="btn-group btn-group-sm">\
  98. <a href="/mine/" class="btn btn-sm btn-outline-secondary ">修改设定</a>\
  99. <a href="javascript:void(0);" onclick="if (confirm(\'你确定要退出小组吗?\')) api.leaveGroup(9,null,local.redirect);" class="btn btn-sm btn-danger">退出小组</a>\
  100. </ul>').addClass('mt-3 mb-0');
  101. }
  102.  
  103. // 夹带私货
  104. $("img[alt='软件设计实践']").attr("src", "https://s1.ax1x.com/2023/03/02/ppk9fGn.png");
  105.  
  106. // Site index page fixing
  107. $(".row").children('p').addClass('col-md-12 alert alert-info');
  108. $(".row").children('p').each(function(){if($(this).text().replace(/\s+/g, "")=="")$(this).hide();}); // remove extra spaces
  109. $(".user-group,.my-group-contest").addClass("row");
  110. $(".recently-submit,.my-contest-list").addClass('col-md-10');
  111.  
  112. // Alerts
  113. $(".notification").attr('class','alert alert-warning');
  114. $(".contest-description").attr('class','alert alert-info');
  115. $(".notice").attr('class','alert alert-danger');
  116.  
  117. // Change top menu
  118. var tabs = $("#topMenu ul")
  119. tabs.addClass('nav nav-tabs');
  120. tabs.children('li').addClass('nav-item');
  121. $('.nav a').addClass('nav-link');
  122. $(".current-show").children().addClass('nav-link active');
  123. tabs.children('li').removeClass('current-show');
  124. $("#topMenu").addClass('col-md-12 mb-3 mt-2').removeAttr('id');
  125.  
  126. // Change bottom menu
  127. tabs = $(".bottomMenu");
  128. tabs.addClass('pagination');
  129. tabs.children('li').addClass('page-item');
  130. $('.pagination a').addClass('page-link');
  131. $(".current-show").addClass('active');
  132. tabs.children('li').removeClass('current-show');
  133.  
  134. // Change tables' style
  135. $("table").addClass('table table-sm table-hover table-responsive');
  136. $("#main,#contestStatistics,#problemStatus").children("table").wrapAll("<div class='row justify-content-center'><div class='col-auto'></div></div>");
  137. $(".practice-info table,#problemsList table,.recently-submit table").removeClass('table-responsive');
  138. $("thead tr td").replaceWith(function () {
  139. return $("<th />").append($(this).contents());
  140. });
  141. $("table thead").addClass('thead-light text-center');
  142. $(".practice-info table thead").removeClass('text-center');
  143. $("table td.accepted,table td.submissions,table td.code-length").css('min-width','5em');
  144. $("table td.title").css('min-width','15em');
  145.  
  146.  
  147. // Remove too long text
  148. $("td.class-name,td.className").each(function() {
  149. if ($(this).text().length > 10 && $(this).width() < 150) {
  150. $(this).attr('title',$(this).text());
  151. $(this).html($(this).text().replace(/\s+/g, "").substr(0, 10) + "...")
  152. }
  153. })
  154.  
  155. // Change searching form
  156. $(".status-search form").addClass('form-inline justify-content-center');
  157. $(".status-query-params").addClass('row');
  158. $(".status-query-params input,.status-query-params select").addClass('form-control form-control-sm');
  159. $(".status-query-params button").addClass('btn-sm');
  160.  
  161. // Change page bar
  162. var pageBar = $(".page-bar");
  163. if(pageBar.length > 0){
  164. pageBar.removeClass('page-bar');
  165. pageBar = pageBar.children('.pages').attr('class','pagination pagination-sm justify-content-center');
  166. pageBar.children().each(function(){
  167. if($(this).hasClass('current')){
  168. $(this).attr('class','page-link');
  169. $(this).wrapAll('<span class="page-item active"></span>');
  170. } else if ($(this).is('a')){
  171. $(this).attr('class','page-link');
  172. $(this).wrapAll('<span class="page-item"></span>');
  173. } else {
  174. $(this).attr('class','page-link');
  175. $(this).wrapAll('<span class="page-item disabled"></span>');
  176. }
  177. });
  178. // If it's a contest page, add pagigation in the top
  179. if($(".timeBar").length > 0) {
  180. $(".timeBar").after(pageBar.clone());
  181. }
  182. }
  183.  
  184. var abbr = {
  185. "Accepted": "AC",
  186. "Wrong Answer": "WA",
  187. "Time Limit Exceeded": "TLE",
  188. "Memory Limit Exceeded": "MLE",
  189. "Output Limit Exceeded": "OLE",
  190. "Runtime Error": "RE",
  191. "Compile Error": "CE",
  192. "Presentation Error": "PE",
  193. "Waiting": "W.",
  194. "Problem Disabled": "PD",
  195. "Running And Judging": "R&J.",
  196. "System Error": "SE",
  197. "Validator Error": "VE"
  198. };
  199.  
  200. var color = {
  201. "Accepted": "#52C41A",
  202. "Wrong Answer": "#E74C3C",
  203. "Presentation Error": "#00A497",
  204. "Time Limit Exceeded": "#052242",
  205. "Memory Limit Exceeded": "#052242",
  206. "Output Limit Exceeded": "#E74C3C",
  207. "Runtime Error": "#9D3DCF",
  208. "Compile Error": "#FADB14",
  209. "Waiting": "#14558F",
  210. "Problem Disabled": "#AAAAAA",
  211. "Running And Judging": "#14558F",
  212. "System Error":"#CC317C",
  213. "Validator Error": "#CC317C"
  214. }
  215.  
  216. // Change solution's style
  217. if(/^\/[^\/]+\/solution\/\d+\/?$/.test(window.location.pathname)) {
  218.  
  219. var result = $('.compile-status a').text();
  220. $('.compile-status a').remove();
  221.  
  222. var memory = $('.compile-info dl dd:eq(3)').text();
  223. var time = $('.compile-info dl dd:eq(4)').text();
  224.  
  225. var detail = result == "Compile Error" || result == "Waiting" ? "" : time +"/" + memory;
  226.  
  227. var newStatus = "\
  228. <div class='beautiful-status' title='" + result + "'>\
  229. " + abbr[result] + "\
  230. <div style='font-size:11px;'>" + detail + "</div>\
  231. </div>";
  232.  
  233. $('.compile-status').append(newStatus);
  234.  
  235. $('.beautiful-status').css({
  236. "background-color": color[result],
  237. "height": "100px",
  238. "width": "100px",
  239. "margin-top": "20px",
  240. "display": "flex",
  241. "align-items": "center",
  242. "justify-content": "center",
  243. "flex-direction": "column",
  244. "color": "white",
  245. "font-size": "24px",
  246. "font-family": "-apple-system, BlinkMacSystemFont, 'San Francisco', 'Helvetica Neue', 'Noto Sans CJK SC', 'Noto Sans CJK', 'Source Han Sans', 'PingFang SC', 'Microsoft YaHei', sans-serif"
  247. });
  248. }
  249.  
  250. // Change code's font
  251. if(/^\/[^\/]+\/[^\/]+\/submit\/?$/.test(window.location.pathname)) {
  252. $("textarea#source").css({
  253. "font-family": "Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace",
  254. "width": "100%"
  255. })
  256. // $("#submit").removeClass('col-md-9');
  257. $("#submit dt:eq(1)").text("语言");
  258. $("#submit form textarea").addClass('form-control');
  259. $("#main").width("100%");
  260. $(".submit-button").removeClass('btn-secondary').addClass('btn-primary');
  261. }
  262. $("pre,span.sh_string").css({
  263. "font-family": "Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace"
  264. })
  265.  
  266. // Change question('clarify')'s style
  267. if(/^\/[^\/]+\/clarify(\/[^\/]*\/?)?$/.test(window.location.pathname) || /^\/mine\/?$/.test(window.location.pathname)) {
  268. $("#main form").addClass('form');
  269. $("#main form textarea,#main form :text").addClass("form-control").width("90%");
  270. $("#main form :text").height("auto");
  271. }
  272.  
  273. // Change ranking style
  274. if(/^\/[^\/]+\/ranking\/?$/.test(window.location.pathname)) {
  275. let allData = $("td.alpha");
  276. for(let i = 0; i < allData.length; i++) {
  277. let text = allData.eq(i).html();
  278. if(text.indexOf("<a") != -1) continue;
  279. if(text.indexOf(":") != -1 ) { // If passed
  280. let res = '&#8730;';
  281. if(text.indexOf('<br>') != -1) {
  282. res = "&#8730;" + text.split('<br>')[1];
  283. }
  284. allData.eq(i).html(res);
  285. allData.eq(i).css({
  286. "background-color": "#dff0d890",
  287. "color": "#3c763d"
  288. });
  289. } else if(text.indexOf('(-') != -1) { // Or not passed, but tried
  290. let res = text.split('<br>')[1];
  291. allData.eq(i).html(res);
  292. allData.eq(i).css({
  293. "background-color": "#f2dede90",
  294. "color": "#a94442"
  295. });
  296. }
  297. }
  298.  
  299. $(document).ready(function(){
  300. // If too wide, add scrolling event
  301. if($('table')[0].scrollWidth > $('table').width()) {
  302. $('table').attr('id','scroll-horizontally');
  303. {
  304. function scrollHorizontally(e) {
  305. e = window.event || e;
  306. var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
  307. document.getElementById('scroll-horizontally').scrollLeft -= (delta * 60);
  308. e.preventDefault();
  309. }
  310. $('#scroll-horizontally').on('mousewheel',scrollHorizontally);
  311. }
  312. }
  313. });
  314.  
  315. }
  316.  
  317. // Change other status's style
  318. var otherResult = $('.result-wrong,.result-ce,.result-right,.result-pending');
  319. otherResult.css({
  320. "padding": "3px 6px",
  321. "color": "white",
  322. "border-radius": "2px",
  323. "font-style": "normal"
  324. });
  325. for(let i = 0; i < otherResult.length; i++) {
  326. let res = otherResult.eq(i).text();
  327. otherResult.eq(i).text(abbr[res]);
  328. otherResult.eq(i).attr('title',res);
  329. otherResult.eq(i).css({
  330. "background-color": color[res],
  331. });
  332. }
  333. $('.result').css('width','auto');
  334.  
  335.  
  336. // Change finish ratio's style
  337. function getColorByRatio(ratio){
  338. var one = (255+255) / 100;
  339. var r = 0;
  340. var g = 0;
  341. var b = 0;
  342. if (ratio < 50) {
  343. r = one * ratio;
  344. g = 255;
  345. }
  346. if (ratio >= 50) {
  347. g = 255 - ((ratio - 50 ) * one) ;
  348. r = 255;
  349. }
  350. r = parseInt(r);
  351. g = parseInt(g);
  352. b = parseInt(b);
  353. return "rgba(" + r + "," + g + "," + b + ",0.5)";
  354. }
  355. var ratios = $('.ratio');
  356. for(let i = 0; i < ratios.length; i++) {
  357. let value = parseInt(ratios.eq(i).text().replace('%',''));
  358. if (!isNaN(value)) {
  359. ratios.eq(i).css({'background-color':getColorByRatio(100 - value),'min-width':'4em'});
  360. }
  361. }
  362.  
  363. // Change time bar
  364. if($('.timeBar').length > 0) {
  365. let startTime = new Date($(".start-time-dd").text());
  366. let endTime = new Date($(".end-time-dd").text());
  367. let currentState = $(".current-time").text();
  368. function formatDateTime(date) {
  369. var y = date.getFullYear();
  370. var m = date.getMonth() + 1;
  371. m = m < 10 ? ('0' + m) : m;
  372. var d = date.getDate();
  373. d = d < 10 ? ('0' + d) : d;
  374. var h = date.getHours();
  375. h=h < 10 ? ('0' + h) : h;
  376. var minute = date.getMinutes();
  377. minute = minute < 10 ? ('0' + minute) : minute;
  378. var second=date.getSeconds();
  379. second=second < 10 ? ('0' + second) : second;
  380. return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
  381. };
  382. let newTime = `
  383. <div class="row">
  384. <div class="col-md-3 text-left"><small>开始时间</small><br><b>${formatDateTime(startTime)}</b></div>
  385. <div class="col-md-6 text-center"><b>${currentState}</b><p><small id="currentTime"></small></p></div>
  386. <div class="col-md-3 text-right"><small>结束时间</small><br><b>${formatDateTime(endTime)}</b></div>
  387. </div>`;
  388. $('.timeBar').append(newTime).addClass('mt-4 mb-4');
  389. $('.current-contest-info,.past-contest-info').remove();
  390. $('.timeBar').append('<p style="display:none;" id="timeclock"></p>');
  391. if(new Date() < endTime && new Date() > startTime){
  392. let total = endTime - startTime;
  393. let progress = `
  394. <div class="progress">
  395. <div class="progress-bar progress-bar-striped progress-bar-animated" id="timeProgressBar"
  396. role="progressbar" style="width: 0%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
  397. </div>
  398. </div>`;
  399. $('.timeBar').append(progress);
  400. function updateValue(){
  401. var currentTime = new Date();
  402. var percent = (currentTime - startTime) * 100 / total;
  403. $("#timeProgressBar").attr({'style':'width:' + percent + '%','aria-valuenow':percent + ''});
  404. $("#currentTime").text(formatDateTime(currentTime));
  405. }
  406. updateValue();
  407. setInterval(updateValue,1000);
  408. }
  409. }
  410.  
  411. // Change those old icon to unicode character
  412. var solvedIcon = $('.solved');
  413. for(let i = 0; i < solvedIcon.length; i++) {
  414. let html = solvedIcon.eq(i).html();
  415. if(html.indexOf('accepted') != -1) {
  416. solvedIcon.eq(i).html("<span style='color:green;font-weight:bold;'>&#8730;</span>");
  417. }
  418. else if(html.indexOf('wrong') != -1) {
  419. solvedIcon.eq(i).html("<span style='color:red;;font-weight:bold;'>&#215;</span>");
  420. }
  421. }
  422.  
  423. // Change login page
  424. var loginForm = $("#main form[action='/api/auth/login/']");
  425. if(loginForm.length>0) {
  426. loginForm.parent().removeClass('col-md-8').addClass('col-md-12');
  427. loginForm.html(`
  428. <style>
  429. .form-signin {
  430. width: 100%;
  431. max-width: 330px;
  432. padding: 15px;
  433. margin: auto;
  434. }
  435. .form-signin .checkbox {
  436. font-weight: 400;
  437. }
  438. .form-signin .form-control {
  439. position: relative;
  440. box-sizing: border-box;
  441. height: auto;
  442. padding: 10px;
  443. font-size: 16px;
  444. }
  445. .form-signin .form-control:focus {
  446. z-ind ex: 2;
  447. }
  448. .form-signin input[type="text"] {
  449. margin-bottom: -1px;
  450. border-bottom-right-radius: 0;
  451. border-bottom-left-radius: 0;
  452. }
  453. .form-signin input[type="password"] {
  454. margin-bottom: 10px;
  455. border-top-left-radius: 0;
  456. border-top-right-radius: 0;
  457. }
  458. </style>
  459. <form action="/api/auth/login/" method="post" onsubmit="$(this).ajaxSubmit({dataType:'json',success:local.redirect,'target':'#result'}).find(':submit').each(function(){this.disabled=true;});return false;" class="form-signin">\
  460. <input type="hidden" name="redirectUrl" value="">
  461. <div class="login-message"></div>
  462. <label for="email" class="sr-only">邮箱地址</label>
  463. <input id="email" type="text" name="email" size="20" onfocus="this.select();" class="form-control" placeholder="邮箱地址">
  464. <label for="password" class="sr-only">密码</label>
  465. <input id="password" type="password" name="password" size="20" class="form-control" placeholder="密码">
  466. <button type="submit" class="btn btn-block btn-primary mt-3">登入</button>
  467. <div class="d-flex justify-content-between mt-3">
  468. <p><a href="/register/">点此注册(不可用)</a></p>
  469. <p><a href="http://openjudge.cn/auth/forget/">忘记密码?</a></p>
  470. </div>
  471. </form>`);
  472. }
  473.  
  474. // Change register style
  475. if(/^\/register\/?$/.test(window.location.pathname)) {
  476. var originalStyle = $('#pagebody .row,#sitePagebody .row').children('style').text();
  477. $('#pagebody .row,#sitePagebody .row').children('style').text(originalStyle.replace(/\.btn\s*\{[^}]*\}/,''));
  478. $('#pagebody .row,#sitePagebody .row').addClass('justify-content-center');
  479. $('#main').removeClass('col-md-10').addClass('col-md-4');
  480. $('#main form dd,form dt').remove();
  481. $('#main form').prepend(`
  482. <div class="mb-3">
  483. <label for="regEmail">Email地址</label>
  484. <input id="regEmail" type="text" name="user_email" class="form-control">
  485. </div>
  486. <div class="mb-3">
  487. <label for="regName">用户名</label>
  488. <input id="regName" type="text" name="user_name" class="form-control">
  489. </div>
  490. <div class="mb-3">
  491. <label for="regPasswd">密码</label>
  492. <input id="regPasswd" type="password" name="user_passwd" class="form-control">
  493. </div>
  494. <div class="mb-3">
  495. <label for="regPasswd2">确认密码</label>
  496. <input id="regPasswd2" type="password" name="user_passwd2" class="form-control">
  497. </div>`);
  498. $('#main form').append(`
  499. <p id="wait" class="hide">正在加载验证码......</p>
  500. <p id="notice" class="hide">请先拖动验证码到相应位置</p>
  501. <button type="submit" class="mt-3 btn btn-block btn-primary btn-lg">注册(不可用)</button>`);
  502. };
  503. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址