Commit 3f5d46aa authored by Pierre M's avatar Pierre M
Browse files

factorize code


Signed-off-by: Pierre M's avatarPierre Mazière <pierre.maziere@gmx.com>
parent ad183e9e
......@@ -313,90 +313,65 @@
return false;
}
let articles = document.getElementsByTagName('article');
for (let i = 0; i < articles.length; i++) {
let userLink = articles[i].getElementsByClassName('meta').item(0).getElementsByTagName('a').item(0);
let span = document.createElement("span");
let sup = document.createElement("sup");
let a = document.createElement("a");
let txt = document.createTextNode(" Plonk");
a.appendChild(txt);
a.addEventListener("click",function(){
addToPlonkList(userLink.href.match(userRE)[1],userLink.textContent);
},true);
a.href = "#";
sup.appendChild(a);
span.appendChild(sup);
userLink.parentNode.insertBefore(span,userLink.nextSibling);
if(plonkClosedAccounts){
GM_xmlhttpRequest({
method: "GET",
url: userLink.href,
context: articles[i],
onload: function(response) {
if(response.responseText.match(/Compte fermé/)){
response.context.style.display = "none";
if(unlistClosedAccounts){
let userLink =response.context.getElementsByClassName('meta').item(0).getElementsByTagName('a').item(0);
let user= userLink.href.match(userRE);
if(plonkList.hasOwnProperty(user)){
delete plonkList[user];
GM_setValue("plonkList",JSON.stringify(plonkList));
}
}
}
}
});
function plonkContents(type){
let contents;
switch(type){
case 'article': contents = document.getElementsByTagName(type); break;
case 'comment': contents = document.getElementsByClassName(type); break;
}
for(let u in plonkList){
if (userLink.href === "https://linuxfr.org/users/"+u && plonkList[u][0]){
articles[i].style.display = "none";
break;
}
}
}
let comments = document.getElementsByClassName('comment');
for (let i = 0; i < comments.length; i++) {
let userLink = comments[i].getElementsByClassName('meta').item(0).getElementsByTagName('a').item(0);
let span = document.createElement("span");
let sup = document.createElement("sup");
let a = document.createElement("a");
let txt = document.createTextNode(" Plonk");
a.appendChild(txt);
a.addEventListener("click",function(){
addToPlonkList(userLink.href.match(userRE)[1],userLink.textContent);
},true);
a.href = "#";
sup.appendChild(a);
span.appendChild(sup);
userLink.parentNode.insertBefore(span,userLink.nextSibling);
if(plonkClosedAccounts){
GM_xmlhttpRequest({
method: "GET",
url: userLink.href,
context: comments[i],
onload: function(response) {
if(response.responseText.match(/Compte fermé/)){
response.context.style.display = "none";
if(unlistClosedAccounts){
let userLink =response.context.getElementsByClassName('meta').item(0).getElementsByTagName('a').item(0);
let user= userLink.href.match(userRE);
if(plonkList.hasOwnProperty(user)){
delete plonkList[user];
GM_setValue("plonkList",JSON.stringify(plonkList));
for (let i = 0; i < contents.length; i++) {
let userLink = contents[i].getElementsByClassName('meta').item(0).getElementsByTagName('a').item(0);
let span = document.createElement("span");
let sup = document.createElement("sup");
let a = document.createElement("a");
let txt = document.createTextNode(" Plonk");
a.appendChild(txt);
a.addEventListener("click",
addToPlonkList.bind(null,userLink.href.match(userRE)[1],userLink.textContent),
true);
a.href = "#";
sup.appendChild(a);
span.appendChild(sup);
userLink.parentNode.insertBefore(span,userLink.nextSibling);
if(plonkClosedAccounts){
GM_xmlhttpRequest({
method: "GET",
url: userLink.href,
context: contents[i],
onload: function(response) {
if(response.responseText.match(/Compte fermé/)){
response.context.style.display = "none";
if(unlistClosedAccounts){
let userLink =response.context.getElementsByClassName('meta').item(0).getElementsByTagName('a').item(0);
let user= userLink.href.match(userRE);
if(plonkList.hasOwnProperty(user)){
delete plonkList[user];
GM_setValue("plonkList",JSON.stringify(plonkList));
}
}
}
}
}
});
}
for(let u in plonkList){
if (userLink.href === "https://linuxfr.org/users/"+u && plonkList[u][1]){
comments[i].style.display = "none";
break;
});
}
for(let u in plonkList){
if (userLink.href !== "https://linuxfr.org/users/"+u){
continue;
}
let plonk = false;
switch(type){
case 'article': if (plonkList[u][0]){plonk=true;} break;
case 'comment': if (plonkList[u][1]){plonk=true;} break;
}
if(plonk){
contents[i].style.display = "none";
break;
}
}
}
}
plonkContents('article');
plonkContents('comment');
})();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment