-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom.js
89 lines (80 loc) · 2.46 KB
/
dom.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Honeypot trap for malware */
/* write(); document.write(); */
function DUMMY() {
document.write("harmless");
document.write("test2");
}
/**
* Pretty Print
*/
function pp(x) {
var s = "";
for (var k in x) {
s += k + ": " + x[k] + ", " ;
}
return s;
}
function println(s) {
document.write(s + "<br>\n");
}
function getEl(id) {
if (document.getElementById) return document.getElementById(id);
else if (document.all) return document.all[id];
}
function showEl(s, type) {
if (type) getEl(s).style.display = type;
else getEl(s).style.display = "block";
}
function hideEl(s) {
getEl(s).style.display = "none";
}
function disable(s) {
getEl(s).disabled = true;
}
function enable(s) {
getEl(s).disabled = false;
}
/**
* Math
*/
function roundTo(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}
/**
* String
*/
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (str){
return this.lastIndexOf(str, 0) === 0;
};
}
function addslashes(str) {
// Escapes single quote, double quotes and backslash characters in a string with backslashes
//
// version: 1109.2015
// discuss at: http://phpjs.org/functions/addslashes
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Ates Goral (http://magnetiq.com)
// + improved by: marrtins
// + improved by: Nate
// + improved by: Onno Marsman
// + input by: Denny Wardhana
// + improved by: Brett Zamir (http://brett-zamir.me)
// + improved by: Oskar Larsson Högfeldt (http://oskar-lh.name/)
// * example 1: addslashes("kevin's birthday");
// * returns 1: 'kevin\'s birthday'
return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}
/*
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&, <, >, ", '), the forward slash is included as it helps to end an HTML entity.
& --> &
< --> <
> --> >
" --> "
' --> ' ' is not recommended
/ --> / forward slash is included as it helps end an HTML entity
*/
function strToHTML(str) {
return (str + '').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,''').replace(/\//g,'/');
}