Lang-8 - "All Corrections" View Enhancer

Easier to read and view corrections in the "All Corrections" viewer, especially for Japanese.

  1. // ==UserScript==
  2. // @name Lang-8 - "All Corrections" View Enhancer
  3. // @description Easier to read and view corrections in the "All Corrections" viewer, especially for Japanese.
  4. // @author Kai Krause (kaikrause95@gmail.com)
  5. // @match http://lang-8.com/*/journals/*
  6. // @match https://lang-8.com/*/journals/*
  7. // @version 1.4
  8. // @grant none
  9. // @namespace Lang8LTR
  10. // ==/UserScript==
  11.  
  12. /*
  13. Remove strike-through text on corrections, "All Corrections" view and default.
  14. All Corrections View:
  15. Expands the view more dynamically for larger displays.
  16. Removes "No correction needed" green text messages.
  17. Re-injects the comment icon for comments, as they didn't always appear.
  18. Absurd hacked in feature: Removes corrections that are the same as your entry's sentence, but not duplicates of the same correction from others)
  19. Removes empty 'correct' fields that overlap their icons and spacing.
  20. Removes unnecessary and large spacing between corrections.
  21. Inserts a grey background for corrections to differentiate them from your written entry.
  22. */
  23.  
  24. var pong = false;
  25.  
  26. function resizeAllCorrectionsWindow(){
  27. var allCorrectionsParent = document.getElementById("allCorrectionsPanel_c");
  28. var allCorrections = document.getElementById("allCorrectionsPanel");
  29. var heightBox = allCorrections.getElementsByClassName("bd")[0];
  30. if (allCorrectionsParent){
  31. //Resize the window
  32. var w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],screenWidth=w.innerWidth||e.clientWidth||g.clientWidth,screenHeight=w.innerHeight||e.clientHeight||g.clientHeight;
  33. var DPR = window.devicePixelRatio; //Credit to https://stackoverflow.com/a/21737839
  34. if (DPR <= 0.6){
  35. zoomLevel = 2.4;
  36. } else if (DPR <= 0.8){
  37. zoomLevel = 2.2;
  38. } else if (DPR <= 1.0){
  39. zoomLevel = 2.0;
  40. } else if (DPR <= 1.21){
  41. zoomLevel = 1.8;
  42. } else if (DPR <= 1.34){
  43. zoomLevel = 1.6;
  44. } else if (DPR <= 2.0){
  45. zoomLevel = 1.5;
  46. } else {
  47. zoomLevel = 2.0;
  48. }
  49.  
  50. //Apply our size
  51. allCorrections.style.width = screenWidth/zoomLevel + "px";
  52. heightBox.style.height = screenHeight/zoomLevel + "px";
  53. //ReCenter it
  54. var vertScroll = window.pageYOffset || document.documentElement.scrollTop;
  55. if (!pong){
  56. window.scrollBy(0, 2);
  57. pong = true;
  58. }
  59. else if (pong) {
  60. window.scrollBy(0, -2);
  61. pong = false;
  62. }
  63. }
  64. }
  65.  
  66. window.onresize = resizeAllCorrectionsWindow;
  67.  
  68. document.getElementById("showAll").onclick = function showallexecuteLineThroughRemoval() {
  69. resizeAllCorrectionsWindow();
  70. var allCorrectionsParent = document.getElementById("allCorrectionsPanel_c");
  71. var allCorrections = document.getElementById("allCorrectionsPanel");
  72. var heightBox = allCorrections.getElementsByClassName("bd")[0];
  73. //Remove "All Corrections" line-through
  74. var b = allCorrections.getElementsByTagName("span");
  75. for (i = 0; i < b.length; ++i) {
  76. if (b[i].style.textDecorationLine){
  77. b[i].innerHTML = "";
  78. }
  79. }
  80. //Remove duplicate non-corrected lines from our entry, for further readability and less confusion
  81. //Hacked-in absurdly as Lang-8's developers didn't correctly use tags around our written text, and corrections.
  82. var bc = allCorrections.textContent;
  83. var bd = allCorrections.getElementsByClassName("correct");
  84. //Convert our HTMLCollection content to an array
  85. var arr = [];
  86. for (i = 0; i < bd.length; ++i){
  87. //Make sure to get the first element, which is our correction and not the comment with it
  88. arr.push(bd[i].getElementsByTagName('p')[0].textContent);
  89. }
  90. //Sort it
  91. var sortedArr = arr.sort();
  92. var tempMatchObj = {};
  93. var tempMatches = 0;
  94. //Find duplicates and add it to a key:value object, along with an int of how many of that duplicate we had
  95. for (i = 0; i < sortedArr.length; ++i){
  96. if (sortedArr[i] === sortedArr[i+1]){
  97. tempMatches+=1;
  98. tempMatchObj[sortedArr[i]] = tempMatches;
  99. }
  100. else if (sortedArr[i] != sortedArr[i-1]){
  101. tempMatches = 1;
  102. tempMatchObj[sortedArr[i]] = tempMatches;
  103. }
  104. }
  105. //Check this int of duplicate matches against the entirety of the html content
  106. //If we have more matches of the same than our corrections did, then remove the correction as that's the same sentence written by the author
  107. //Else, keep the correction since more than one corrector has corrected the same mistakes in the same way, creating a duplicate - which we keep for sanity.
  108. for(key in tempMatchObj) {
  109. if(tempMatchObj.hasOwnProperty(key)) {
  110. var innerValue = tempMatchObj[key];
  111. var escapedKey = key.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); // Credit to https://stackoverflow.com/a/6318729
  112. var toMatch = new RegExp(escapedKey, 'g');
  113. var outerValue = (bc.match(toMatch)||[]).length;
  114. //console.log(key + " " + "InnerValue is: " + innerValue + " " + "OuterValue is: " + outerValue);
  115. if (outerValue > innerValue){
  116. for (i = 0; i < bd.length; ++i) {
  117. if (bd[i].textContent == key){
  118. bd[i].textContent = "-";
  119. }
  120. }
  121. }
  122. }
  123. }
  124. //Remove default NoCorrectionNecessary message
  125. var c = allCorrections.getElementsByClassName("corrected perfect");
  126. for (i = 0; i < c.length; ++i) {
  127. c[i].innerHTML = "";
  128. }
  129. //Remove empty 'correct' fields
  130. var e = allCorrections.getElementsByClassName("correct");
  131. for (i = 0; i < e.length; ++i) {
  132. if (e[i].textContent == ''){
  133. e[i].className = '';
  134. }
  135. }
  136. //Reinsert comment image next to comments since they don't always have one
  137. var d = allCorrections.getElementsByClassName("correction_comment");
  138. for (var i = d.length; i--;) {
  139. d[i].innerHTML = '&emsp;&emsp;<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAANlBMVEV9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX3AS/7wAAAAEXRSTlMACTReYWJmdpaf7e7v8PHy93y2WnUAAAA2SURBVHjancc3DgAgEMTAJeew//8sFKcTNVPZ8IOiO1SqBj6+ZlBNhEWxPK5MFgORd4RKVuIAotwHM1W7LmAAAAAASUVORK5CYII" />' + '&nbsp;' + d[i].innerHTML + '<br />';
  140. d[i].style.backgroundColor = "#E5E5E5";
  141. d[i].className = " ";
  142. d = allCorrections.getElementsByClassName("correction_comment");
  143. }
  144. //Remove some unnecessary spacing
  145. var toRep = heightBox.innerHTML;
  146. var toRepB = toRep.replace(/<br>/g, "");
  147. var toRepC = toRepB.replace(/<p><\/p>/g, "");
  148. var toRepD = toRepC.replace(/<li class="corrected perfect"><\/li>/g, "");
  149. var toRepE = toRepD.replace("Title", "Title<br>");
  150. var toRepF = toRepE.replace("Main Body", "Main Body<br>");
  151. heightBox.innerHTML = toRepF;
  152. //Break up our corrections with a background
  153. var bb = allCorrections.getElementsByClassName("correction_field");
  154. for (i = 0; i < bb.length; ++i) {
  155. bb[i].style.backgroundColor = "#E5E5E5"
  156. }
  157. };
  158.  
  159. window.onload = function onloadexecuteLineThroughRemoval(){
  160. //Remove correction posts' themselves' line-through
  161. var a = document.getElementsByClassName("sline");
  162. for (i = 0; i < a.length; ++i) {
  163. a[i].innerHTML='';
  164. }
  165. }

QingJ © 2025

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