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 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Lang-8 - "All Corrections" View Enhancer
// @namespace   Lang8LTR
// @description	Easier to read and view corrections in the "All Corrections" view. - https://greasyfork.org/en/users/3656-kaiko
// @include     http://lang-8.com/*/journals/*
// @include     https://lang-8.com/*/journals/*
// @version     1
// @grant       none
// ==/UserScript==

function resizeAllCorrectionsWindow(){
	var allCorrectionsParent = document.getElementById("allCorrectionsPanel_c");
	var allCorrections = document.getElementById("allCorrectionsPanel");
	var heightBox = allCorrections.getElementsByClassName("bd")[0];
	if (allCorrectionsParent){
		//Resize the window
		allCorrections.style.width = window.innerWidth/1.5 + "px";
		heightBox.style.height = window.innerHeight/1.5 + "px";
		//ReCenter it
		allCorrectionsParent.style.left = window.innerWidth/6.2 + "px";
		allCorrectionsParent.style.top = window.innerHeight/7 + document.documentElement.scrollTop + "px";
	}
}

window.onresize = resizeAllCorrectionsWindow;


document.getElementById("showAll").onclick = function showallexecuteLineThroughRemoval() {
	var allCorrectionsParent = document.getElementById("allCorrectionsPanel_c");
	var allCorrections = document.getElementById("allCorrectionsPanel");
	var heightBox = allCorrections.getElementsByClassName("bd")[0];
	resizeAllCorrectionsWindow();
	
	//Remove "All Corrections" line-through
	var b = allCorrections.getElementsByTagName("span");
	for (i = 0; i < b.length; ++i) {
		if (b[i].style.textDecorationLine){
			b[i].innerHTML = "";
		}
	}
	//Remove duplicate non-corrected lines from our entry, for further readability and less confusion
	//Hacked-in absurdly as Lang-8's developers didn't correctly use tags around our written text, and corrections.
	var bc = allCorrections.textContent;
	var bd = allCorrections.getElementsByClassName("correct");
	for (i = 0; i < bd.length; ++i) {
		var re = new RegExp(bd[i].textContent, 'g');
		var matchCount  = bc.match(re).length;
		if (matchCount >= 2){
			console.log(matchCount +"	Diff is:	"+bd[i].textContent);
			bd[i].textContent = "-";
		}
	}
	//Remove default NoCorrectionNecessary message
	var c = allCorrections.getElementsByClassName("corrected perfect");
	for (i = 0; i < c.length; ++i) {
		c[i].innerHTML = "";
	}
	//Reinsert comment image next to comments since they don't always have one
	var d = allCorrections.getElementsByClassName("correction_comment");
	for (i = 0; i < d.length; ++i) {
		d[i].innerHTML = '<img alt="Comment" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAMAAABhq6zVAAAANlBMVEV9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX3AS/7wAAAAEXRSTlMACTReYWJmdpaf7e7v8PHy93y2WnUAAAA2SURBVHjancc3DgAgEMTAJeew//8sFKcTNVPZ8IOiO1SqBj6+ZlBNhEWxPK5MFgORd4RKVuIAotwHM1W7LmAAAAAASUVORK5CYII" />' + " " + d[i].innerHTML + "<br />";
		d[i].className = '';
	}
	//Remove empty 'correct' fields
	var e = allCorrections.getElementsByClassName("correct");
	for (i = 0; i < e.length; ++i) {
		if (e[i].textContent == ''){
			e[i].className = '';
		}
	}
	//Remove some unnecessary spacing
	var toRep = heightBox.innerHTML;
	var toRepB = toRep.replace(/<br>/g, "");
	var toRepC = toRepB.replace(/<p><\/p>/g, "");
	var toRepD = toRepC.replace(/<li class="corrected perfect"><\/li>/g, "");
	var toRepE = toRepD.replace("Title", "Title<br>");
	var toRepF = toRepE.replace("Main Body", "Main Body<br>");
	heightBox.innerHTML = toRepF;
	//Break up our corrections with a background
	var bb = allCorrections.getElementsByClassName("correction_field");
	for (i = 0; i < bb.length; ++i) {
		bb[i].style.backgroundColor = "#E5E5E5"
	}
};

window.onload = function onloadexecuteLineThroughRemoval(){
	//Remove correction posts' themselves' line-through
	var a = document.getElementsByClassName("sline");
	for (i = 0; i < a.length; ++i) {
		a[i].innerHTML='';
	}
}