Skip to content

Commit

Permalink
fixed the upload progress on explore submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibek Shrestha committed Aug 10, 2021
1 parent 3b14311 commit 2a741f1
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions scripts/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,22 +600,40 @@ function startUploadCountDown() {
}
}, 10000);
}
/* start upload will inject a spinner on left side to the "Run Code" button */
function startUpload() {
elem = document.getElementById('leethub_progress_anchor_element')
if (elem !== undefined) {
elem = document.createElement('span')
elem.id = "leethub_progress_anchor_element"

/* we will need specific anchor element that is specific to the page you are in Eg. Explore */
function insertToAnchorElement(elem){
if(document.URL.startsWith("https://leetcode.com/explore/")) {
// means we are in explore page
target = document.getElementsByClassName('action')[0].getElementsByClassName('row')[0].getElementsByClassName('col-sm-6')[1]
elem.className = "pull-left"
target.childNodes[0].prepend(elem)

} else {
target = document.getElementsByClassName('action__38Xc')[0]
elem.className = "runcode-wrapper__8rXm"
elem.style = "margin-right: 20px;padding-top: 2px;"
}
elem.innerHTML = `<div id="leethub_progress_elem" class="leethub_progress"></div>`
target = document.getElementsByClassName('action__38Xc')[0]
if (target.childNodes.length > 0) {
target.childNodes[0].prepend(elem)
}
// start the countdown
startUploadCountDown();
}

/* start upload will inject a spinner on left side to the "Run Code" button */
function startUpload() {
try {
elem = document.getElementById('leethub_progress_anchor_element')
if (elem !== undefined) {
elem = document.createElement('span')
elem.id = "leethub_progress_anchor_element"
elem.style = "margin-right: 20px;padding-top: 2px;"
}
elem.innerHTML = `<div id="leethub_progress_elem" class="leethub_progress"></div>`
target = insertToAnchorElement(elem)
// start the countdown
startUploadCountDown();
} catch (error) {
// generic exception handler for time being so that existing feature doesnt break but
// error gets logged
console.log(error);
}
}

/* This will create a tick mark before "Run Code" button signalling LeetHub has done its job */
Expand Down

0 comments on commit 2a741f1

Please sign in to comment.