Commit 61e4d5a4 authored by Pierre M's avatar Pierre M
Browse files

handle comments in addition to articles


Signed-off-by: Pierre M's avatarPierre Mazière <pierre.maziere@gmx.com>
parent df2129e8
......@@ -28,11 +28,21 @@
if(plonkList.length === 1 && plonkList[0] === ""){
plonkList = {};
}
// no break on purpose
case "object":
// check for pre-hash configuration data
if(Array.isArray(plonkList)){
plonkList = plonkList.reduce(function(obj,user,index){
obj[user]=[true];
obj[user]=[true,true];
return obj;
},{});
}else{
// check for configuration with lesser user specific options
plonkList = Object.keys(plonkList).reduce(function(obj,user,index){
switch(plonkList[user].length){
case 1: obj[user]=[plonkList[user][0],true]; break;
default: obj[user]=plonkList[user];break;
}
return obj;
},{});
}
......@@ -47,8 +57,14 @@
GM_addStyle(".overlaybg{position:fixed;top:0;left:0;width: 100%;height: 100%;background-color:#000; opacity:0.5;z-index:100}");
GM_addStyle(".overlaywin{position:fixed;left:0;right:0;top:0;bottom:0;width:600px;height:480px;margin:auto;background-color:#FFF;z-index:101;padding:10px 20px;border:thick double #000}");
GM_addStyle("#plonkForm select{width:100%;height:180px}");
GM_addStyle("#plonkList{position:relative;padding-top:25px;background:gray}");
GM_addStyle("#plonkList>div{overflow-y:auto;height:160px;background:#ddd}");
GM_addStyle("#plonkList table{width:100%;border-collapse:collapse}");
GM_addStyle("#plonkList td, #plonkForm th{color:#000;text-align:center;border:1px;white-space:nowrap;padding:5px 25px;}");
GM_addStyle("#plonkList th{height:0;line-height:0;padding-top:0;padding-bottom:0;border:none;color:transparent;white-space:nowrap}");
GM_addStyle("#plonkList th>div,#plonkList th>input{position:absolute;top:0;background:transparent;color:#000;padding:4px 25px;margin-left:-6px;line-height:normal;}");
GM_addStyle("#plonkForm button{background-image:none;padding-left:5px}");
GM_addStyle("#plonkList+button{margin-top:10px}")
GM_addStyle("#plonkForm h2{text-align:center}");
function closePlonkList(){
......@@ -106,7 +122,7 @@
let button = document.createElement("button");
button.setAttribute("id","plonkAdd");
button.appendChild(document.createTextNode("Plonker '"+user+"'"));
button.appendChild(document.createTextNode("Ajouter '"+user+"'"));
if( user !== alias ){
button.appendChild(document.createTextNode("' alias '"+alias+"'"));
}
......@@ -116,34 +132,118 @@
},true);
let p = document.createElement("p");
let select = document.createElement("select");
let container = document.createElement("div");
container.setAttribute("id","plonkList");
let list = document.createElement("div");
container.appendChild(list);
let table = document.createElement("table");
list.appendChild(table);
let thead = document.createElement("thead");
table.appendChild(thead);
let row = document.createElement("tr");
thead.appendChild(row);
let col = document.createElement("th");
row.appendChild(col);
checkbox = document.createElement("input");
checkbox.setAttribute("type","checkbox");
checkbox.addEventListener("change",function(){
let users = document.getElementsByName("users");
for (let i = 0; i < users.length ; i++){
users[i].checked=!users[i].checked;
}
});
col.appendChild(checkbox);
col = document.createElement("th");
row.appendChild(col);
col.appendChild(document.createTextNode("Comptes"));
div = document.createElement("div");
div.appendChild(document.createTextNode("Comptes"));
col.appendChild(div);
col = document.createElement("th");
row.appendChild(col);
col.appendChild(document.createTextNode("Contenus"));
div = document.createElement("div");
div.appendChild(document.createTextNode("Contenus"));
col.appendChild(div);
col = document.createElement("th");
row.appendChild(col);
col.appendChild(document.createTextNode("Commentaires"));
div = document.createElement("div");
div.appendChild(document.createTextNode("Commentaires"));
col.appendChild(div);
let tbody = document.createElement("tbody");
table.appendChild(tbody);
if(Object.keys(plonkList).length){
p.appendChild(
document.createTextNode("Liste des utilisateurs plonkés:")
);
select.setAttribute("id","plonkList");
select.setAttribute("multiple","multiple");
for(let u in plonkList){
let option = document.createElement("option");
option.setAttribute("value",u);
option.appendChild(document.createTextNode(u));
select.appendChild(option);
row = document.createElement("tr");
row.setAttribute("id",u);
col=document.createElement("td");
checkbox = document.createElement("input");
checkbox.setAttribute("id","user_"+u);
checkbox.setAttribute("type","checkbox");
checkbox.setAttribute("name","users");
checkbox.setAttribute("value",u);
col.appendChild(checkbox);
row.appendChild(col);
col=document.createElement("td");
label = document.createElement("label");
label.setAttribute("for","user_"+u);
label.appendChild(document.createTextNode(u));
col.appendChild(label);
row.appendChild(col);
col=document.createElement("td");
checkbox = document.createElement("input");
checkbox.setAttribute("type","checkbox");
checkbox.setAttribute("name","articles_"+u);
checkbox.addEventListener("change",function(){
plonkList[u][0]=!plonkList[u][0];
GM_setValue("plonkList",JSON.stringify(plonkList));
});
if(plonkList[u][0]){
checkbox.setAttribute("checked","checked");
}
col.appendChild(checkbox);
row.appendChild(col);
col=document.createElement("td");
checkbox = document.createElement("input");
checkbox.setAttribute("type","checkbox");
checkbox.setAttribute("name","comments_"+u);
checkbox.addEventListener("change",function(){
plonkList[u][1]=!plonkList[u][1];
GM_setValue("plonkList",JSON.stringify(plonkList));
});
if(plonkList[u][1]){
checkbox.setAttribute("checked","checked");
}
col.appendChild(checkbox);
row.appendChild(col);
tbody.appendChild(row);
}
}else{
p.appendChild(
document.createTextNode("Aucun utilisateur actif plonké pour le moment.")
);
select.remove();
select = null;
container.remove();
container = null;
}
form.appendChild(p);
if(!plonkList.hasOwnProperty(user)){
form.appendChild(button);
form.appendChild(button);
if(plonkList.hasOwnProperty(user)){
button.style.visibility="hidden";
}
if(select){
form.appendChild(select);
if(container){
form.appendChild(container);
}
button = document.createElement("button");
......@@ -166,36 +266,26 @@
}
function plonk(user,alias){
plonkList[user] = [true];
plonkList[user] = [true,true];
GM_setValue("plonkList",JSON.stringify(plonkList));
let select = document.getElementById("plonkList");
if(!select){
let form = document.getElementById("plonkForm");
form.remove();
form = document.createElement("form");
form.setAttribute("id","plonkForm");
buildForm(form,user,alias);
document.getElementsByClassName("overlaywin").item(0).appendChild(form);
}else{
let option = document.createElement("option");
option.setAttribute("value",user);
option.appendChild(document.createTextNode(user));
option.setAttribute("selected","selected");
select.appendChild(option);
document.getElementById("plonkAdd").style.visibility="hidden";
}
let form = document.getElementById("plonkForm");
form.remove();
form = document.createElement("form");
form.setAttribute("id","plonkForm");
buildForm(form,user,alias);
document.getElementsByClassName("overlaywin").item(0).appendChild(form);
}
function unplonk(user,alias){
select = document.getElementById("plonkList");
let users = document.getElementsByName("users");
// walk select options in reverse order to avoid
// indices reordering consequence of option removal
for (let i = select.length-1; i >= 0 ; i--){
if(!select[i].selected){
for (let i = users.length-1; i >= 0 ; i--){
if(!users[i].checked){
continue;
}
delete plonkList[select[i].value];
select[i].remove();
delete plonkList[users[i].value];
document.getElementById(users[i].value).remove();
}
if(!Object.keys(plonkList).length){
let form = document.getElementById("plonkForm");
......@@ -259,10 +349,54 @@
});
}
for(let u in plonkList){
if (userLink.href === "https://linuxfr.org/users/"+u){
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 u in plonkList){
if (userLink.href === "https://linuxfr.org/users/"+u && plonkList[u][1]){
comments[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