-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
executable file
·87 lines (78 loc) · 2.42 KB
/
common.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
document.addEventListener(
"DOMContentLoaded",
function () {
// format JSON method
document.getElementById("submit").addEventListener(
"click",
function () {
var jsonValue = null;
try {
if (document.getElementById("inputTxt").value) {
jsonValue = document
.getElementById("inputTxt")
.value.replace('"{', "{")
.replace('}"', "}");
// condition check for format or deformat
if (document.getElementById("deformat").checked) {
document.getElementById("inputTxt").value = JSON.stringify(
JSON.parse(jsonValue)
);
} else {
document.getElementById("inputTxt").value = JSON.stringify(
JSON.parse(jsonValue),
null,
2
);
}
// copy the formatted content
copyContent();
} else {
// error handler
document.getElementById("copiedMsg").style.display = "none";
document.getElementById("errorMsg").style.display = "block";
setTimeout(function () {
document.getElementById("errorMsg").style.display = "none";
}, 6500);
}
} catch (err) {}
},
false
);
// loads google analytics scripts
loadScript();
},
false
);
function copyContent() {
if (
document.queryCommandSupported &&
document.queryCommandSupported("copy")
) {
var copyTextarea = document.getElementById("inputTxt");
copyTextarea.select();
try {
document.execCommand("copy");
document.getElementById("errorMsg").style.display = "none";
document.getElementById("copiedMsg").style.display = "block";
setTimeout(function () {
document.getElementById("copiedMsg").style.display = "none";
}, 6500);
// to unselect the selection content
if (window.getSelection) {
window.getSelection().removeAllRanges();
}
} catch (err) {}
}
}
function gtag() {
dataLayer.push(arguments);
}
function loadScript() {
var scriptTag = document.createElement("script");
scriptTag.src = "https://www.googletagmanager.com/gtag/js?id=UA-102573905-3";
scriptTag.async = true;
document.querySelector("head").append(scriptTag);
window.dataLayer = window.dataLayer || [];
gtag("js", new Date());
gtag("config", "UA-102573905-3");
}