Simple Print LeetCode Problems

Removed unnecessary elements in the page for a clear PDF print of the leetcode question only

  1. // ==UserScript==
  2. // @name Simple Print LeetCode Problems
  3. // @namespace https://greatest.deepsurf.us/en/users/114838-groundzyy
  4. // @version 0.3.3.31
  5. // @description Removed unnecessary elements in the page for a clear PDF print of the leetcode question only
  6. // @author groundzyy
  7. // @match https://leetcode.com/problems/*
  8. // ==/UserScript==
  9.  
  10. function waitForKeyElements (
  11. selectorTxt, /* Required: The jQuery selector string that
  12. specifies the desired element(s).
  13. */
  14. actionFunction, /* Required: The code to run when elements are
  15. found. It is passed a jNode to the matched
  16. element.
  17. */
  18. bWaitOnce, /* Optional: If false, will continue to scan for
  19. new elements even after the first match is
  20. found.
  21. */
  22. iframeSelector /* Optional: If set, identifies the iframe to
  23. search.
  24. */
  25. ) {
  26. var targetNodes, btargetsFound;
  27.  
  28. if (typeof iframeSelector == "undefined")
  29. targetNodes = $(selectorTxt);
  30. else
  31. targetNodes = $(iframeSelector).contents ()
  32. .find (selectorTxt);
  33.  
  34. if (targetNodes && targetNodes.length > 0) {
  35. btargetsFound = true;
  36. /*--- Found target node(s). Go through each and act if they
  37. are new.
  38. */
  39. targetNodes.each ( function () {
  40. var jThis = $(this);
  41. var alreadyFound = jThis.data ('alreadyFound') || false;
  42.  
  43. if (!alreadyFound) {
  44. //--- Call the payload function.
  45. var cancelFound = actionFunction (jThis);
  46. if (cancelFound)
  47. btargetsFound = false;
  48. else
  49. jThis.data ('alreadyFound', true);
  50. }
  51. } );
  52. }
  53. else {
  54. btargetsFound = false;
  55. }
  56.  
  57. //--- Get the timer-control variable for this selector.
  58. var controlObj = waitForKeyElements.controlObj || {};
  59. var controlKey = selectorTxt.replace (/[^\w]/g, "_");
  60. var timeControl = controlObj [controlKey];
  61.  
  62. //--- Now set or clear the timer as appropriate.
  63. if (btargetsFound && bWaitOnce && timeControl) {
  64. //--- The only condition where we need to clear the timer.
  65. clearInterval (timeControl);
  66. delete controlObj [controlKey]
  67. }
  68. else {
  69. //--- Set a timer, if needed.
  70. if ( ! timeControl) {
  71. timeControl = setInterval ( function () {
  72. waitForKeyElements ( selectorTxt,
  73. actionFunction,
  74. bWaitOnce,
  75. iframeSelector
  76. );
  77. },
  78. 300
  79. );
  80. controlObj [controlKey] = timeControl;
  81. }
  82. }
  83. waitForKeyElements.controlObj = controlObj;
  84. }
  85.  
  86. waitForKeyElements (
  87. "div.like-and-dislike"
  88. , commentCallbackFunction
  89. );
  90.  
  91. //--- Page-specific function to do what we want when the node is found.
  92. function commentCallbackFunction (jNode) {
  93.  
  94. $('div.content-wrapper > div.navbar').remove();
  95.  
  96. var diff = $('#desktop-side-bar div ul.side-bar-list li:nth-child(2) span:nth-child(2)').text();
  97. $('.question-title h3').text($('.question-title h3').text() + ' (' + diff + ')');
  98.  
  99. $('head title').text($('.question-title h3').text().trim().replace('.', ''));
  100. $('div.like-and-dislike').parent().remove();
  101. $('nav.tab-view').parent().remove();
  102. $('div.action-btn-base').remove();
  103. $('div#interviewed-div').remove();
  104. $('div.question-detail-bottom').parent().remove();
  105. $('div.notepad-wrapper').remove();
  106. $('div#notepad-container').remove();
  107. $('div#lc_navbar_placeholder').remove();
  108. $('#supportModal').remove();
  109. $('div.CreateModal-base').remove();
  110. $('#lc-alert-container').remove();
  111. $('.showspoilers').remove();
  112. $('#MathJax_Message').remove();
  113.  
  114.  
  115. if ($('#tags-company a')) {
  116. $('#tags-company').html('Companies: ' + $('#tags-company').html());
  117. $('.question-panel').append($('#tags-company'));
  118. }
  119. if ($('#tags-topic a')) {
  120. $('#tags-topics').html('Topics: ' + $('#tags-topics').html());
  121. $('.question-panel').append($('#tags-topics'));
  122. }
  123. if ($('#tags-question a')) {
  124. $('#tags-question').html('Similar Questions: ' + $('#tags-question').html());
  125. $('.question-panel').append($('#tags-question'));
  126. }
  127. $('footer').remove();
  128. $('#desktop-side-bar').remove();
  129.  
  130. $('body').css('font-size', '24px');
  131. $('body').css('line-height', '24px');
  132. $('.question-title').css('margin-top', '2px');
  133. $('.spoilers').css('display', '');
  134. $('pre').css('font-size', '24px');
  135. $('pre').css('white-space', 'pre-wrap');
  136. $('a.btn-primary').css('font-size', '18px');
  137. $('div.question-title h3').css('font-size', '32px');
  138. $('p').css('margin-bottom', '20px');
  139. $('p').css('margin-top', '20px');
  140. $('div.content-wrapper').css('padding-bottom', '0px');
  141.  
  142. $('div a').removeClass('text-sm btn-xs label text-sm label-M label-E');
  143. $('#tags-company a').addClass('text-lg');
  144. $('#tags-topics a').addClass('text-lg');
  145. $('div a').removeClass('round');
  146. $('#tags-question a').addClass('text-lg btn btn-default btn-round text-lg');
  147. $('div > a').removeAttr("href");
  148.  
  149. $('a').removeClass("label-Easy");
  150. $('a').removeClass("label-Medium");
  151. $('a').removeClass("label-Hard");
  152.  
  153. $('div#tags-company, div#tags-topics, div#tags-question').css('font-size', '14px');
  154. $('div a.btn').removeClass('sidebar-tag text-lg');
  155.  
  156. };