CodeForces Helper

优雅打印

  1. // ==UserScript==
  2. // @name CodeForces Helper
  3. // @name:zh-CN CodeForces Helper
  4. // @description Print elegantly
  5. // @description:zh-CN 优雅打印
  6. // @namespace work.pythoner
  7. // @match *://*.codeforces.com/*
  8. // @match *://*.codeforc.es/*
  9. // @run-at document-end
  10. // @grant GM_registerMenuCommand
  11. // @version 1.0
  12. // @author Hanson Hu
  13. // @homepage https://blog.pythoner.work
  14. // @icon https://blog.pythoner.work/favicon.ico
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. (function() {
  19.  
  20. function getToday() {
  21. // local tz
  22. let ret = new Date().toLocaleString('sv').slice(0, 10);
  23. return ret;
  24. }
  25.  
  26. function getTail(str) {
  27. let index = str.lastIndexOf('\/');
  28. return str.substring(index + 1, str.length);
  29. }
  30.  
  31. function onClickPrint() {
  32. $('.menu-box').remove();
  33. $('.second-level-menu').remove();
  34. $('.input-output-copier').remove();
  35. $('#header').remove();
  36. $('#sidebar').remove();
  37. $('#footer').remove();
  38. $('br').remove();
  39. $('hr').remove();
  40.  
  41. $('.header').css('text-align', 'left');
  42. $('.problem-statement .sample-tests .input').css('border', '1px solid #eee');
  43. $('.problem-statement .sample-tests .output').css('border', '1px solid #eee');
  44. $('.problem-statement .sample-tests .title').css({'border-bottom': '1px solid #eee', 'font-size': '1em'});
  45. $('#body').css({'max-width': 'none', 'min-width': '0px'});
  46. $('#pageContent').css({'margin-left': '2em', 'margin-right': '2em', 'padding-top': '0px'});
  47. $('body').css({'zoom': '80%', 'font-size': '1rem'});
  48.  
  49. // override !important
  50. $('.content-with-sidebar').each(function() {
  51. this.style.setProperty('margin-right', '2em', 'important');
  52. });
  53.  
  54. $('.header .title').text(title);
  55.  
  56. let elem = $('<div style="position: absolute; top: 2px; right: 2px; ' +
  57. 'font-family: Bahnschrift, Trebuchet MS, sans-serif; ' +
  58. 'font-weight: lighter; font-stretch: condensed; ' +
  59. 'font-size: 20px;">' +
  60. getToday() +
  61. '</div>');
  62. $('body').append(elem);
  63. }
  64.  
  65. GM_registerMenuCommand('Prepare to print', onClickPrint);
  66.  
  67. let contest = getTail($('#sidebar a').attr('href'));
  68. let title = 'CF' + contest + $('.header .title').text().trim();
  69.  
  70. })();