-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
81 lines (70 loc) · 2.04 KB
/
script.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
/**
* function to toggle dark theme
*/
function toggle_dark_theme() {
var element = document.body;
element.classList.toggle("dark-mode");
var containDarkMode = element.classList.contains("dark-mode");
if(containDarkMode){
localStorage.setItem("globalTheme", "dark-mode");
}else{
localStorage.setItem("globalTheme", "light-mode");
}
}
/**
* function to launch a url in new tab
* @param {string} url to be opened
*/
function launch_url(url) {
var win = window.open(url, '_blank');
win.focus();
}
/**
* copy email to clipboard onclick
*/
document.querySelector(".email").onclick = function(){
copyStringToClipboard(".email", "gauriatiq@gmail.com");
};
/**
* copy email to clipboard onclick
*/
document.querySelector(".meet-strangers").onclick = function(){
copyStringToClipboard(
".meet-strangers", "gauriatiq@gmail.com",
"Yay! you have my email in clipboard.", 2000
);
};
/**
* copy text to clipboard
* @param {string} class or id of target element with . & #
* @param {string} string which needs to be copied
*/
function copyStringToClipboard(element, str, copyHtml=null, sleepTime=null) {
var originalString = document.querySelector(element).innerHTML;
var el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style = {position: 'absolute', left: '-9999px'};
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
if(copyHtml == null){
copyHtml = "copied      "
}
document.querySelector(element).innerHTML = copyHtml;
if(sleepTime == null){
sleepTime = 500
}
sleep(sleepTime).then(() => {
document.querySelector(element).innerHTML = originalString;
})
console.log("done");
}
/**
* delay execution of statement for some milliseconds
* @param {number} milliseconds
*/
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}