kickjava enhancer

Hide line numbers, make it easy to copy source code form kickjava.com

  1. // ==UserScript==
  2. // @name kickjava enhancer
  3. // @namespace kickjava enhancer
  4. // @include http://kickjava.com/*.java
  5. // @include http://kickjava.com/*.java.htm
  6. // @version 1.1
  7. // @grant none
  8. // @description Hide line numbers, make it easy to copy source code form kickjava.com
  9. // ==/UserScript==
  10.  
  11. function getCookie(c_name) {
  12. if (document.cookie.length > 0) {
  13. c_start = document.cookie.indexOf(c_name + "=");
  14. if (c_start != -1) {
  15. c_start = c_start + c_name.length + 1 ;
  16. c_end = document.cookie.indexOf(";", c_start);
  17. if (c_end == -1) {
  18. c_end = document.cookie.length;
  19. }
  20. return unescape(document.cookie.substring(c_start, c_end));
  21. }
  22. }
  23. return "";
  24. }
  25.  
  26. function setCookie (c_name, value, expiresecs) {
  27. var exdate = new Date();
  28. exdate.setSeconds(exdate.getSeconds() + expiresecs);
  29. document.cookie = c_name + "=" + escape(value) + ((expiresecs == null) ? "" : ";expires=" + exdate.toGMTString());
  30. }
  31.  
  32. //Append a tool bar contentColumn0
  33. var contentColumn = document.getElementById("contentColumn");
  34. var contentColumn0 = document.createElement("div");
  35. var contentHeading1 = document.getElementById("contentHeading1");
  36. contentColumn.insertBefore(contentColumn0, contentHeading1);
  37. contentColumn0.style.marginTop = "10px";
  38. contentColumn0.style.backgroundColor = "#DDCC88";
  39. contentColumn0.style.padding = "12px 20px";
  40. var buttonLineNum = document.createElement("input");
  41. buttonLineNum.setAttribute("type","button");
  42. buttonLineNum.setAttribute("id","button-LN");
  43. contentColumn0.appendChild(buttonLineNum);
  44. buttonLineNumStyle = document.createElement("style");
  45. document.body.appendChild(buttonLineNumStyle);
  46. buttonLineNumStyle.innerHTML = "#button-LN\n" +
  47. "{\n" +
  48. "\twidth: 180px;\n" +
  49. "\theight: 26px;\n" +
  50. "\tbackground-color: #EAEAEA;\n" +
  51. "\tbackground-image: linear-gradient(#FAFAFA, #EAEAEA);\n" +
  52. "\tbackground-image: -moz-linear-gradient(#fafafa, #eaeaea);\n" +
  53. "\tbackground-image: -webkit-linear-gradient(#fafafa, #eaeaea);\n" +
  54. "\tbackground-repeat: repeat-x;\n" +
  55. "\tborder-color: #DDDDDD #DDDDDD #C5C5C5;\n" +
  56. "\tborder-radius: 5px;\n" +
  57. "\tborder-style: solid;\n" +
  58. "\tborder-width: 1px;\n" +
  59. "\tbox-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);\n" +
  60. "\tcolor: #333333;\n" +
  61. "\tfont-weight: bold;\n" +
  62. "\ttext-align: center;\n" +
  63. "\tvertical-align: middle;\n" +
  64. "\ttext-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);\n" +
  65. "}\n" +
  66. "#button-LN:hover, #button-LN:active\n" +
  67. "{\n" +
  68. "\tcursor: pointer;\n" +
  69. "\tbackground-color: #dadada;\n" +
  70. "\tbackground-image: -moz-linear-gradient(#fafafa, #dadada);\n" +
  71. "\tbackground-image: -webkit-linear-gradient(#fafafa, #dadada);\n" +
  72. "\tbackground-image: linear-gradient(#fafafa, #dadada);\n" +
  73. "\tborder-color: #ccc #ccc #b5b5b5;\n" +
  74. "}\n" +
  75. "#button-LN:focus\n" +
  76. "{\n" +
  77. "\toutline: none;\n" +
  78. "\tborder-color: #CC9933;\n" +
  79. "\tborder-style: solid;\n" +
  80. "\tbox-shadow: 0 0 5px rgba(192, 96, 0,0.5);\n" +
  81. "}\n" +
  82. "#button-LN::-moz-focus-inner\n" +
  83. "{\n" +
  84. "\toutline: none;\n" +
  85. "\tborder-color:transparent;\n" +
  86. "}\n";
  87.  
  88. //Copy to clipboard
  89. function setClipBoard(s) {
  90. if (window.clipboardData) { //IE
  91. window.clipboardData.setData("Text", s);
  92. } else {
  93. alert("This utility is only for IE");
  94. }
  95. }
  96.  
  97. function hideLineNum() {
  98. tags = document.getElementsByTagName("font");
  99. for (var i = 0; i < tags.length; i++) {
  100. if (tags[i].id == "LN") {
  101. tags[i].style.display = "none";
  102. }
  103. }
  104. buttonLineNum.onclick = showLineNum;
  105. buttonLineNum.value = "show line numbers";
  106. setCookie("line-number-display", "hidden");
  107. }
  108.  
  109. function showLineNum() {
  110. tags = document.getElementsByTagName("font");
  111. for (var i = 0; i < tags.length; i++) {
  112. if (tags[i].id == "LN") {
  113. tags[i].style.display = "inline";
  114. }
  115. }
  116. buttonLineNum.onclick = hideLineNum;
  117. buttonLineNum.value = "hide line numbers";
  118. setCookie("line-number-display", "onshow");
  119. }
  120.  
  121. if (getCookie("line-number-display") == "onshow") {
  122. showLineNum();
  123. } else {
  124. hideLineNum();
  125. }