This repository has been archived by the owner on Aug 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
449 lines (428 loc) · 11.7 KB
/
index.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
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
// const api_url = 'https://zenquotes.io/api/quotes/';
let i = 0;
function pack(data) {
// For Static Quotes
i = i + 1;
const rndInt = i;
myText = {
author: data[rndInt].author,
quote: data[rndInt].text,
};
$('#text').html(`<p> <q> ${myText.quote} </q></p>`);
$('#author').text(myText.author);
$('.dater').text(`Generated ${today}`);
$('#tweet-quote').attr(
'href',
'https://twitter.com/intent/tweet?hashtags=quotes&related=Dev_Obele&text=' +
encodeURIComponent('“' + myText.quote + '” —' + myText.author)
);
$('#whatsapp-quote').attr(
'href',
'whatsapp://send?text=' +
encodeURIComponent('“' + myText.quote + '” —' + myText.author)
);
}
// Fix for blocked by CORS policy
async function fetchWithCORS(url) {
const response = await fetch(url, {
method: 'GET',
headers: {
'Access-Control-Allow-Origin': '*',
},
});
if (response.status === 200) {
return response;
} else {
throw new Error(response.statusText);
}
}
async function main() {
const responses = await fetchWithCORS('https://type.fit/api/quotes');
try {
const data = await responses.json();
pack(data);
console.log(data);
} catch (error) {
console.log('Error:', error);
}
}
main();
var myText,
dataList = [];
//Get Quotes API
function getapi() {
$('.spinner-border').addClass('hider');
dataList.push(data);
const today = new Date().toLocaleString('en-US', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: true,
});
/*Author List for this other API*/
var authorList2 = (datum) => {
var authors2 = [];
for (let i = 0; i < datum[0].length; i++) {
authors2.push(datum[0][i].a);
}
var SetAuthor2 = new Set(authors2);
var ArrAuthor2 = Array.from(SetAuthor2);
ArrAuthor2.map((x) => {
$('#datalistOptions').append(`<option value="${x}">`);
});
};
$('#searchBtn').click(function () {
var author = $('input').val();
filtered2 = dataList[0].filter((datum) => datum.a == author);
filtered2.map((x) =>
$('.deList').append(
`<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto tag"> ${x.q} — ${x.a} </div>
</li>`
)
);
}); // Calling the functions
authorList2(dataList);
pack();
$('#new-quote').click(function () {
$('#copy-quote').attr('data-bs-original-title', 'Copy this quote!');
pack();
});
}
var clickNum = 0;
$(document).ready(function () {
getapi(api_url);
$('#copy-quote').attr('data-bs-original-title', 'Copy this quote!');
// Reloading the page
$('#new-quote').click(function () {
clickNum = ++clickNum;
if (clickNum == 48) {
window.location.reload();
clickNum = 0;
}
});
// clipboard func
function copyToClipboard() {
var text = myText;
var sampleTextarea = document.createElement('textarea');
document.body.appendChild(sampleTextarea);
sampleTextarea.value = `“${text.quote}” — ${text.author}`; //save main text in it
sampleTextarea.select(); //select textarea contents
document.execCommand('copy');
document.body.removeChild(sampleTextarea);
}
// end of func
// calling clipboard func
$('.copy').click(function () {
copyToClipboard();
$('#copy-quote').attr('data-bs-original-title', 'Copied!');
$('#copy-quote').tooltip('show');
});
$('.altcls').click(function () {
$('#copyToast').toggleClass('show');
});
});
// See Changes Btn
$(document).ready(function () {
$('.toclose').click(function () {
$('#liveToastBtn').removeClass('vis');
$('#liveToast').toggleClass('show');
});
$('#liveToastBtn').click(function () {
$('#liveToast').toggleClass('show');
$('#liveToastBtn').addClass('vis');
$('#liveToast').toast({ autohide: false });
});
});
//Toast functions And Other Bootstrap Items
$(document).ready(function () {
// Initialize tooltips
var tooltipTriggerList = [].slice.call(
document.querySelectorAll('[data-bs-toggle="tooltip"]')
);
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
var collapseElementList = [].slice.call(
document.querySelectorAll('.collapse')
);
var collapseList = collapseElementList.map(function (collapseEl) {
return new bootstrap.Collapse(collapseEl);
});
});
// Change Font Func
$(document).ready(function () {
var fontList = [];
var randomFont = (font) => {
for (let i = 0; i < font.length; i++) {
fontList.push(randomFont[i]);
}
};
randomFont = [
'Permanent Marker',
'Rock Salt',
'Raleway',
'PT Sans',
'Lora',
'Roboto Condensed',
'Oswald',
'Open Sans Condensed',
'Merriweather',
'Ubuntu',
'Yanone Kaffeesatz',
'Roboto',
'Alegreya',
'Dancing Script',
'EB Garamond',
'Amatic SC',
'Josefin Sans',
'Droid Seri',
'Playfair Display',
'Alice',
'Lato',
'Grand Hotel',
'Abel',
'Coustard',
'Leckerli On',
];
let i = 0;
var changeFont = () => {
var random_font = randomFont[i];
i = i + 1;
$('.Dqoute').css('font-family', random_font);
};
changeFont();
$('#new-quote').click(function () {
changeFont();
});
});
// End Change Font Func
// Change Colors
$(document).ready(function () {
var colors = [];
var genColor = (color) => {
for (let i = 0; i < color.length; i++) {
colors.push('#' + color[i]);
}
};
genColor([
'39C0ED',
'ff0000',
'd9534f',
'1266F1',
'B23CFD',
'00B74A',
'FFA900',
'283593',
'004D40',
'FB8C00',
'BF360C',
'FF3D00',
'F93154',
'FF6D00',
'00C853',
'33691E',
'1B5E20',
'004D40',
'006064',
'6200EA',
'4A148C',
'311B92',
'e7aa0a',
'8f549f',
'80b4f0',
'acabcf',
'162ea0',
'f49ccc',
'c390af',
'eb7424',
]);
const colorCode = () => {
var random_color = colors[Math.floor(Math.random() * colors.length)];
$('#new-quote').css('background-color', random_color);
$('.tweet').css('background-color', random_color);
$('.btn').css('background-color', `${random_color} !important`);
$('.copy').css('background-color', random_color);
$('.whatsapp').css('background-color', random_color);
$('.change_col').css('background-color', random_color);
$('.light').css('background-color', random_color);
$('.dark').css('background-color', random_color);
$('body').css('background-color', random_color);
$('.badgeCol').css('background-color', random_color);
};
colorCode();
$('#new-quote').click(function () {
colorCode();
});
$('.change_col').click(function () {
colorCode();
});
});
// end of Change Colors
// For the Search Quote
const settings = {
async: true,
crossDomain: true,
url: 'https://type.fit/api/quotes',
method: 'GET',
};
$.ajax(settings).done(function (response) {
var datar = JSON.parse(response);
// For Dynamic Quotes
const Dynamic = () => {
const rndNo = Math.floor(Math.random() * 15) + 1;
$('blockquote').html(`<p>${datar[rndNo].text}</p>
<footer class="blockquote-footer">
<cite title="Source Title">${datar[rndNo].author}</cite>
</footer>`);
};
// Replace Text
Dynamic();
let timer = setInterval(Dynamic, 8500);
/* Author List for FreeCodeCamp API */
var authorList = (datum) => {
var authors = [];
for (let i = 0; i < datum.length; i++) {
authors.push(datum[i].author);
}
var SetAuthor = new Set(authors);
var ArrAuthor = Array.from(SetAuthor);
ArrAuthor.map((x) => {
$('#datalistOptions').append(`<option value="${x}">`);
});
};
authorList(datar);
//Click Search Button function
$('#searchBtn').click(function () {
var author = $('input').val();
filtered = datar.filter((datum) => datum.author == author);
filtered2 = dataList[0].filter((datum) => datum.a == author);
if (filtered2.length == 0 && filtered.length == 0) {
$('.deList').text('');
$('.deList').append(
`<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto tag"> Please try a different name. </div>
</li>`
);
} else {
$('.deList').text('');
filtered.map((x) =>
$('.deList').append(
`<li class="list-group-item d-flex justify-content-between align-items-start">
<div class="ms-2 me-auto tag"> ${x.text} — ${x.author} </div>
</li>`
)
);
}
});
});
//Redux: For Dark Mode
// LocalStorage
const loadState = () => {
try {
const serialState = localStorage.getItem('appState');
if (serialState === null) {
return undefined;
}
return JSON.parse(serialState);
} catch (err) {
return undefined;
}
};
const persistedState = loadState();
const saveState = (state) => {
try {
const serialState = JSON.stringify(state);
localStorage.setItem('appState', serialState);
} catch (err) {
console.log(err);
}
};
// End!
// Initial State
const initialState = { DarkMode: false, persistedState };
const reducer = (state = initialState.DarkMode, action) => {
switch (action.type) {
case 'LIGHT':
return false;
case 'DARK':
return true;
default:
return state;
}
};
const store = Redux.createStore(
reducer,
persistedState
// window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
// Wire click events to actions
$(document).ready(function () {
$('.dark').click(function () {
window.location.reload();
store.dispatch({ type: 'DARK' });
});
$('.light').click(function () {
window.location.reload();
store.dispatch({ type: 'LIGHT' });
});
const Mood = () => {
if (store.getState().DarkMode) {
return { bcol: 'black', tcol: 'white' };
} else {
return { bcol: 'white', tcol: 'black' };
}
};
const change = () => {
if (store.getState().DarkMode) {
$('.dark').hide();
$('.light').show();
$('.footer > a').css('border-color', Mood().tcol);
$('.navbar').addClass('navbar-dark');
$('.navbar').addClass('bg-dark');
$('.footer').removeClass('bg-light');
$('.footer > a').removeClass('text-dark');
$('.footer').addClass('bg-dark');
$('.footer > .text-center').removeClass('text-dark');
$('.footer > .text-center > a').removeClass('text-dark');
$('.footer > .text-center > a').addClass('text-light');
} else {
$('.light').hide();
$('.dark').show();
$('.footer > a').css('border-color', Mood().tcol);
$('.navbar').removeClass('navbar-dark');
$('.navbar').removeClass('bg-dark');
$('.footer').addClass('bg-light');
$('.footer > a').addClass('text-dark');
$('.footer > .text-center').addClass('text-dark');
$('.footer > .text-center > a').addClass('text-dark');
$('.footer').removeClass('bg-dark');
}
};
$('.card').css('background-color', Mood().bcol);
$('h1').css('color', Mood().tcol);
$('h2').css('color', Mood().tcol);
$('#new-quote').css('color', Mood().tcol);
$('.copy').css('color', Mood().tcol);
$('.whatsapp').css('color', Mood().tcol);
$('.tweet').css('color', Mood().tcol);
$('.card').css('color', Mood().tcol);
$('.list-group').css('background-color', Mood().bcol);
$('.form-control').css('background-color', Mood().bcol);
$('.form-control').css('color', Mood().tcol);
change();
store.subscribe(() => {
$('.card').css('background-color', Mood().bcol);
$('.list-group').css('background-color', Mood().bcol);
$('.form-control').css('background-color', Mood().bcol);
$('.form-control').css('color', Mood().tcol);
change();
saveState({
DarkMode: store.getState(),
});
});
});
// End of Redux Function