-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpage.js
More file actions
391 lines (325 loc) · 11.9 KB
/
Copy pathwebpage.js
File metadata and controls
391 lines (325 loc) · 11.9 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
function bookmarkPage() {
if (window.sidebar && window.sidebar.addPanel) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(document.title, window.location.href, '');
} else if (window.external && ('AddFavorite' in window.external)) { // IE Favorite
window.external.AddFavorite(location.href, document.title);
} else if (window.opera && window.print) { // Opera Hotlist
this.title = document.title;
return true;
} else { // webkit - safari/chrome
alert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') !== -1 ? 'Command/Cmd' : 'CTRL') + ' + D to bookmark this page.');
}
}
function getBrowser() {
var ua = navigator.userAgent, tem,
browser = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(browser[1])){
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
return 'IE '+(tem[1] || '');
}
if(browser[1] === 'Chrome'){
tem= ua.match(/\b(OPR|Edge)\/(\d+)/);
if(tem !== null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
}
browser = browser[2] ? [browser[1], browser[2]]: [navigator.appName, navigator.appVersion, '-?'];
if((tem = ua.match(/version\/(\d+)/i))!== null) browser.splice(1, 1, tem[1]);
return browser.join(' ');
}
function browserPlugins() {
var plugins = [];
for (var i in navigator.plugins) {
if (typeof (navigator.plugins[i]) === 'object') {
plugins.push(navigator.plugins[i].name);
}
};
return plugins;
}
function getIp(selector) {
selector = selector || false;
ajax({
url: "http://api.ipify.org/"
}, function(data) {
if (selector) {
document.querySelectorAll(selector).forEach(function(item) {
item.innerHTML += data;
});
}
});
}
function blink(selector, speed) {
selector = selector || 'blink';
speed = speed || 500;
var elements = document.querySelectorAll(selector);
elements.forEach(function(item){
var el = item;
setInterval(function(){
if (el.style.opacity === '' || el.style.opacity === '1') {
el.style.opacity = '0.0';
} else {
el.style.opacity = '1.0';
}
}, speed);
});
}
function isNumericDigit(evt) {
return (evt.keyCode >= 48 && evt.keyCode <= 57)
|| (evt.keyCode >= 96 && evt.keyCode <= 105);
}
function isNode(obj){
return (
typeof Node === "object" ? obj instanceof Node :
obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName==="string"
);
}
function isElement(obj){
return (
typeof HTMLElement === "object" ? obj instanceof HTMLElement : //DOM2
obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string"
);
}
function isHidden(el) {
var style = window.getComputedStyle(el);
return (el.offsetParent === null || style.display === 'none');
}
function escapeHtml(string) {
var entityMap = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
'/': '/',
'`': '`',
'=': '='
};
return String(string).replace(/[&<>"'`=\/]/g, function(str) {
return entityMap[str];
});
}
function isIpv4(ip) {
var str = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/.test(ip);
//var str = /^(?:(?:25[0-5]2[0-4][0-9][01]?[0-9][0-9]?)\.){3}(?:25[0-5]2[0-4][0-9][01]?[0-9][0-9]?)$/.test(ip);
return str;
}
function isIpv6(ip) {
var str = /^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?$/.test(ip);
return str;
}
function isMobile() {
function ua(ag) {
return navigator.userAgent.match(ag);
}
if(ua(/Android/i)
|| ua(/webOS/i)
|| ua(/iPhone/i)
|| ua(/iPad/i)
|| ua(/iPod/i)
|| ua(/BlackBerry/i)
|| ua(/Windows Phone/i)
){
return true;
} else {
return false;
}
}
function isEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function isURL(url) {
var pattern = new RegExp('^(https?:\/\/)?'+ // protocol
'((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|'+ // domain name
'((\d{1,3}\.){3}\d{1,3}))'+ // OR ip (v4) address
'(\:\d+)?(\/[-a-z\d%_.~+]*)*'+ // port and path
'(\?[;&a-z\d%_.~+=-]*)?'+ // query string
'(\#[-a-z\d_]*)?$','i'); // fragment locater
if(!pattern.test(url)) {
return false;
} else {
return true;
}
}
function urlParams() {
var vars = {};
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
vars[key] = value;
});
return vars;
}
function formSubmit(id, userEvent){
userEvent = userEvent || window.event;
if (typeof id === 'number') {
document.forms[id].submit();
} else {
document.getElementById(id).submit();
}
}
function enterSubmit(id, userEvent){
if (userEvent.keyCode === 13) {
formSubmit(id, userEvent);
}
}
function setFullScreen() {
var doc = document.documentElement,
rfs = doc.requestFullScreen
|| doc.webkitRequestFullScreen
|| doc.mozRequestFullScreen;
rfs.call(doc);
}
function ss(scriptPath, callback, insertBody) {
insertBody = insertBody || true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = scriptPath;
if (insertBody) {
document.body.appendChild(script);
} else {
document.head.appendChild(script);
}
script.onload = function() {
callback();
};
}
function windowSize() {
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
return {"width": x, "height": y};
}
function goTop() {
window.scrollTo(0, 0);
}
function goBottom() {
window.scrollTo(0, document.body.scrollHeight);
}
function pagePos(x, y) {
window.scrollTo(x, y);
}
function printContent(elemId) {
var d = document, body = d.body,
elementsContent = d.getElementById(elemId).innerHTML,
oldPage = body.innerHTML;
body.innerHTML ="<html>"+
"<head>"+
"<meta charset='" + d.characterSet + "'>"+
"<title>Print</title>"+
"</head>"+
"<body>" + elementsContent + "</body>"+
"</html>";
//Print Page
window.print();
//Restore orignal HTML
document.body.innerHTML = oldPage;
}
function toggleCheckAll(e) {
var element = e.target || event.srcElement || e.srcElement;
var check = element.checked;
var arrayElements = document.getElementsByTagName('input');
for (var i = 0; i < arrayElements.length; i++) {
if (arrayElements[i].type === 'checkbox') {
arrayElements[i].checked = check;
}
}
}
function isValidForm(id) {
if (typeof id === 'number') {
return document.forms[id].checkValidity();
} else {
return document.getElementById(id).checkValidity();
}
}
function serializeForm(form) {
if (!form || form.nodeName !== "FORM") {
return false;
}
var i = form.elements.length - 1, j = 0, q = [];
while (i >= 0) {
var element = form.elements[i];
var elementName = element.name, elementType = element.type, elementValue = element.value;
if (elementName === "") {
i = i - 1;
continue;
}
switch (element.nodeName) {
case "INPUT":
switch (elementType) {
case "checkbox":
case "radio":
if (element.checked) {
q.push(elementName + "=" + encodeURIComponent(elementValue));
}
break;
default:
q.push(elementName + "=" + encodeURIComponent(elementValue));
break;
}
break;
case "TEXTAREA":
q.push(elementName + "=" + encodeURIComponent(elementValue));
break;
case "SELECT":
switch (elementType) {
case "select-one":
q.push(elementName + "=" + encodeURIComponent(elementValue));
break;
case "select-multiple":
j = element.options.length - 1;
while (j >= 0) {
if (element.options[j].selected) {
q.push(elementName + "=" + encodeURIComponent(element.options[j].value));
}
j = j - 1;
}
}
break;
case "BUTTON":
q.push(elementName + "=" + encodeURIComponent(elementValue));
break;
}
i = i - 1;
}
return q.join("&");
};
function isInput(selector) {
var query = document.querySelectorAll(selector);
if ( ! isEmpty(query) ) {
var elem = query[0].nodeName,
result = ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'].indexOf(elem);
return result !== -1;
}
return false;
}
function copyTextToClipboard(selector) {
var d = document, aux = d.createElement("input");
aux.setAttribute("value", document.querySelectorAll(selector)[0].innerHTML);
d.body.appendChild(aux);
aux.select();
d.execCommand("copy");
d.body.removeChild(aux);
}
function copyHtmlToClipboard(selector){
var d = document, aux = d.createElement("div");
aux.setAttribute("contentEditable", true);
aux.innerHTML = document.querySelectorAll(selector)[0].innerHTML;
aux.setAttribute("onfocus", "document.execCommand('selectAll',false,null)");
d.body.appendChild(aux);
aux.focus();
d.execCommand("copy");
d.body.removeChild(aux);
}
function getEndPoint() {
var urlSplit = window.location.href.split('/');
urlSplit = urlSplit[urlSplit.length -1];
return urlSplit.replace(/((\?)|(\/)|(\#)).*/, '');
}
function notNativeFunctions() {
var Instance = eval('Function');
return Object.keys(window).filter(function (x) {
return window[x] instanceof Instance && !/\[native code\]/.test(window[x].toString());
});
}
// try cookies lang, language, see if is 2 chars or 2 chars + _ or - + 2 chars like en_US or en-es, try window.location.href if is "en.adobe.com" or something like "adobe.com/en" or so "adobe.com?lang=en" and get the "en"
function guessPageLanguage() {}