Commit 1c5678b8 authored by Pierre M's avatar Pierre M
Browse files

enable plonked user specific options


Signed-off-by: Pierre M's avatarPierre Mazière <pierre.maziere@gmx.com>
parent f1a801ea
......@@ -21,16 +21,25 @@
let userRE = new RegExp("https://linuxfr.org/users/(.*)$");
let plonkList = JSON.parse(GM_getValue("plonkList","[]"));
// check for pre-JSON configuration data
if(!Array.isArray(plonkList)){
if(typeof plonkList === "string"){
plonkList = plonkList.split(',');
if(plonkList.length === 1 && plonkList[0] === ""){
plonkList = [];
}
}else{
plonkList = [];
switch(typeof plonkList){
case "string":
// check for pre-JSON configuration data
plonkList = plonkList.split(',');
if(plonkList.length === 1 && plonkList[0] === ""){
plonkList = {};
}
case "object":
// check for pre-hash configuration data
if(Array.isArray(plonkList)){
plonkList = plonkList.reduce(function(obj,user,index){
obj[user]=[true];
return obj;
},{});
}
break;
default:
plonkList = {};
break;
}
let plonkClosedAccounts = GM_getValue("plonkClosedAccounts",true);
......@@ -105,16 +114,16 @@
let p = document.createElement("p");
let select = document.createElement("select");
if(plonkList.length){
if(Object.keys(plonkList).length){
p.appendChild(
document.createTextNode("Liste des utilisateurs plonkés:")
);
select.setAttribute("id","plonkList");
select.setAttribute("multiple","multiple");
for (let i = 0; i < plonkList.length; i++){
for(let u in plonkList){
let option = document.createElement("option");
option.setAttribute("value",plonkList[i]);
option.appendChild(document.createTextNode(plonkList[i]));
option.setAttribute("value",u);
option.appendChild(document.createTextNode(u));
select.appendChild(option);
}
}else{
......@@ -126,7 +135,7 @@
}
form.appendChild(p);
if(plonkList.indexOf(user) === -1){
if(!plonkList.hasOwnProperty(user)){
form.appendChild(button);
}
......@@ -137,7 +146,7 @@
button = document.createElement("button");
button.appendChild(document.createTextNode("Supprimer la sélection"));
button.addEventListener("click",function(){unplonk(user,alias);},true);
if(plonkList.length){
if(Object.keys(plonkList).length){
form.appendChild(button);
}
......@@ -148,7 +157,7 @@
}
function plonk(user,alias){
plonkList.push(user);
plonkList[user] = [true];
GM_setValue("plonkList",JSON.stringify(plonkList));
let select = document.getElementById("plonkList");
if(!select){
......@@ -174,10 +183,10 @@
if(!select[i].selected){
continue;
}
plonkList.splice(plonkList.indexOf(select[i].value),1);
delete plonkList[select[i].value];
select[i].remove();
}
if(!plonkList.length){
if(!Object.keys(plonkList).length){
let form = document.getElementById("plonkForm");
form.remove();
form = document.createElement("form");
......@@ -228,9 +237,9 @@
response.context.style.display = "none";
if(unlistClosedAccounts){
let userLink =response.context.getElementsByClassName('meta').item(0).getElementsByTagName('a').item(0);
let index = plonkList.indexOf(userLink.href.match(userRE)[1]);
if(index !== -1){
plonkList.splice(index,1);
let user= userLink.href.match(userRE);
if(plonkList.hasOwnProperty(user)){
delete plonkList[user];
GM_setValue("plonkList",JSON.stringify(plonkList));
}
}
......@@ -238,8 +247,8 @@
}
});
}
for(let j = 0; j < plonkList.length; j++){
if (userLink.href === "https://linuxfr.org/users/"+plonkList[j]){
for(let u in plonkList){
if (userLink.href === "https://linuxfr.org/users/"+u){
articles[i].style.display = "none";
break;
}
......
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