-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
347 lines (281 loc) · 9.55 KB
/
main.js
File metadata and controls
347 lines (281 loc) · 9.55 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
class Link {
constructor(title, link) {
this.title = title;
this.link = link;
}
}
let quickLinks = [];
function loadQuickLinks() {
quickLinks = [];
hasLink = true;
linkNum = 0;
while (hasLink) {
title = localStorage.getItem("t" + linkNum);
if (title) {
link = localStorage.getItem("l" + linkNum);
linkNum++;
quickLinks.push(new Link(title, link))
} else {
hasLink = false;
// alert("noLinksTo SHwo")
}
}
// console.log(quickLinks)
displayLinks();
}
function isValidURL(url) {
try {
new URL(url);
return true;
} catch (e) {
return false;
}
}
loadQuickLinks();
function displayLinks() {
let quicklinksElement = document.getElementById('quickLinks');
quicklinksElement.innerHTML = ""
// console.log(quicklinksElement)
linkId = 0;
quickLinks.forEach(link => {
quicklinksElement.innerHTML += createQuickLinkElement(link, linkId);
linkId++;
});
AddNewLinkElement = `
<div onClick="showWindow('linkAdderFull')" class="fullQuickLink">
<div class="quickLink m-10">
<div class="closeButtonHolder">
</div>
<h2 class="text-center quickLinkText quickLinkPlus">+</h2>
</div>
<p class="m-10 text-center quickLinkText">New Link</p>
</div>`;
quicklinksElement.innerHTML += AddNewLinkElement;
}
function heilightText(text) {
text.select();
}
function getFavicon(url) {
if (!isValidURL(url)) {
return;
}
// Extract domain from URL
let domain = new URL(url).origin;
// Standard location of favicon
let faviconUrl = `${domain}/favicon.ico`;
// Alternative: Use Google's favicon service
let googleFaviconUrl = `https://www.google.com/s2/favicons?domain=${domain}`;
return googleFaviconUrl;
}
function createQuickLinkElement(linkObj, id) {
link = linkObj.link;
title = linkObj.title;
titleDisplay = title;
if (title.length > 8) {
titleDisplay = title.substring(0, 6) + "..";
}
let quickLinkObj = ` <div id="id" class="fullQuickLink" title="${title}" onclick="openQuickLink('${link}')">
<div class="quickLink m-10">
<div class="closeButtonHolder">
<button class="closeButton small" onClick="deleteQuickLink(${id})" >X</button>
</div>
<div class="iconHolder center">
<img class="fav" src="${getFavicon(link)}" alt="">
</div>
</div>
<p class="m-10 text-center quickLinkText">${titleDisplay}</p>
</div>`
return quickLinkObj;
}
function saveQuickLink() {
title = document.getElementById("title").value;
newLink = document.getElementById("newLink").value;
if (title && isValidURL(newLink)) {
linkNum = quickLinks.length;
localStorage.setItem("t" + linkNum, title);
localStorage.setItem("l" + linkNum, newLink);
quickLinks.push(new Link(title, newLink));
// console.log(quickLinks);
loadQuickLinks();
} else {
alert("Link or Llink title Cannot be empty..")
}
}
function deleteQuickLink(id) {
localStorage.removeItem("t" + id, title);
localStorage.removeItem("l" + id, newLink);
linkNum = 0
// console.log("dlete" + id);
for (let i = 0; i < quickLinks.length; i++) {
if (i != id) {
localStorage.setItem("t" + linkNum, title);
localStorage.setItem("l" + linkNum, newLink);
linkNum++;
}
}
loadQuickLinks();
}
function cancelSavingLink() {
}
function searchInAll() {
openGoogle();
openYoutube();
openChatGPT();
}
function openChatGPT() {
const chatGPTUrl = `https://chat.openai.com/?model=gpt-4-turbo&temporary-chat=true`;
window.open(chatGPTUrl, "_blank");
}
function openGoogle() {
const encodedQuery = document.getElementById("searchText").value;
const googleUrl = `https://www.google.com/search?q=${encodedQuery}`;
window.open(googleUrl, "_blank");
}
function openYoutube() {
let youtubeUrl;
let searchText = document.getElementById("searchText").value;
if (searchText == "") {
youtubeUrl = `https://www.youtube.com`
} else {
youtubeUrl = `https://www.youtube.com/results?search_query=${searchText}`;
}
window.open(youtubeUrl, "_blank")
}
function openQuickLink(link) {
window.open(link, "_blank");
}
//=================home Page =============
function OpenYoutubeTutorial() {
window.open("https://www.youtube.com/", "_blank")
}
//====================common=============
function closeWindow(id) {
document.getElementById(id).classList.add("d-none");
}
function showWindow(id) {
document.getElementById(id).classList.remove("d-none");
}
//=============================================== saving and loading links =============
let links = [];
let currentEditingLink;
let linkEditText = document.getElementById("linkEditText");
function selectLink(linkId) {
currentEditingLink = linkId.id;
document.getElementById("linkEditTextSection").style.display = 'flex'
let link = localStorage.getItem(currentEditingLink) || "https://www.google.com";
document.getElementById("linkEditText").value = link;
}
function loadAllLinks() {
for (let i = 0; i < 5; i++) {
let link = localStorage.getItem("link" + i) || "https://www.google.com";
links.push(link);
document.getElementById("link" + i).textContent = link;
}
}
function saveLink() {
if (currentEditingLink) {
let linkEditTextValue = document.getElementById("linkEditText").value
if (!isValidURL(linkEditTextValue)) {
alert("Entered URL is not valid....");
return;
}
// console.log(currentEditingLink + " current editing link")
let linkIdInList = currentEditingLink[4] * 1;
links[linkIdInList] = linkEditTextValue;
localStorage.setItem(currentEditingLink, linkEditTextValue);
document.getElementById(currentEditingLink).textContent = linkEditTextValue;
document.getElementById("linkEditTextSection").style.display = 'none'
} else {
alert("No Edit Link Selected");
}
}
loadAllLinks();
// =================================================== time limits
let refreshDetails = document.getElementById("refreshDetails");
let minValue;
let maxValue;
function setValues(valueType) {
minValue = document.getElementById("minValue").value * 1;
maxValue = document.getElementById("maxValue").value * 1;
if (minValue >= maxValue) {
alert("Max value should be bigger than Min value");
return;
}
localStorage.setItem("minValue", minValue);
localStorage.setItem("maxValue", maxValue);
location.reload();
}
function loadminAndMaxValues() {
minValue = localStorage.getItem("minValue");
maxValue = localStorage.getItem("maxValue");
document.getElementById("minValue").value = minValue;
document.getElementById("maxValue").value = maxValue;
}
loadminAndMaxValues();
setTimeout(() => {
// console.log(links);
startOpenLinks(minValue, maxValue);
}, 4000)
let pause = false;
function pauseTimer(pauseButton, resumeButton) {
pauseButton.classList.add("d-none");
resumeButton.classList.remove("d-none");
pause = true;
}
function resume(pauseButton, resumeButton) {
pauseButton.classList.remove("d-none");
resumeButton.classList.add("d-none");
pause = false;
}
function checkPause() {
return pause;
}
function startOpenLinks(n, x) {
openLink(links[Math.floor(Math.random() * 5)]);
let frontTimeDisplay = document.getElementById("frontTimeDisplay");
let linksOpendTimes = 0;
links.push("https://www.linkedin.com/in/shehan-maleesha-017a89261/");
links.push("https://shehanm95.github.io/shehan.com/");
randomVal = createRandomVal(n, x);
setInterval(() => {
//console.log(randomVal);
if (!checkPause()) {
if (randomVal < 0) {
if (linksOpendTimes < 4) {
linksOpendTimes++;
randomLink = Math.floor(Math.random() * 5);
//console.log(links[randomLink]);
openLink(links[randomLink]);
} else {
linksOpendTimes = 0;
randomLink = Math.floor(Math.random() * 2 + 5);
//console.log(links[randomLink]);
openLink(links[randomLink]);
}
randomVal = createRandomVal(n, x);
} else {
timeText = `Site Refresh In : ${String((Math.floor(randomVal / 60))).padStart(2, "0")}:${String(randomVal % 60).padStart(2, "0")}`;
refreshDetails.textContent = timeText
frontTimeDisplay.textContent = timeText
}
randomVal--
}
}, 1000)
}
function createRandomVal(min, max) {
min = min * 1;
max = max * 1;
// Convert minutes to seconds directly - no need to multiply by 60 again
let minSeconds = min * 60;
let maxSeconds = max * 60;
let randomSeconds = Math.floor(Math.random() * (maxSeconds - minSeconds + 1) + minSeconds);
console.log(`Creating random timer: ${min}-${max} minutes = ${minSeconds}-${maxSeconds} seconds = ${randomSeconds} seconds (${Math.floor(randomSeconds / 60)}:${randomSeconds % 60})`);
return randomSeconds; // Return value in seconds
}
function openLink(link) {
window.open(link, "_blank");
// console.log(link)
}
function contactDeveloper() {
window.open("https://www.linkedin.com/in/shehan-maleesha-017a89261/", "_blank")
}