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