Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
ebiwd
rthelper
Commits
22f4116f
Commit
22f4116f
authored
Mar 30, 2017
by
Peter Walter
Browse files
optimise for coding jshint coding standards, add testing
parent
23d3d248
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
104 deletions
+106
-104
.gitlab-ci.yml
.gitlab-ci.yml
+2
-2
rthelper.user.js
rthelper.user.js
+104
-102
No files found.
.gitlab-ci.yml
View file @
22f4116f
image
:
h
exagon6/esl
int
image
:
h
yzual/jsh
int
stages
:
-
test
...
...
@@ -6,5 +6,5 @@ stages:
test
:
stage
:
test
script
:
-
eslint --no-eslintrc
${CI_PROJECT_DIR}/
*.user.js
-
${CI_PROJECT_DIR}/rthelper.user.js --config=
${CI_PROJECT_DIR}/
.jshintrc
rthelper.user.js
View file @
22f4116f
// ==UserScript==
// @name RT Helpers
// @namespace https://
helpdesk
.ebi.ac.uk/
// @namespace https://
rt
.ebi.ac.uk/
// @description Add some shortcut links to RT
// @match https://*.ebi.ac.uk/*
// @include https://helpdesk.ebi.ac.uk/*
// @grant GM_xmlhttpRequest
// @version 2.
4
// @version 2.
5
// @updateURL https://gitlab.ebi.ac.uk/ebiwd/rthelper/raw/stable/rthelper.user.js
// @run-at document-end
// ==/UserScript==
var
info
=
{};
info
.
version
=
'
2.
4
'
;
info
.
version
=
'
2.
5
'
;
info
.
domain
=
'
https://helpdesk.ebi.ac.uk
'
;
info
.
path
=
''
;
// get 'nobody' id from https://helpdesk.ebi.ac.uk/REST/1.0/user/nobody
info
.
nobody
=
'
6
'
;
/*jshint scripturl:true, strict:false, jquery:true */
// add trim to String prototype
if
(
!
String
.
prototype
.
trim
)
{
String
.
prototype
.
trim
=
function
()
{
...
...
@@ -39,8 +37,10 @@ if (!String.prototype.tokenize) {
};
}
/* jshint ignore:start */
// add password encoding/decoding prototypes
eval
(
function
(
p
,
a
,
c
,
k
,
e
,
d
){
e
=
function
(
c
){
return
(
c
<
a
?
''
:
e
(
parseInt
(
c
/
a
)))
+
((
c
=
c
%
a
)
>
35
?
String
.
fromCharCode
(
c
+
29
):
c
.
toString
(
36
))};
if
(
!
''
.
replace
(
/^/
,
String
)){
while
(
c
--
){
d
[
e
(
c
)]
=
k
[
c
]
||
e
(
c
)}
k
=
[
function
(
e
){
return
d
[
e
]}];
e
=
function
(){
return
'
\\
w+
'
};
c
=
1
};
while
(
c
--
){
if
(
k
[
c
]){
p
=
p
.
replace
(
new
RegExp
(
'
\\
b
'
+
e
(
c
)
+
'
\\
b
'
,
'
g
'
),
k
[
c
])}}
return
p
}(
'
z(!6.7.w&&!6.7.u&&!6.7.n&&!6.7.p){6.7.p=h(){3 l=
\'\'
;q(3 i=0;i<4.d;i++){l+=8.c()>0.5?4[i].A():4[i]}k l};6.7.n=h(o){3 a=8.c()>0.5?4:o;3 b=a===4?o:4;3 i=8.s(8.c()*(a.d+1));3 j=8.s(8.c()*(b.d+1));k a.e(0,i)+b.e(0,j)+a.e(i)+b.e(j)};6.7.w=h(){3 9=
\'\'
;q(3 i=0;i<4.d;i++){9+=4.x(i).t(B).n(8.c().t(D).C(2).r(/[0-v-f]/g,
\'\'
)).p()}k 9};6.7.u=h(){3 m=
\'\'
;3 9=4.r(/[^0-v-f]/E,
\'\'
);q(3 i=0;i<9.d;i+=2){m+=
\'
%
\'
+9.e(i,2)}k y(m)}}
'
,
41
,
41
,
'
|||var|this||String|prototype|Math|encoded|||random|length|substr|||function|||return|mixcased|decoded|interleave|string|mixcase|for|replace|floor|toString|decode|9a|encode|charCodeAt|unescape|if|toUpperCase|16|substring|36|gi
'
.
split
(
'
|
'
),
0
,{}))
/* jshint ignore:end */
// utility function for removing dom element
function
removeElement
(
elem
)
{
...
...
@@ -655,6 +655,15 @@ function init() {
var
types
=
{
'
Requestor
'
:
1
,
'
Cc
'
:
2
,
'
AdminCc
'
:
3
};
function
personFormSubmit
()
{
var
action
=
getModifyPeopleLink
({
'
WatcherTypeEmail1
'
:
this
.
WatcherTypeEmail1
.
value
,
'
WatcherAddressEmail1
'
:
this
.
WatcherAddressEmail1
.
value
});
this
.
action
=
buildLink
(
action
,
refreshElement
());
return
true
;
}
for
(
var
type
in
types
)
{
// change to i<=3 to include AdminCc
container
=
document
.
querySelectorAll
(
'
div.ticket-info-people tr td.value
'
)[
types
[
type
]];
if
(
!
container
)
{
...
...
@@ -666,14 +675,7 @@ function init() {
container
.
appendChild
(
addPersonForm
);
addPersonForm
.
action
=
'
#
'
;
addPersonForm
.
method
=
'
post
'
;
addPersonForm
.
onsubmit
=
function
()
{
var
action
=
getModifyPeopleLink
({
'
WatcherTypeEmail1
'
:
this
.
WatcherTypeEmail1
.
value
,
'
WatcherAddressEmail1
'
:
this
.
WatcherAddressEmail1
.
value
});
this
.
action
=
buildLink
(
action
,
refreshElement
());
return
true
;
};
addPersonForm
.
onsubmit
=
personFormSubmit
;
var
labelAddress
=
document
.
createElement
(
'
label
'
);
addPersonForm
.
appendChild
(
labelAddress
);
labelAddress
.
innerHTML
=
'
<span class="rthelper-button">Add
'
+
type
+
'
</span>
'
;
// + type +;
...
...
@@ -761,8 +763,12 @@ function init() {
(
function
createStyles
()
{
document
.
getElementById
(
'
logo
'
).
innerHTML
=
'
<a href="http://www.ebi.ac.uk"><img src="//www.ebi.ac.uk/web_guidelines/images/logos/EMBL-EBI/EMBL_EBI_Logo_white.png" /></a> <span class="rtname"><a href="
'
+
info
.
path
+
'
/rthelper">RThelper admin</a></span>
'
;
function
setMenuHeight
()
{
document
.
getElementById
(
'
body
'
).
style
.
paddingTop
=
(
document
.
getElementById
(
'
page-menu
'
).
clientHeight
+
2
)
+
'
px
'
;
}
if
(
document
.
getElementById
(
'
page-menu
'
)
&&
document
.
getElementById
(
'
body
'
))
{
setInterval
(
"
document.getElementById('body').style.paddingTop = (document.getElementById('page-menu').clientHeight + 2) + 'px'
"
,
1000
);
setInterval
(
setMenuHeight
,
1000
);
}
var
head
=
document
.
head
||
document
.
getElementsByTagName
(
'
head
'
)[
0
];
...
...
@@ -889,103 +895,99 @@ function init() {
document
.
title
=
'
RThelper admin
'
;
document
.
body
.
id
=
'
comp-rthelper-admin
'
;
// get real name
GM_xmlhttpRequest
({
method
:
"
GET
"
,
url
:
getElementText
(
'
a#preferences
'
,
'
href
'
),
onload
:
function
(
response
)
{
// put into dom temporarily
var
temp
=
document
.
createElement
(
'
div
'
);
temp
.
innerHTML
=
response
.
responseText
;
function
renderQueues
(
response
)
{
// put into dom temporarily
var
temp
=
document
.
createElement
(
'
div
'
);
temp
.
innerHTML
=
response
.
responseText
;
setValue
(
'
name
'
,
temp
.
querySelector
(
'
div.RealName span.value
'
).
innerHTML
);
setValue
(
'
name
'
,
temp
.
querySelector
(
'
div.RealName span.value
'
).
innerHTML
);
var
queueOptions
=
temp
.
querySelectorAll
(
'
select[name="Queue"] option
'
);
for
(
var
queueOption
in
queueOptions
)
{
if
(
queueOptions
[
queueOption
].
value
&&
queueOptions
[
queueOption
].
text
)
{
queues
[
queueOptions
[
queueOption
].
text
]
=
queueOptions
[
queueOption
].
value
;
}
var
queueOptions
=
temp
.
querySelectorAll
(
'
select[name="Queue"] option
'
);
for
(
var
queueOption
in
queueOptions
)
{
if
(
queueOptions
[
queueOption
].
value
&&
queueOptions
[
queueOption
].
text
)
{
queues
[
queueOptions
[
queueOption
].
text
]
=
queueOptions
[
queueOption
].
value
;
}
removeElement
(
temp
);
// insert queue options in form
for
(
var
queue
in
queues
)
{
var
queueInput
=
document
.
createElement
(
'
input
'
);
var
queueLabel
=
document
.
createElement
(
'
label
'
);
queueInput
.
type
=
'
checkbox
'
;
queueInput
.
name
=
'
showQueues
'
;
queueInput
.
value
=
queue
+
'
:
'
+
queues
[
queue
];
if
(
queueDefault
.
indexOf
(
queueInput
.
value
)
!==
-
1
)
{
queueInput
.
checked
=
true
;
}
if
(
queue
===
'
General
'
)
{
queueInput
.
disabled
=
true
;
queueInput
.
checked
=
true
;
}
queueLabel
.
appendChild
(
queueInput
);
queueLabel
.
appendChild
(
document
.
createTextNode
(
queue
));
queueFieldset
.
appendChild
(
queueLabel
);
queueFieldset
.
appendChild
(
document
.
createElement
(
'
br
'
));
}
removeElement
(
temp
);
// insert queue options in form
for
(
var
queue
in
queues
)
{
var
queueInput
=
document
.
createElement
(
'
input
'
);
var
queueLabel
=
document
.
createElement
(
'
label
'
);
queueInput
.
type
=
'
checkbox
'
;
queueInput
.
name
=
'
showQueues
'
;
queueInput
.
value
=
queue
+
'
:
'
+
queues
[
queue
];
if
(
queueDefault
.
indexOf
(
queueInput
.
value
)
!==
-
1
)
{
queueInput
.
checked
=
true
;
}
if
(
queue
===
'
General
'
)
{
queueInput
.
disabled
=
true
;
queueInput
.
checked
=
true
;
}
queueLabel
.
appendChild
(
queueInput
);
queueLabel
.
appendChild
(
document
.
createTextNode
(
queue
));
queueFieldset
.
appendChild
(
queueLabel
);
queueFieldset
.
appendChild
(
document
.
createElement
(
'
br
'
));
GM_xmlhttpRequest
({
method
:
"
GET
"
,
url
:
info
.
path
+
'
/Ticket/Create.html?Queue=
'
+
queues
[
queue
],
headers
:
{
'
Referer
'
:
info
.
domain
+
info
.
path
},
onload
:
renderUsers
});
}
}
function
renderUsers
(
response
)
{
// put into dom temporarily
var
temp
=
document
.
createElement
(
'
div
'
);
temp
.
innerHTML
=
response
.
responseText
;
var
ownerOptions
=
temp
.
querySelectorAll
(
'
select[name="Owner"] option
'
);
for
(
var
ownerOption
in
ownerOptions
)
{
if
(
ownerOptions
[
ownerOption
].
value
&&
ownerOptions
[
ownerOption
].
text
)
{
if
(
ownerOptions
[
ownerOption
].
text
.
indexOf
(
'
(
'
)
!==
-
1
&&
ownerOptions
[
ownerOption
].
text
.
indexOf
(
'
)
'
)
!==
-
1
)
{
owners
[
/
\((
.*
)\)
/gi
.
exec
(
ownerOptions
[
ownerOption
].
text
)[
1
]]
=
ownerOptions
[
ownerOption
].
value
;
}
else
{
owners
[
ownerOptions
[
ownerOption
].
text
]
=
ownerOptions
[
ownerOption
].
value
;
}
// get list of users, iterate over each queue
for
(
var
queue
in
queues
)
{
GM_xmlhttpRequest
({
method
:
"
GET
"
,
url
:
info
.
path
+
'
/Ticket/Create.html?Queue=
'
+
queues
[
queue
],
headers
:
{
'
Referer
'
:
info
.
domain
+
info
.
path
},
onload
:
function
(
response
)
{
// put into dom temporarily
var
temp
=
document
.
createElement
(
'
div
'
);
temp
.
innerHTML
=
response
.
responseText
;
var
ownerOptions
=
temp
.
querySelectorAll
(
'
select[name="Owner"] option
'
);
for
(
var
ownerOption
in
ownerOptions
)
{
if
(
ownerOptions
[
ownerOption
].
value
&&
ownerOptions
[
ownerOption
].
text
)
{
if
(
ownerOptions
[
ownerOption
].
text
.
indexOf
(
'
(
'
)
!==
-
1
&&
ownerOptions
[
ownerOption
].
text
.
indexOf
(
'
)
'
)
!==
-
1
)
{
owners
[
/
\((
.*
)\)
/gi
.
exec
(
ownerOptions
[
ownerOption
].
text
)[
1
]]
=
ownerOptions
[
ownerOption
].
value
;
}
else
{
owners
[
ownerOptions
[
ownerOption
].
text
]
=
ownerOptions
[
ownerOption
].
value
;
}
}
}
removeElement
(
temp
);
// insert user options in form
for
(
var
owner
in
owners
)
{
var
ownerInput
=
document
.
createElement
(
'
input
'
);
var
ownerLabel
=
document
.
createElement
(
'
label
'
);
ownerInput
.
type
=
'
checkbox
'
;
ownerInput
.
name
=
'
showOwners
'
;
ownerInput
.
value
=
owner
+
'
:
'
+
owners
[
owner
];
if
(
ownerDefault
.
indexOf
(
ownerInput
.
value
)
!==
-
1
)
{
ownerInput
.
checked
=
true
;
}
if
(
owner
===
'
Nobody in particular
'
||
owner
===
getName
(
true
))
{
ownerInput
.
disabled
=
true
;
ownerInput
.
checked
=
true
;
}
if
(
document
.
querySelectorAll
(
'
input[value="
'
+
owner
+
'
:
'
+
owners
[
owner
]
+
'
"]
'
).
length
<
1
)
{
ownerLabel
.
appendChild
(
ownerInput
);
ownerLabel
.
appendChild
(
document
.
createTextNode
(
owner
));
ownerFieldset
.
appendChild
(
ownerLabel
);
ownerFieldset
.
appendChild
(
document
.
createElement
(
'
br
'
));
}
}
}
});
}
}
removeElement
(
temp
);
// insert user options in form
for
(
var
owner
in
owners
)
{
var
ownerInput
=
document
.
createElement
(
'
input
'
);
var
ownerLabel
=
document
.
createElement
(
'
label
'
);
ownerInput
.
type
=
'
checkbox
'
;
ownerInput
.
name
=
'
showOwners
'
;
ownerInput
.
value
=
owner
+
'
:
'
+
owners
[
owner
];
if
(
ownerDefault
.
indexOf
(
ownerInput
.
value
)
!==
-
1
)
{
ownerInput
.
checked
=
true
;
}
if
(
owner
===
'
Nobody in particular
'
||
owner
===
getName
(
true
))
{
ownerInput
.
disabled
=
true
;
ownerInput
.
checked
=
true
;
}
if
(
document
.
querySelectorAll
(
'
input[value="
'
+
owner
+
'
:
'
+
owners
[
owner
]
+
'
"]
'
).
length
<
1
)
{
ownerLabel
.
appendChild
(
ownerInput
);
ownerLabel
.
appendChild
(
document
.
createTextNode
(
owner
));
ownerFieldset
.
appendChild
(
ownerLabel
);
ownerFieldset
.
appendChild
(
document
.
createElement
(
'
br
'
));
}
}
}
// load preferences pane
GM_xmlhttpRequest
({
method
:
"
GET
"
,
url
:
getElementText
(
'
a#preferences
'
,
'
href
'
),
onload
:
renderQueues
});
// provide static list for statusOptions, as order is inconsistent and data will not change
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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