-
Notifications
You must be signed in to change notification settings - Fork 137
/
options.js
802 lines (681 loc) · 23.7 KB
/
options.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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
const jrDomain = "https://justread.link/";
/* Use Ace https://ace.c9.io/ to create our CSS editor */
const editor = ace.edit("css-editor");
editor.setTheme("ace/theme/crimson_editor");
editor.session.setOptions({
mode: "ace/mode/css",
tabSize: 2,
});
editor.$blockScrolling = Infinity;
// Enable zooming of the editor itself
editor.commands.addCommands([
{
name: "increaseFontSize",
bindKey: "Ctrl-=|Ctrl-+",
exec: function (editor) {
const size = parseInt(editor.getFontSize(), 10) || 12;
editor.setFontSize(size + 1);
},
},
{
name: "decreaseFontSize",
bindKey: "Ctrl+-|Ctrl-_",
exec: function (editor) {
const size = parseInt(editor.getFontSize(), 10) || 12;
editor.setFontSize(Math.max(size - 1 || 1));
},
},
{
name: "resetFontSize",
bindKey: "Ctrl+0|Ctrl-Numpad0",
exec: function (editor) {
editor.setFontSize(12);
},
},
{
name: "save",
bindKey: "Ctrl+s",
exec: saveTheme,
},
]);
let changed = false,
stylesheetObj = {},
defaultLiItem,
defaultStylesheet = "default-styles.css",
darkStylesheet = "dark-styles.css",
currTheme,
hasAccount = false,
jrSecret,
isPremium = false,
jrLastChecked;
function isEmpty(obj) {
return Object.keys(obj).length === 0;
}
// Given a chrome storage object, add them to our domain list
function setDomains(domains) {
let domainString = "";
for (let i = 0; i < domains.length; i++) {
domainString += domains[i] + "\n";
}
domainList.value = domainString;
}
// Given a chrome storage object, setup our Options page
function getDataFromStorage(storage) {
for (let key in storage) {
if (key === "auto-enable-site-list") {
setDomains(storage[key]);
} else if (key === "hideSegments") {
hideSegments.checked = storage[key];
} else if (key === "summaryReplace") {
summaryReplace.checked = storage[key];
} else if (key === "openSharedPage") {
openSharedPage.checked = storage[key];
} else if (key === "closeOldPage") {
closeOldPage.checked = storage[key];
} else if (key === "enable-pageCM") {
pageCM.checked = storage[key];
} else if (key === "enable-linkCM") {
linkCM.checked = storage[key];
} else if (key === "enable-autorunCM") {
autorunCM.checked = storage[key];
} else if (key === "scrollbar") {
scrollbar.checked = storage[key];
} else if (key === "remove-orig-content") {
removeOrig.checked = storage[key] !== false;
} else if (key === "backup") {
backup.checked = storage[key];
} else if (key === "leave-pres") {
leavePres.checked = storage[key];
} else if (key === "addOrigURL") {
addOrigURL.checked = storage[key];
} else if (key === "addTimeEstimate") {
addTimeEstimate.checked = storage[key];
} else if (key === "alwaysAddAR") {
alwaysAddAR.checked = storage[key];
} else if (key === "autoscroll") {
autoscroll.checked = storage[key];
} else if (key === "scroll-speed") {
scrollSpeed.value = storage[key];
} else if (key === "domainSelectors") {
domainSelectors.value = JSON.stringify(storage[key], null, 4);
} else if (key === "summarizer-options") {
summarizerOptions.value = storage[key];
} else if (key === "currentTheme") {
currTheme = storage[key];
} else if (key === "jrSecret") {
hasAccount = true;
jrSecret = storage[key];
} else if (key === "isPremium") {
isPremium = storage[key];
} else if (key === "jrLastChecked") {
jrLastChecked = storage[key];
} else if (key.substring(0, 3) === "jr-") {
// Get the user's stylesheets
stylesheetObj[key.substring(3)] = storage[key];
}
}
}
// Set the chrome storage based on our stylesheet object
function setStylesOfStorage(nextFunc) {
for (let stylesheet in stylesheetObj) {
const obj = {};
obj["jr-" + stylesheet] = stylesheetObj[stylesheet];
chrome.storage.sync.set(obj, function () {
if (
chrome.runtime.lastError &&
chrome.runtime.lastError.message ===
"QUOTA_BYTES_PER_ITEM quota exceeded"
) {
chrome.runtime
.getBackgroundPage()
.alert(
"File did not save: Your stylesheet is too big. Minifying it or removing lesser-used entries may help.\n\nYou can minify it at: https://cssminifier.com/"
);
} else {
if (nextFunc) nextFunc();
}
});
}
}
// Remove a given element from chrome storage
function removeStyleFromStorage(stylesheet) {
chrome.storage.sync.remove(stylesheet);
}
// Detect double click - pulled from http://stackoverflow.com/a/26296759/2065702
function makeDoubleClick(doubleClickCallback, singleClickCallback) {
return (function () {
let clicks = 0,
timeout;
return function () {
const me = this;
clicks++;
if (clicks == 1) {
singleClickCallback && singleClickCallback.apply(me, arguments);
timeout = setTimeout(function () {
clicks = 0;
}, 400);
} else {
timeout && clearTimeout(timeout);
doubleClickCallback && doubleClickCallback.apply(me, arguments);
clicks = 0;
}
};
})();
}
// Check to make sure there isn't a file with this name already. If so, add a number to the end
function checkFileName(fileName) {
let tempName = fileName,
count = 1;
while (stylesheetObj[tempName])
tempName = fileName.replace(/(\.[\w\d_-]+)$/i, "(" + count++ + ").css");
return tempName;
}
// Allow file names to be edited
function rename() {
const liItem = this;
// Hide the list item
liItem.style.display = "none";
// Insert an input temporarily
const fileNameInput = document.createElement("input");
fileNameInput.type = "text";
fileNameInput.value = fileNameInput.dataset.originalName = liItem.innerText;
// Update the style sheet object on blur
fileNameInput.onblur = function () {
// If the file name has changed
if (fileNameInput.value != fileNameInput.dataset.originalName) {
fileNameInput.value = checkFileName(fileNameInput.value);
stylesheetObj[fileNameInput.value] = stylesheetObj[liItem.innerText];
delete stylesheetObj[liItem.innerText];
removeStyleFromStorage("jr-" + liItem.innerText);
setTimeout(function () {
saveTheme();
}, 10);
liItem.innerText = fileNameInput.value;
}
// Un-hide the list item
liItem.style.display = "list-item";
// Remove the input
fileNameInput.parentNode.removeChild(fileNameInput);
};
// Allow enter to be used to save the rename
fileNameInput.onkeyup = function (e) {
if (e.key === "Enter") fileNameInput.onblur();
};
if (liItem.nextSibling) {
liItem.parentNode.insertBefore(fileNameInput, liItem.nextSibling);
} else {
liItem.parentNode.appendChild(fileNameInput);
}
fileNameInput.focus();
}
// Make sure the user wants to change files before saving
function confirmChange() {
if (changed)
if (
chrome.runtime
.getBackgroundPage()
.confirm("Do you really want to change files before saving?")
)
return false;
else return true;
else return false;
}
function styleListOnClick() {
// Don't do anything if it's already active
if (!this.classList.contains("active")) {
const cancel = confirmChange();
if (!cancel) {
// Switch out current CSS for the selected one
const fileName = this.textContent;
// Open up the file from localStorage
editor.setValue(
stylesheetObj[fileName] === undefined ? "" : stylesheetObj[fileName],
-1
);
// Toggle the active class on the list items
if (document.querySelector(".stylesheets .active"))
document
.querySelector(".stylesheets .active")
.classList.remove("active");
this.classList.add("active");
localStorage.currentTheme = fileName;
changed = false;
}
}
}
// The stuff to fire after the stylesheets have been loaded
function continueLoading() {
if (typeof stylesheetObj[darkStylesheet] === "undefined") {
// If the dark theme isn't found, add it
const xhr = new XMLHttpRequest();
xhr.overrideMimeType("text/css");
xhr.open("GET", chrome.runtime.getURL(darkStylesheet), true);
xhr.onreadystatechange = function () {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
// Save the file's contents to our object
stylesheetObj[darkStylesheet] = xhr.responseText;
// Save it to Chrome storage
setStylesOfStorage();
}
};
xhr.send();
}
if (
jrSecret &&
(typeof jrLastChecked === "undefined" ||
Date.now() - jrLastChecked > 86400000)
) {
chrome.storage.sync.set({ jrLastChecked: Date.now() });
fetch(jrDomain + "checkPremium", {
mode: "cors",
method: "POST",
headers: { "Content-type": "application/json; charset=UTF-8" },
body: JSON.stringify({
jrSecret: jrSecret,
}),
})
.then(function (response) {
if (!response.ok) throw response;
else return response.text();
})
.then((response) => {
isPremium = response === "true";
chrome.storage.sync.set({ isPremium: isPremium });
finishLoading();
})
.catch((err) => console.error(`Fetch Error =\n`, err));
} else {
finishLoading();
}
}
function finishLoading() {
// Get the currently used stylesheet
currTheme = currTheme || defaultStylesheet;
// Based on that object, populate the list values
const list = document.querySelector(".stylesheets");
for (let stylesheet in stylesheetObj) {
const li = document.createElement("li"),
liClassList = li.classList;
// If the sheet is the one currently applied, add a signifier class
if (stylesheet === currTheme) {
liClassList.add("used");
}
// Add them to the li element
li.innerText += stylesheet;
// Lock the default-styles.css file (prevent deletion)
if (stylesheet === defaultStylesheet || stylesheet === darkStylesheet) {
defaultLiItem = li;
liClassList.add("locked");
}
// Make the current one active
if (stylesheet === currTheme) {
liClassList.add("active");
const fileName = li.textContent;
editor.setValue(
stylesheetObj[fileName] === undefined ? "" : stylesheetObj[fileName],
-1
);
}
list.appendChild(li);
}
stylesheetListItems = document.querySelectorAll(".stylesheets li");
stylesheetListItems.forEach(function (item, i) {
if (!item.classList.contains("locked"))
item.onclick = makeDoubleClick(rename, styleListOnClick);
// Prevent the locked items from being changed in name
else item.onclick = styleListOnClick;
});
// Keep track of changes since last save
editor.on("change", function () {
if (editor.curOp && editor.curOp.command.name) changed = true;
});
if (isPremium) {
allowPremiumStuff();
}
addEventListeners();
}
function allowPremiumStuff() {
document.querySelector(".options-subtitle").style.display = "block";
document.querySelector(".upgrade").style.display = "none";
document
.querySelectorAll(".disabled")
.forEach((el) => el.classList.remove("disabled"));
}
// Obtain the stylesheet strings from localStorage and put them in our stylesheet object
function getStylesheets() {
chrome.storage.sync.get(null, function (result) {
// Setup our options page based on the user's Chrome storage
getDataFromStorage(result);
if (isEmpty(stylesheetObj)) {
// Not found, so we add our default
// Open the default CSS file and save it to our object
const xhr = new XMLHttpRequest();
xhr.overrideMimeType("text/css");
xhr.open("GET", chrome.runtime.getURL(defaultStylesheet), true);
xhr.onreadystatechange = function () {
if (xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
// Save the file's contents to our object
stylesheetObj[defaultStylesheet] = xhr.responseText;
// Save it to Chrome storage
setStylesOfStorage();
continueLoading();
}
};
xhr.send();
return;
} else {
continueLoading();
}
});
}
function continueSaving() {
const currFileElem = document.querySelector(".stylesheets .active");
if (currFileElem.classList.contains("locked")) {
// The file is locked, so make a new one with the same name
const fileName = checkFileName(currFileElem.innerText);
// Add a new list element
const list = document.querySelector(".stylesheets"),
li = document.createElement("li");
li.innerText += fileName;
// Make it active
if (document.querySelector(".stylesheets .active"))
document.querySelector(".stylesheets .active").classList.remove("active");
li.classList.add("active");
// Force them to save to keep it
changed = true;
list.appendChild(li);
document.querySelector(".stylesheets").lastChild.onclick = makeDoubleClick(
rename,
styleListOnClick
);
// Update our stylesheet storage
useTheme();
}
// Show the save animation
saveButton.classList.add("saved");
// Note that the file has been saved
changed = false;
}
function saveTheme() {
// Get the name of the current file being edited
const currFileElem = document.querySelector(".stylesheets .active");
// Save that file to localStorage
if (!currFileElem.classList.contains("locked")) {
stylesheetObj[currFileElem.innerText] = editor.getValue();
}
setStylesOfStorage(continueSaving);
}
function useTheme() {
const themeToUse = document.querySelector(".stylesheets .active"),
previouslyUsed = document.querySelector(".stylesheets .used");
// Save the current theme
if (!themeToUse.classList.contains("locked")) saveTheme();
// Remove the used class from the old list item
if (previouslyUsed !== null) previouslyUsed.classList.remove("used");
// Update the class to show it's applied
themeToUse.classList.add("used");
// Apply the current theme
const sheet = themeToUse.innerText;
chrome.storage.sync.set({ currentTheme: sheet });
// Tell that we changed it
useButton.classList.add("used");
// Add the listener for the use animation
useButton.addEventListener("animationend", function () {
useButton.classList.remove("used");
});
useButton.addEventListener("webkitAnimationEnd", function () {
useButton.classList.remove("used");
});
}
function addEventListeners() {
// Update the domain list with any new values
domainList.onkeyup = function (e) {
const domainLine = domainList.value.split("\n").filter(String);
chrome.storage.sync.set({ "auto-enable-site-list": domainLine });
};
// Update the OpenAI params
summarizerOptions.onkeyup = function (e) {
chrome.storage.sync.set({ "summarizer-options": summarizerOptions.value });
};
// Update the domain-specific selectors list
domainSelectors.onkeyup = function (e) {
if (isPremium) {
const domainSelectorArr = JSON.parse(domainSelectors.value);
chrome.storage.sync.set({ domainSelectors: domainSelectorArr });
} else {
showPremiumNotification();
}
};
// Allow the "Enter" key to be used to add new stylesheets
newFileInput.onkeyup = function (e) {
if (e.key === "Enter") add.onclick();
};
// Create a new file with the given name
add.onclick = function () {
if (newFileInput.value !== "") {
let fileName = newFileInput.value;
// If it has .css at the end, remove it
if (fileName.slice(-4) === ".css") fileName = fileName.slice(0, -4);
// Parse out the other stuff we don't want and add .css
fileName = fileName.replace(/[^a-z0-9]/gi, "-").toLowerCase() + ".css";
// If there's already a file with this name, change it
fileName = checkFileName(fileName);
// Add a new list element
const list = document.querySelector(".stylesheets"),
li = document.createElement("li");
li.innerText = fileName;
// Make it active
if (document.querySelector(".stylesheets .active"))
document
.querySelector(".stylesheets .active")
.classList.remove("active");
li.classList.add("active");
// Clear out the editor and add some smart defaults
editor.setValue(
"/* Some defaults you may want */\n.simple-container {\n max-width: 600px;\n margin: 0 auto;\n padding-top: 70px;\n padding-bottom: 20px;\n}\nimg { max-width: 100%; }\n/* Also keep in mind that the close button is by default black. */\n\n\n",
-1
);
// Force them to save to keep it
changed = true;
list.appendChild(li);
document.querySelector(".stylesheets").lastChild.onclick =
makeDoubleClick(rename, styleListOnClick);
// Update our stylesheet storage
saveTheme();
newFileInput.value = "";
}
};
// Save the current code to the current file
saveButton.onclick = saveTheme;
// Use the selected stylesheet
useButton.onclick = useTheme;
// Remove the selected file
removeButton.onclick = function () {
// Select the item to be removed
const elem = document.querySelector(".stylesheets .active");
// Make sure they can't delete locked files
if (!elem.classList.contains("locked")) {
// Add confimation
if (window.confirm("Do you really want to remove this file?")) {
// Remove the file from our object
delete stylesheetObj[
document.querySelector(".stylesheets .active").innerText
];
// Remove the file from Chrome's storage
removeStyleFromStorage("jr-" + elem.innerText);
// Check to see if it's the currently used sheet - if so set it to the default
if (elem.classList.contains("used")) {
elem.classList.remove("active");
chrome.storage.sync.set(
{ currentTheme: defaultStylesheet },
function () {
styleListOnClick.call(defaultLiItem);
defaultLiItem.classList.add("used", "active");
}
);
}
// Remove it from the list
elem.parentNode.removeChild(elem);
editor.setValue("", -1);
}
} else
chrome.runtime
.getBackgroundPage()
.alert("This file is locked and cannot be deleted.");
// Otherwise we do nothing
};
hideSegments.onchange = function () {
chrome.storage.sync.set({ hideSegments: this.checked });
};
summaryReplace.onchange = function () {
chrome.storage.sync.set({ summaryReplace: this.checked });
};
openSharedPage.onchange = function () {
if (isPremium) {
chrome.storage.sync.set({ openSharedPage: this.checked });
if (this.checked) {
closeOldPage.disabled = false;
} else {
closeOldPage.disabled = true;
}
} else {
showPremiumNotification();
}
};
closeOldPage.onchange = function () {
if (isPremium) {
chrome.storage.sync.set({ closeOldPage: this.checked });
} else {
showPremiumNotification();
}
};
pageCM.onchange = function () {
chrome.storage.sync.set({ "enable-pageCM": this.checked });
chrome.runtime.sendMessage({ updateCMs: "true" });
};
linkCM.onchange = function () {
chrome.storage.sync.set({ "enable-linkCM": this.checked });
chrome.runtime.sendMessage({ updateCMs: "true" });
};
autorunCM.onchange = function () {
chrome.storage.sync.set({ "enable-autorunCM": this.checked });
chrome.runtime.sendMessage({ updateCMs: "true" });
};
alwaysAddAR.onchange = function () {
chrome.storage.sync.set({ alwaysAddAR: this.checked });
};
autoscroll.onchange = function () {
if (isPremium) {
chrome.storage.sync.set({ autoscroll: this.checked });
} else {
showPremiumNotification();
}
};
scrollSpeed.onkeyup = scrollSpeed.onkeydown = function () {
if (isPremium) {
chrome.storage.sync.set({ "scroll-speed": parseFloat(this.value) });
} else {
showPremiumNotification();
}
};
const removeOrig = document.getElementById("removeOrig"),
backup = document.getElementById("backup"),
leavePres = document.getElementById("leavePres"),
addOrigURL = document.getElementById("addOrigURL"),
addTimeEstimate = document.getElementById("addTimeEstimate"),
scrollbar = document.getElementById("scrollbar");
removeOrig.onchange = function () {
chrome.storage.sync.set({ "remove-orig-content": this.checked });
};
backup.onchange = function () {
chrome.storage.sync.set({ backup: this.checked });
};
leavePres.onchange = function () {
chrome.storage.sync.set({ "leave-pres": this.checked });
};
addOrigURL.onchange = function () {
chrome.storage.sync.set({ addOrigURL: this.checked });
};
addTimeEstimate.onchange = function () {
chrome.storage.sync.set({ addTimeEstimate: this.checked });
};
scrollbar.onchange = function () {
if (isPremium) {
chrome.storage.sync.set({ scrollbar: this.checked });
} else {
showPremiumNotification();
}
};
// Add the listener for the save animation
saveButton.addEventListener("animationend", function () {
saveButton.classList.remove("saved");
});
saveButton.addEventListener("webkitAnimationEnd", function () {
saveButton.classList.remove("saved");
});
}
const newFileInput = document.getElementById("new-file"),
addButton = document.getElementById("add"),
saveButton = document.getElementById("save"),
useButton = document.getElementById("use"),
removeButton = document.getElementById("remove"),
domainList = document.getElementById("domainList"),
domainSelectors = document.querySelector(".domainSelectors"),
summarizerOptions = document.getElementById("summarizerOptions");
let stylesheetListItems;
const hideSegments = document.getElementById("hideSegments"),
summaryReplace = document.getElementById("summaryReplace"),
openSharedPage = document.getElementById("openSharedPage"),
closeOldPage = document.getElementById("closeOldPage"),
pageCM = document.getElementById("pageCM"),
linkCM = document.getElementById("linkCM"),
autorunCM = document.getElementById("autorunCM"),
alwaysAddAR = document.getElementById("alwaysAddAR"),
autoscroll = document.getElementById("autoscroll"),
scrollSpeed = document.querySelector("[name='scrollSpeed']");
getStylesheets();
function createNotification(options) {
const oldNotification = document.querySelector(".jr-notifier");
if (oldNotification)
oldNotification.parentElement.removeChild(oldNotification);
const notifier = document.createElement("div");
notifier.className = "jr-tooltip jr-notifier";
const notificationText = document.createElement("p");
notificationText.innerHTML = options.textContent;
const btnContainer = document.createElement("div");
btnContainer.className = "right-align-buttons";
const secondaryBtn = document.createElement("button");
secondaryBtn.className = "jr-secondary";
secondaryBtn.addEventListener(
"click",
function () {
this.parentNode.parentNode.parentNode.removeChild(
this.parentNode.parentNode
);
},
{ once: true }
);
secondaryBtn.innerText = options.secondaryText;
const primaryLink = document.createElement("a");
primaryLink.href = options.url;
primaryLink.target = "_blank";
const primaryBtn = document.createElement("button");
primaryBtn.className = "jr-primary";
primaryBtn.innerText = options.primaryText;
primaryLink.appendChild(primaryBtn);
btnContainer.appendChild(secondaryBtn);
btnContainer.appendChild(primaryLink);
notifier.appendChild(notificationText);
notifier.appendChild(btnContainer);
document.body.appendChild(notifier);
}
function showPremiumNotification() {
const notification = {
textContent:
"To access this feature, upgrade to <a href='https://justread.link/#get-Just-Read' target='_blank'>Just Read Premium</a>!",
url: "https://justread.link/#get-Just-Read",
primaryText: "Learn more",
secondaryText: "Maybe later",
};
createNotification(notification);
}