-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
255 lines (216 loc) · 8.09 KB
/
main.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
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
// search-bar
$(document).ready(function() {
$('form').submit(function(event) {
event.preventDefault();
var searchQuery = $('input[type="text"]').val().toLowerCase();
$('.box').each(function() {
var boxText = $(this).text().toLowerCase();
if (boxText.indexOf(searchQuery) !== -1) {
$(this).show();
} else {
$(this).hide();
}
});
});
});
var shortcuts = [];
// Get the shortcut container element
var shortcutContainer = document.getElementById("shortcutContainer");
// Render shortcuts
function renderShortcuts() {
// Clear existing shortcuts
shortcutContainer.innerHTML = "";
// Loop through shortcuts and create elements
shortcuts.forEach(function (shortcut) {
var shortcutElement = document.createElement("div");
shortcutElement.className = "shortcut";
// Create logo image
var logoImg = document.createElement("img");
logoImg.alt = shortcut.name;
logoImg.onerror = function() {
// Use the default favicon if logo retrieval fails
logoImg.src = shortcut.logo || ("https://www.google.com/s2/favicons?domain=" + shortcut.url);
};
// Fetch the website and extract the logo
fetch(shortcut.url)
.then(response => response.text())
.then(data => {
var parser = new DOMParser();
var doc = parser.parseFromString(data, "text/html");
var logoElement = doc.querySelector("link[rel='shortcut icon'], link[rel='icon']");
if (logoElement) {
var logoUrl = new URL(logoElement.href, shortcut.url);
logoImg.src = logoUrl.href;
} else {
// Use the default favicon if no logo found
logoImg.src = "https://www.google.com/s2/favicons?domain=" + shortcut.url;
}
})
.catch(error => {
console.error("Logo fetch error:", error);
// Use the default favicon on fetch error
logoImg.src = "https://www.google.com/s2/favicons?domain=" + shortcut.url;
});
// Create site icon container
var siteIconContainer = document.createElement("div");
siteIconContainer.className = "site-icon-container";
siteIconContainer.appendChild(logoImg);
// Append site icon container to shortcut element
shortcutElement.appendChild(siteIconContainer);
// Create site name
var nameElement = document.createElement("div");
nameElement.className = "name";
var displayName = shortcut.name.length > 8 ? shortcut.name.slice(0, 8) + "..." : shortcut.name;
nameElement.textContent = displayName;
shortcutElement.appendChild(nameElement);
// Add click event to open site
shortcutElement.addEventListener("click", function () {
window.open(shortcut.url, "_blank");
});
// Create options
var optionsElement = document.createElement("div");
optionsElement.className = "options";
// Create three-dot icon
var optionsIcon = document.createElement("i");
optionsIcon.className = "fas fa-ellipsis-v options-icon";
optionsIcon.addEventListener("click", function (event) {
event.stopPropagation();
optionsElement.style.display = "block";
});
shortcutElement.appendChild(optionsIcon);
// Create rename button
var renameBtn = document.createElement("button");
renameBtn.textContent = "Rename";
renameBtn.addEventListener("click", function (event) {
event.stopPropagation();
var newName = prompt("Enter new name", shortcut.name);
if (newName) {
shortcut.name = newName;
renderShortcuts();
saveShortcuts();
}
});
optionsElement.appendChild(renameBtn);
// Create delete button
var deleteBtn = document.createElement("button");
deleteBtn.textContent = "Delete";
deleteBtn.addEventListener("click", function (event) {
event.stopPropagation();
var index = shortcuts.indexOf(shortcut);
if (index > -1) {
shortcuts.splice(index, 1);
renderShortcuts();
saveShortcuts();
}
});
optionsElement.appendChild(deleteBtn);
// Add options to the shortcut element
shortcutElement.appendChild(optionsElement);
// Add the shortcut element to the container
shortcutContainer.appendChild(shortcutElement);
});
}
// Add shortcut button click event
var addShortcutBtn = document.getElementById("addShortcutBtn");
addShortcutBtn.addEventListener("click", function () {
document.getElementById("modal").style.display = "block";
});
// Save shortcut button click event
var saveShortcutBtn = document.getElementById("saveShortcutBtn");
saveShortcutBtn.addEventListener("click", function () {
var nameInput = document.getElementById("nameInput");
var urlInput = document.getElementById("urlInput");
var name = nameInput.value;
var url = urlInput.value;
if (name && url) {
var shortcut = {
name: name,
url: url
};
shortcuts.push(shortcut);
renderShortcuts();
saveShortcuts();
nameInput.value = "";
urlInput.value = "";
document.getElementById("modal").style.display = "none";
}
});
// Close modal button click event
var closeButton = document.getElementsByClassName("close")[0];
closeButton.addEventListener("click", function () {
document.getElementById("modal").style.display = "none";
});
// Save shortcuts to local storage
function saveShortcuts() {
localStorage.setItem("shortcuts", JSON.stringify(shortcuts));
}
// Load shortcuts from local storage
function loadShortcuts() {
var storedShortcuts = localStorage.getItem("shortcuts");
if (storedShortcuts) {
shortcuts = JSON.parse(storedShortcuts);
renderShortcuts();
}
}
// Load shortcuts on page load
loadShortcuts();
// Add the new shortcut
var newShortcut = {
name: "SmartWeb",
url: "https://harshitsingh1.github.io/SmartWeb/",
logo: "https://harshitsingh1.github.io/SmartWeb/img/logo.png"
};
shortcuts.push(newShortcut);
var newShortcut2 = {
name: "Outlook",
url: "https://outlook.office.com/mail/inbox",
};
shortcuts.push(newShortcut2);
renderShortcuts();
//collapse sidebar
const collapseButton = document.querySelector('.collapse-button');
const sidebar = document.querySelector('.sidebar');
collapseButton.addEventListener('click', function() {
sidebar.classList.toggle('collapsed');
});
// a function for share links
function shareLink() {
var url = "https://harshitsingh1.github.io/BreakBuddy/";
var title = "Check out this amazing platform!";
var description = "Join the conversation at OpenAI Chat.";
if (navigator.share) {
navigator.share({
title: title,
text: description,
url: url
})
.then(() => console.log('Successfully shared'))
.catch((error) => console.log('Error sharing:', error));
} else {
alert("Sharing is not supported in your browser.");
}
}
// set reminder
function setReminder() {
var timeRange = prompt("Set reminder so that you don't miss your work. \nEnter reminder time (in minutes):");
var minutes = parseInt(timeRange);
if (!isNaN(minutes)) {
var milliseconds = minutes * 60 * 1000;
setTimeout(function() {
var message = minutes + " minutes are over!";
alert(message);
}, milliseconds);
}
}
function toggleIcons() {
var iconsDiv = document.getElementById("socialMediaIcons");
iconsDiv.classList.toggle("hidden");
}
setTimeout(function() {
document.querySelector('.progress').style.width = '10%';
}, 1000);
//hide the progress div when sidebar collapsed
const rankProgress = document.querySelector('.rank-progress');
collapseButton.addEventListener('click', function() {
rankProgress.classList.toggle('hidden');
});