-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.gs
54 lines (50 loc) · 1.42 KB
/
Util.gs
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
function isArray(what) {
return Object.prototype.toString.call(what) === '[object Array]';
}
function makeURLEncodedStringWithArrays(JSON_obj) {
var query = "";
for (key in JSON_obj) {
if (isArray(JSON_obj[key])) {
for (var idx=0; idx < JSON_obj[key].length; idx++) {
query += encodeURIComponent(key)+"="+encodeURIComponent(JSON_obj[key][idx])+"&";
}
} else {
query += encodeURIComponent(key)+"="+encodeURIComponent(JSON_obj[key])+"&";
}
}
return query;
}
function getElementsByTagName(element, tagName) {
var data = [];
var descendants = element.getDescendants();
for(i in descendants) {
var elt = descendants[i].asElement();
if( elt !=null && elt.getName()== tagName) data.push(elt);
}
return data;
}
function getElementsByClassName(element, classToFind) {
var data = [];
var descendants = element.getDescendants();
descendants.push(element);
for(i in descendants) {
var elt = descendants[i].asElement();
if(elt != null) {
var classes = elt.getAttribute('class');
if(classes != null) {
classes = classes.getValue();
if(classes == classToFind) data.push(elt);
else {
classes = classes.split(' ');
for(j in classes) {
if(classes[j] == classToFind) {
data.push(elt);
break;
}
}
}
}
}
}
return data;
}