Commit 7e6de67a authored by Pierre M's avatar Pierre M
Browse files

deal nicely with user aliases


Signed-off-by: Pierre M's avatarPierre Mazière <pierre.maziere@gmx.com>
parent 8e9b05e6
......@@ -20,8 +20,8 @@
(function() {
let userRE = new RegExp("https://linuxfr.org/users/(.*)$");
let types = {
article: 0,
comment: 1
article: 1,
comment: 2
}
let plonkList = JSON.parse(GM_getValue("plonkList","[]"));
......@@ -37,7 +37,7 @@
// check for pre-hash configuration data
if(Array.isArray(plonkList)){
plonkList = plonkList.reduce(function(obj,user,index){
obj[user]=[true,true];
obj[user]=['',true,true];
return obj;
},{});
}else{
......@@ -45,6 +45,7 @@
plonkList = Object.keys(plonkList).reduce(function(obj,user,index){
switch(plonkList[user].length){
case 1: obj[user]=[plonkList[user][0],true]; break;
case 2: obj[user]=['',plonkList[user][0],plonkList[1]]; break;
default: obj[user]=plonkList[user];break;
}
return obj;
......@@ -132,7 +133,7 @@
let button = document.createElement("button");
button.setAttribute("id","plonkAdd");
button.appendChild(document.createTextNode("Ajouter '"+user+"'"));
if( user !== alias ){
if( user !== alias.toLowerCase() ){
button.appendChild(document.createTextNode("' alias '"+alias+"'"));
}
button.addEventListener("click",plonk.bind(null,user,alias),true);
......@@ -201,6 +202,10 @@
label = document.createElement("label");
label.setAttribute("for","user_"+u);
label.appendChild(document.createTextNode(u));
if(plonkList[u][0] !== ''){
label.appendChild(document.createElement("br"));
label.appendChild(document.createTextNode("["+plonkList[u][0]+"]"));
}
col.appendChild(label);
row.appendChild(col);
......@@ -266,7 +271,10 @@
}
function plonk(user,alias){
plonkList[user] = [true,true];
if(user === alias.toLowerCase()){
alias = '';
}
plonkList[user] = [alias,true,true];
GM_setValue("plonkList",JSON.stringify(plonkList));
let form = document.getElementById("plonkForm");
form.remove();
......@@ -354,15 +362,23 @@
}
});
}
let alteredList = false;
for(let u in plonkList){
if (userLink.href !== "https://linuxfr.org/users/"+u){
continue;
}
if (userLink.textContent.toLowerCase() !== u && userLink.textContent !== plonkList[u][0] ){
plonkList[u][0] = userLink.textContent;
alteredList = true;
}
if(plonkList[u][types[type]]){
contents[i].style.display = "none";
break;
}
}
if(alteredList){
GM_setValue("plonkList",JSON.stringify(plonkList));
}
}
}
......
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