Skip to content

Commit

Permalink
Merge pull request QasimWani#117 from sbibek/dev
Browse files Browse the repository at this point in the history
feature: pull the notes and push it to git repo
  • Loading branch information
QasimWani authored Aug 10, 2021
2 parents 76f1dbf + 17123f3 commit 3b14311
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions scripts/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const languages = {
/* Commit messages */
const readmeMsg = 'Create README - LeetHub';
const discussionMsg = 'Prepend discussion post - LeetHub';
const createNotesMsg = 'Create NOTES - LeetHub';

/* Difficulty of most recenty submitted question */
let difficulty = '';
Expand Down Expand Up @@ -479,6 +480,26 @@ document.addEventListener('click', (event) => {
}
});

/* function to get the notes if there is any
the note should be opened atleast once for this to work
this is because the dom is populated after data is fetched by opening the note */
function getNotesIfAny() {
notes = '';
notesdiv = document
.getElementsByClassName('notewrap__eHkN')[0]
.getElementsByClassName('CodeMirror-code')[0];
if (notesdiv) {
for (i = 0; i < notesdiv.childNodes.length; i++) {
if (notesdiv.childNodes[i].childNodes.length == 0) continue;
text = notesdiv.childNodes[i].childNodes[0].innerText;
if (text) {
notes = `${notes}\n${text.trim()}`;
}
}
}
return notes.trim();
}

const loader = setInterval(() => {
let code = null;
let probStatement = null;
Expand Down Expand Up @@ -530,6 +551,22 @@ const loader = setInterval(() => {
}
});

/* get the notes and upload it */
setTimeout(function () {
notes = getNotesIfAny();
if (notes != undefined && notes.length != 0) {
console.log('Create Notes');
// means we can upload the notes too
uploadGit(
btoa(unescape(encodeURIComponent(notes))),
problemName,
'NOTES.txt',
createNotesMsg,
'upload',
);
}
}, 500);

/* Upload code to Git */
setTimeout(function () {
findCode(
Expand Down

0 comments on commit 3b14311

Please sign in to comment.