Skip to content

Commit

Permalink
fixes issue with new site layout breaking functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
arunbhardwaj committed Apr 18, 2024
1 parent f082077 commit acb4a3c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions scripts/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,9 @@ LeetCodeV2.prototype.init = async function () {
async function getSubmissionId() {
return new Promise((resolve, reject) => {
setTimeout(() => {
const submissionId = document.URL.match(/\/(\d+)\/?$/)[1]; // '/problems/two-sum/post-solution?submissionId=999594717'
resolve(submissionId);
}, 100);
const submissionId = document.URL.match(/\/(\d+)\/?$/)[1]; // '/problems/two-sum/submissions/1180327225/'
resolve(submissionId);
}, 300);
});
}
const submissionId = await getSubmissionId();
Expand Down Expand Up @@ -871,11 +871,11 @@ LeetCodeV2.prototype.insertToAnchorElement = function (elem) {
// }
return;
}

if (checkElem(document.getElementsByClassName('ml-auto flex items-center space-x-4'))) {
const target = document.getElementsByClassName('ml-auto flex items-center space-x-4')[0];
// TODO: target within the Run and Submit div regardless of UI position of submit button
let target = document.querySelector('[data-e2e-locator="console-submit-button"]').parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.childNodes
if (checkElem(target)) {
elem.className = 'runcode-wrapper__8rXm';
if (target.childNodes.length > 0) target.childNodes[0].prepend(elem);
target[0].appendChild(elem);
}
};
LeetCodeV2.prototype.markUploaded = function () {
Expand Down Expand Up @@ -1046,12 +1046,15 @@ const observer = new MutationObserver(function (_mutations, observer) {
observer.disconnect();

const leetCode = new LeetCodeV2();
v2SubmitBtn.addEventListener('click', () => loader(leetCode));
textarea.addEventListener('keydown', e => submitByShortcuts(e, leetCode));
if (!!!v2SubmitBtn.onclick) {
v2SubmitBtn.onclick = () => loader(leetCode);
textarea.addEventListener('keydown', e => submitByShortcuts(e, leetCode));
}
}
});

// Submission location
observer.observe(document.body, {
childList: true,
subtree: true,
});
});

0 comments on commit acb4a3c

Please sign in to comment.