Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aandrew-me
GitHub Repository: aandrew-me/ytDownloader
Path: blob/main/src/common.js
448 views
1
const electron = require("electron");
2
/**
3
*
4
* @param {string} id
5
* @returns {any}
6
*/
7
function getId(id) {
8
return document.getElementById(id);
9
}
10
11
getId("menuIcon").addEventListener("click", () => {
12
const menuDisplay = getId("menu").style.display;
13
if (menuDisplay != "none" && menuDisplay != "") {
14
getId("menuIcon").style.transform = "rotate(0deg)";
15
let count = 0;
16
let opacity = 1;
17
const fade = setInterval(() => {
18
if (count >= 10) {
19
getId("menu").style.display = "none";
20
clearInterval(fade);
21
} else {
22
opacity -= 0.1;
23
getId("menu").style.opacity = opacity.toFixed(3).toString();
24
count++;
25
}
26
}, 50);
27
} else {
28
getId("menuIcon").style.transform = "rotate(90deg)";
29
30
setTimeout(() => {
31
getId("menu").style.display = "flex";
32
getId("menu").style.opacity = "1";
33
}, 150);
34
}
35
});
36
37
getId("themeToggle").addEventListener("change", () => {
38
localStorage.setItem("theme", getId("themeToggle").value);
39
40
const x = window.innerWidth;
41
const y = 0;
42
const maxRadius = Math.hypot(window.innerWidth, window.innerHeight);
43
44
const transition = document.startViewTransition(() => {
45
document.documentElement.setAttribute("theme", getId("themeToggle").value);
46
});
47
48
transition.ready.then(() => {
49
document.documentElement.animate(
50
{
51
clipPath: [
52
`circle(0px at ${x}px ${y}px)`,
53
`circle(${maxRadius}px at ${x}px ${y}px)`
54
]
55
},
56
{
57
duration: 1100,
58
easing: 'cubic-bezier(0.4, 0, 0.2, 1)',
59
pseudoElement: '::view-transition-new(root)'
60
}
61
);
62
});
63
});
64
65
const storageTheme = localStorage.getItem("theme");
66
if (storageTheme) {
67
document.documentElement.setAttribute("theme", storageTheme);
68
getId("themeToggle").value = storageTheme;
69
} else {
70
getId("themeToggle").value = "frappe";
71
document.documentElement.setAttribute("theme", "frappe");
72
}
73
74
////
75
let advancedHidden = true;
76
77
function advancedToggle() {
78
if (advancedHidden) {
79
getId("advanced").style.display = "block";
80
advancedHidden = false;
81
} else {
82
getId("advanced").style.display = "none";
83
advancedHidden = true;
84
}
85
}
86
87
// Check scroll go to top
88
89
window.onscroll = function () {
90
scrollFunction();
91
};
92
93
function scrollFunction() {
94
if (
95
document.body.scrollTop > 50 ||
96
document.documentElement.scrollTop > 50
97
) {
98
getId("goToTop").style.display = "block";
99
} else {
100
getId("goToTop").style.display = "none";
101
}
102
}
103
104
// Function to scroll go to top
105
106
getId("goToTop").addEventListener("click", () => {
107
window.scrollTo({top: 0, behavior: "smooth"});
108
});
109
110
// Showing and hiding error details
111
function toggleErrorDetails() {
112
const status = getId("errorDetails").style.display;
113
if (status === "none") {
114
getId("errorDetails").style.display = "block";
115
// @ts-ignore
116
getId("errorBtn").textContent = i18n.__("errorDetails") + " ▲";
117
} else {
118
getId("errorDetails").style.display = "none";
119
// @ts-ignore
120
getId("errorBtn").textContent = i18n.__("errorDetails") + " ▼";
121
}
122
}
123