Skip to content

Commit 30883f7

Browse files
author
Bibek Shrestha
committed
notes not available in explore: fixed
1 parent 2a741f1 commit 30883f7

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

scripts/leetcode.js

+21-15
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ document.addEventListener('click', (event) => {
484484
the note should be opened atleast once for this to work
485485
this is because the dom is populated after data is fetched by opening the note */
486486
function getNotesIfAny() {
487+
// there are no notes on expore
488+
if(document.URL.startsWith("https://leetcode.com/explore/")) return "";
489+
487490
notes = '';
488491
notesdiv = document
489492
.getElementsByClassName('notewrap__eHkN')[0]
@@ -493,7 +496,7 @@ function getNotesIfAny() {
493496
if (notesdiv.childNodes[i].childNodes.length == 0) continue;
494497
text = notesdiv.childNodes[i].childNodes[0].innerText;
495498
if (text) {
496-
notes = `${notes}\n${text.trim()}`;
499+
notes = `${notes}\n${text.trim()}`.trim();
497500
}
498501
}
499502
}
@@ -552,20 +555,23 @@ const loader = setInterval(() => {
552555
});
553556

554557
/* get the notes and upload it */
555-
setTimeout(function () {
556-
notes = getNotesIfAny();
557-
if (notes != undefined && notes.length != 0) {
558-
console.log('Create Notes');
559-
// means we can upload the notes too
560-
uploadGit(
561-
btoa(unescape(encodeURIComponent(notes))),
562-
problemName,
563-
'NOTES.txt',
564-
createNotesMsg,
565-
'upload',
566-
);
567-
}
568-
}, 500);
558+
/* only upload notes if there is any */
559+
notes = getNotesIfAny();
560+
if (notes.length > 0) {
561+
setTimeout(function () {
562+
if (notes != undefined && notes.length != 0) {
563+
console.log('Create Notes');
564+
// means we can upload the notes too
565+
uploadGit(
566+
btoa(unescape(encodeURIComponent(notes))),
567+
problemName,
568+
'NOTES.txt',
569+
createNotesMsg,
570+
'upload',
571+
);
572+
}
573+
}, 500);
574+
}
569575

570576
/* Upload code to Git */
571577
setTimeout(function () {

0 commit comments

Comments
 (0)