-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.user.js
73 lines (61 loc) · 1.52 KB
/
template.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* STD - functions
*/
function decimals(num, n) {
var a = Math.pow(10, n);
return Math.round(num*a) / a;
}
function create(nn, attr, p) {
var n = document.createElement(nn);
for (a in attr)
n.setAttribute(a, attr[a]);
if (p) p.appendChild(n);
return n;
}
function deserialize(name, def) {
var ev = eval(GM_getValue(name));
return (ev != null ? ev :
def != null ? def : null);
}
function serialize(name, val) {
GM_setValue(name, uneval(val));
}
function $x(xpath, root) { // From Johan Sundström
var doc = root ? root.evaluate ? root : root.ownerDocument : document, next;
var got = doc.evaluate(xpath, root||doc, null, null, null), result = [];
while((next = got.iterateNext())) {
result.push(next);
}
return result;
}
function $xs(xpath, root) { return $x(xpath, root)[0]; }
function trim(str) {
return str.replace(/^\W+|\W+$/gi, "");
};
function bind(method, obj) {
return function() {
method.apply(obj, arguments);
};
}
function curry(method, obj) {
var curryargs = $A(arguments).slice(2);
return function() { return method.apply(obj || window, curryargs.concat($A(arguments))); };
}
function $A(arr) {
var r = [], len = arr.length;
while (len--) r.unshift(arr[len]);
return r;
}
function sprintf(str) {
var a;
args = $A(arguments);
args.shift();
while ((a = args.shift()) !== undefined)
str = str.replace("\f", a);
return str;
}
function $(id) {
return document.getElementById(id);
}
// funkar om n != <html>
function remove(n) { n.parentNode.removeChild(n); }