Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pierre M
DLFPlonk
Commits
b937335b
Commit
b937335b
authored
May 26, 2016
by
Pierre M
Browse files
add a UI to manage the plonk list
Signed-off-by:
Pierre Mazière
<
pierre.maziere@gmx.com
>
parent
d81e5632
Changes
2
Hide whitespace changes
Inline
Side-by-side
CHANGELOG
View file @
b937335b
2016-05-26 v2
add a UI to manage the plonk list
2016-05-25 v1
initial release
\ No newline at end of file
initial release
plonk users contained in the plonk list
plonk users whose account is closed
DLFPlonk.user.js
View file @
b937335b
...
...
@@ -2,8 +2,12 @@
// @name DLFPlonk
// @namespace DLFPlonk
// @include https://linuxfr.org/*
// @version
1
// @version
2
// @grant GM_xmlhttpRequest
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_addStyle
// ==/UserScript==
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
...
...
@@ -13,23 +17,153 @@
//
(
function
()
{
var
plonk
=
[];
var
articles
=
document
.
getElementsByTagName
(
'
article
'
);
for
(
var
i
=
0
;
i
<
articles
.
length
;
i
++
)
{
var
userLink
=
articles
[
i
].
getElementsByClassName
(
'
meta
'
).
item
(
0
).
getElementsByTagName
(
'
a
'
).
item
(
0
);
let
plonkList
=
GM_getValue
(
"
plonkList
"
,
""
).
split
(
"
,
"
);
if
(
plonkList
.
length
===
1
&&
plonkList
[
0
]
===
""
){
plonkList
=
[];
}
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:300px;margin:auto;background-color:#FFF;z-index:101;padding:10px 20px;border:thick double #000}
"
);
GM_addStyle
(
"
.overlaywin select{width:100%;height:200px}
"
);
GM_addStyle
(
"
.overlaywin button{background-image:none;padding-left:5px}
"
);
GM_addStyle
(
"
.overlaywin button[disabled='disabled']{background-image:none;padding-left:5px;color:gray}
"
);
function
closePlonkList
(){
document
.
getElementsByClassName
(
"
overlaywin
"
).
item
(
0
).
remove
();
document
.
getElementsByClassName
(
"
overlaybg
"
).
item
(
0
).
remove
();
location
.
reload
();
}
function
buildForm
(
form
,
user
){
let
p
=
document
.
createElement
(
"
p
"
);
let
select
=
document
.
createElement
(
"
select
"
);
if
(
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
++
){
let
option
=
document
.
createElement
(
"
option
"
);
option
.
setAttribute
(
"
value
"
,
plonkList
[
i
]);
option
.
appendChild
(
document
.
createTextNode
(
plonkList
[
i
]));
select
.
appendChild
(
option
);
}
}
else
{
p
.
appendChild
(
document
.
createTextNode
(
"
Aucun utilisateur plonké pour le moment.
"
));
select
.
remove
();
select
=
null
;
}
form
.
appendChild
(
p
);
if
(
select
){
form
.
appendChild
(
select
);
}
let
addButton
=
document
.
createElement
(
"
button
"
);
addButton
.
setAttribute
(
"
id
"
,
"
plonkAdd
"
);
addButton
.
appendChild
(
document
.
createTextNode
(
"
Plonker '
"
+
user
+
"
'
"
));
addButton
.
addEventListener
(
"
click
"
,
function
(){
plonk
(
plonkList
,
user
);},
true
);
if
(
plonkList
.
indexOf
(
user
)
!==
-
1
){
addButton
.
setAttribute
(
"
disabled
"
,
"
disabled
"
);
}
form
.
appendChild
(
addButton
);
let
delButton
=
document
.
createElement
(
"
button
"
);
delButton
.
appendChild
(
document
.
createTextNode
(
"
Supprimer la sélection
"
));
delButton
.
addEventListener
(
"
click
"
,
function
(){
unplonk
(
plonkList
,
user
);},
true
);
if
(
!
plonkList
.
length
){
delButton
.
setAttribute
(
"
disabled
"
,
"
disabled
"
);
}
form
.
appendChild
(
delButton
);
let
cancelButton
=
document
.
createElement
(
"
button
"
);
cancelButton
.
appendChild
(
document
.
createTextNode
(
"
Valider
"
));
cancelButton
.
addEventListener
(
"
click
"
,
function
(){
closePlonkList
();},
true
);
form
.
appendChild
(
cancelButton
);
}
function
plonk
(
plonkList
,
user
){
plonkList
.
push
(
user
);
GM_setValue
(
"
plonkList
"
,
plonkList
.
join
(
"
,
"
));
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
);
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
);
}
}
function
unplonk
(
plonkList
,
user
){
select
=
document
.
getElementById
(
"
plonkList
"
);
for
(
let
i
=
0
;
i
<
select
.
length
;
i
++
){
if
(
!
select
[
i
].
selected
){
continue
;
}
plonkList
.
splice
(
plonkList
.
indexOf
(
select
[
i
]),
1
);
select
[
i
].
remove
();
}
if
(
plonkList
.
length
===
1
&&
plonkList
[
0
]
===
""
){
plonkList
=
[];
}
if
(
!
plonkList
.
length
){
let
form
=
document
.
getElementById
(
"
plonkForm
"
);
form
.
remove
();
form
=
document
.
createElement
(
"
form
"
);
form
.
setAttribute
(
"
id
"
,
"
plonkForm
"
);
buildForm
(
form
,
user
);
document
.
getElementsByClassName
(
"
overlaywin
"
).
item
(
0
).
appendChild
(
form
);
}
GM_setValue
(
"
plonkList
"
,
plonkList
.
join
(
"
,
"
));
}
function
addToPlonkList
(
plonkList
,
user
){
let
bg
=
document
.
createElement
(
"
div
"
);
bg
.
className
=
"
overlaybg
"
;
document
.
body
.
appendChild
(
bg
);
let
win
=
document
.
createElement
(
"
div
"
);
win
.
className
=
"
overlaywin
"
;
let
form
=
document
.
createElement
(
"
form
"
);
form
.
setAttribute
(
"
id
"
,
"
plonkForm
"
);
buildForm
(
form
,
user
);
win
.
appendChild
(
form
);
document
.
body
.
appendChild
(
win
);
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
(
plonkList
,
userLink
.
textContent
);},
true
);
a
.
href
=
"
#
"
;
sup
.
appendChild
(
a
);
span
.
appendChild
(
sup
);
userLink
.
parentNode
.
insertBefore
(
span
,
userLink
.
nextSibling
);
GM_xmlhttpRequest
({
method
:
"
GET
"
,
url
:
userLink
.
href
,
context
:
articles
[
i
],
onload
:
function
(
response
)
{
onload
:
function
(
response
)
{
if
(
response
.
responseText
.
match
(
/Compte fermé/
)){
response
.
context
.
style
.
display
=
"
none
"
;
}
}
});
for
(
var
j
=
0
;
j
<
plonk
.
length
;
j
++
){
if
(
userLink
.
textContent
==
plonk
[
j
]
||
userLink
.
href
==
"
https://linuxfr.org/users/
"
+
plonk
[
j
]){
articles
[
i
].
style
.
display
=
"
none
"
;
for
(
let
j
=
0
;
j
<
plonk
List
.
length
;
j
++
){
if
(
userLink
.
textContent
==
=
plonk
List
[
j
]
||
userLink
.
href
==
=
"
https://linuxfr.org/users/
"
+
plonk
List
[
j
]){
articles
[
i
].
style
.
display
=
"
none
"
;
break
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment