Lang-8 - "All Corrections" View Enhancer

Easier to read and view corrections in the "All Corrections" view. - https://greasyfork.org/en/users/3656-kaiko

当前为 2015-07-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Lang-8 - "All Corrections" View Enhancer
  3. // @namespace Lang8LTR
  4. // @description Easier to read and view corrections in the "All Corrections" view. - https://greasyfork.org/en/users/3656-kaiko
  5. // @include http://lang-8.com/*/journals/*
  6. // @include https://lang-8.com/*/journals/*
  7. // @version 1
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /*
  12. Remove strike-through text on corrections, "All Corrections" view and default.
  13. All Corrections View:
  14. Expands the view more dynamically for larger displays.
  15. Removes "No correction needed" green text messages.
  16. Re-injects the comment icon for comments, as they didn't always appear.
  17. Absurd hacked in feature: Removes corrections that are the same as your entry's sentence (May remove duplicate corrections that appear the same...(To be fixed))
  18. Removes empty 'correct' fields that overlap their icons and spacing.
  19. Removes unnecessary and large spacing between corrections.
  20. Inserts a grey background for corrections to differentiate them from your written entry.
  21. */
  22.  
  23. function resizeAllCorrectionsWindow(){
  24. var allCorrectionsParent = document.getElementById("allCorrectionsPanel_c");
  25. var allCorrections = document.getElementById("allCorrectionsPanel");
  26. var heightBox = allCorrections.getElementsByClassName("bd")[0];
  27. if (allCorrectionsParent){
  28. //Resize the window
  29. var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  30. var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
  31. allCorrections.style.width = w/1.5 + "px";
  32. heightBox.style.height = h/1.5 + "px";
  33. //ReCenter it
  34. allCorrectionsParent.style.left = "16.5%";
  35. allCorrectionsParent.style.top = parseFloat("100%") + document.documentElement.scrollTop + "px";
  36. }
  37. }
  38.  
  39. window.onresize = resizeAllCorrectionsWindow;
  40.  
  41. document.getElementById("showAll").onclick = function showallexecuteLineThroughRemoval() {
  42. var allCorrectionsParent = document.getElementById("allCorrectionsPanel_c");
  43. var allCorrections = document.getElementById("allCorrectionsPanel");
  44. var heightBox = allCorrections.getElementsByClassName("bd")[0];
  45. resizeAllCorrectionsWindow();
  46. //Remove "All Corrections" line-through
  47. var b = allCorrections.getElementsByTagName("span");
  48. for (i = 0; i < b.length; ++i) {
  49. if (b[i].style.textDecorationLine){
  50. b[i].innerHTML = "";
  51. }
  52. }
  53. //Remove duplicate non-corrected lines from our entry, for further readability and less confusion
  54. //Hacked-in absurdly as Lang-8's developers didn't correctly use tags around our written text, and corrections.
  55. //TODO: Sanity check for whether we have more than one match in corrections, and if that increases +1 compared to innerHTML, to then safely remove them.
  56. var bc = allCorrections.textContent;
  57. var bd = allCorrections.getElementsByClassName("correct");
  58. for (i = 0; i < bd.length; ++i) {
  59. var re = new RegExp(bd[i].textContent, 'g');
  60. var matchCount = bc.match(re).length;
  61. if (matchCount >= 2){
  62. console.log(matchCount +" Diff is: "+bd[i].textContent);
  63. bd[i].textContent = "-";
  64. }
  65. }
  66. //Remove default NoCorrectionNecessary message
  67. var c = allCorrections.getElementsByClassName("corrected perfect");
  68. for (i = 0; i < c.length; ++i) {
  69. c[i].innerHTML = "";
  70. }
  71. //Reinsert comment image next to comments since they don't always have one
  72. var d = allCorrections.getElementsByClassName("correction_comment");
  73. for (i = 0; i < d.length; ++i) {
  74. d[i].innerHTML = '<img alt="Comment" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAANlBMVEV9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX3AS/7wAAAAEXRSTlMACTReYWJmdpaf7e7v8PHy93y2WnUAAAA2SURBVHjancc3DgAgEMTAJeew//8sFKcTNVPZ8IOiO1SqBj6+ZlBNhEWxPK5MFgORd4RKVuIAotwHM1W7LmAAAAAASUVORK5CYII" />' + " " + d[i].innerHTML + "<br />";
  75. d[i].className = '';
  76. }
  77. //Remove empty 'correct' fields
  78. var e = allCorrections.getElementsByClassName("correct");
  79. for (i = 0; i < e.length; ++i) {
  80. if (e[i].textContent == ''){
  81. e[i].className = '';
  82. }
  83. }
  84. //Remove some unnecessary spacing
  85. var toRep = heightBox.innerHTML;
  86. var toRepB = toRep.replace(/<br>/g, "");
  87. var toRepC = toRepB.replace(/<p><\/p>/g, "");
  88. var toRepD = toRepC.replace(/<li class="corrected perfect"><\/li>/g, "");
  89. var toRepE = toRepD.replace("Title", "Title<br>");
  90. var toRepF = toRepE.replace("Main Body", "Main Body<br>");
  91. heightBox.innerHTML = toRepF;
  92. //Break up our corrections with a background
  93. var bb = allCorrections.getElementsByClassName("correction_field");
  94. for (i = 0; i < bb.length; ++i) {
  95. bb[i].style.backgroundColor = "#E5E5E5"
  96. }
  97. };
  98.  
  99. window.onload = function onloadexecuteLineThroughRemoval(){
  100. //Remove correction posts' themselves' line-through
  101. var a = document.getElementsByClassName("sline");
  102. for (i = 0; i < a.length; ++i) {
  103. a[i].innerHTML='';
  104. }
  105. }