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. function resizeAllCorrectionsWindow(){
  12. var allCorrectionsParent = document.getElementById("allCorrectionsPanel_c");
  13. var allCorrections = document.getElementById("allCorrectionsPanel");
  14. var heightBox = allCorrections.getElementsByClassName("bd")[0];
  15. if (allCorrectionsParent){
  16. //Resize the window
  17. var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  18. var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
  19. allCorrections.style.width = w/2 + "px";
  20. heightBox.style.height = h/2 + "px";
  21. //ReCenter it
  22. allCorrectionsParent.style.left = "24.7%";
  23. allCorrectionsParent.style.top = "25%" + document.documentElement.scrollTop + "px" ;
  24. }
  25. }
  26.  
  27. window.onresize = resizeAllCorrectionsWindow;
  28.  
  29.  
  30. document.getElementById("showAll").onclick = function showallexecuteLineThroughRemoval() {
  31. var allCorrectionsParent = document.getElementById("allCorrectionsPanel_c");
  32. var allCorrections = document.getElementById("allCorrectionsPanel");
  33. var heightBox = allCorrections.getElementsByClassName("bd")[0];
  34. resizeAllCorrectionsWindow();
  35. //Remove "All Corrections" line-through
  36. var b = allCorrections.getElementsByTagName("span");
  37. for (i = 0; i < b.length; ++i) {
  38. if (b[i].style.textDecorationLine){
  39. b[i].innerHTML = "";
  40. }
  41. }
  42. //Remove duplicate non-corrected lines from our entry, for further readability and less confusion
  43. //Hacked-in absurdly as Lang-8's developers didn't correctly use tags around our written text, and corrections.
  44. var bc = allCorrections.textContent;
  45. var bd = allCorrections.getElementsByClassName("correct");
  46. for (i = 0; i < bd.length; ++i) {
  47. var re = new RegExp(bd[i].textContent, 'g');
  48. var matchCount = bc.match(re).length;
  49. if (matchCount >= 2){
  50. console.log(matchCount +" Diff is: "+bd[i].textContent);
  51. bd[i].textContent = "-";
  52. }
  53. }
  54. //Remove default NoCorrectionNecessary message
  55. var c = allCorrections.getElementsByClassName("corrected perfect");
  56. for (i = 0; i < c.length; ++i) {
  57. c[i].innerHTML = "";
  58. }
  59. //Reinsert comment image next to comments since they don't always have one
  60. var d = allCorrections.getElementsByClassName("correction_comment");
  61. for (i = 0; i < d.length; ++i) {
  62. d[i].innerHTML = '<img alt="Comment" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAANlBMVEV9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX3AS/7wAAAAEXRSTlMACTReYWJmdpaf7e7v8PHy93y2WnUAAAA2SURBVHjancc3DgAgEMTAJeew//8sFKcTNVPZ8IOiO1SqBj6+ZlBNhEWxPK5MFgORd4RKVuIAotwHM1W7LmAAAAAASUVORK5CYII" />' + " " + d[i].innerHTML + "<br />";
  63. d[i].className = '';
  64. }
  65. //Remove empty 'correct' fields
  66. var e = allCorrections.getElementsByClassName("correct");
  67. for (i = 0; i < e.length; ++i) {
  68. if (e[i].textContent == ''){
  69. e[i].className = '';
  70. }
  71. }
  72. //Remove some unnecessary spacing
  73. var toRep = heightBox.innerHTML;
  74. var toRepB = toRep.replace(/<br>/g, "");
  75. var toRepC = toRepB.replace(/<p><\/p>/g, "");
  76. var toRepD = toRepC.replace(/<li class="corrected perfect"><\/li>/g, "");
  77. var toRepE = toRepD.replace("Title", "Title<br>");
  78. var toRepF = toRepE.replace("Main Body", "Main Body<br>");
  79. heightBox.innerHTML = toRepF;
  80. //Break up our corrections with a background
  81. var bb = allCorrections.getElementsByClassName("correction_field");
  82. for (i = 0; i < bb.length; ++i) {
  83. bb[i].style.backgroundColor = "#E5E5E5"
  84. }
  85. };
  86.  
  87. window.onload = function onloadexecuteLineThroughRemoval(){
  88. //Remove correction posts' themselves' line-through
  89. var a = document.getElementsByClassName("sline");
  90. for (i = 0; i < a.length; ++i) {
  91. a[i].innerHTML='';
  92. }
  93. }