Skip to content

Commit

Permalink
Merge pull request #28 from itsluminous/main
Browse files Browse the repository at this point in the history
manual submit button can now be clicked
  • Loading branch information
raphaelheinz authored Mar 20, 2024
2 parents c72cf59 + be247a2 commit ec9deb5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ LeetHub-3.0 works with two different Leetcode UIs. There are known issues when u

Your submission may not be successfully uploaded to GitHub if you update the text in the editor too fast. It is necessary to wait for 4 seconds (until the spinner stops) after submitting the solution before entering new characters, switching languages, or switching editors. During this period, your solution is being pushed to GitHub, and the website should maintain its layout without alteration. While this process is less than ideal, we have not found a better solution so far. Sorry for this inconvenience! If you find a fix, your PRs are welcome!

In the meantime, we have added a manual synchronization button. To trigger a manual synchronization to GitHub, hover with you mouse over this button. Then, a confirmation dialog will open. Please do only use the manual sync button after you have successfully submitted your solution to Leetcode. Please do not click on the button as it breaks its functionality (only hover on it). If you accidentally clicked on the manual synchronization button, please resubmit your solution to Leetcode.
In the meantime, we have added a manual synchronization button next to notes icon. Please use the manual sync button only after you have successfully submitted your solution to Leetcode.


## Installation
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "LeetHub v3",
"description": "Automatically integrate your Leetcode & GeeksforGeeks submissions to GitHub",
"homepage_url": "https://github.com/raphaelheinz/LeetHub-3.0",
"version": "0.0.11",
"version": "0.0.12",
"author": "Raphael Heinz",
"action": {
"default_icon": "assets/thumbnail.png",
Expand Down
44 changes: 20 additions & 24 deletions scripts/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const upload = (token, hook, code, problem, filename, sha, commitMsg, cb = undef

const getAndInitializeStats = problem => {
return chrome.storage.local.get('stats').then(({ stats }) => {
if (stats == null || stats === {}) {
if (stats == null || stats == {}) {
// create stats object
stats = {};
stats.solved = 0;
Expand Down Expand Up @@ -666,16 +666,13 @@ function LeetCodeV2() {
this.injectSpinnerStyle();
}
LeetCodeV2.prototype.init = async function () {
async function getSubmissionId() {
return new Promise((resolve, reject) => {
setTimeout(() => {
const submissionsId = document.URL.match(/\/(\d+)(\/|\?|$)/);
if (submissionsId !== null){
resolve(submissionsId[1]); // '/problems/two-sum/post-solution?submissionId/999594717
}}, 4000);
});
const problem = document.URL.match(/leetcode.com\/problems\/([^\/]*)\//);
const val = await chrome.storage.local.get(problem[1]);
if(!val){
alert("Have you submitted this problem yet?");
return false;
}
const submissionId = await getSubmissionId();
const submissionId = val[problem[1]]

// Query for getting the solution runtime and memory stats, the code, the coding language, the question id, question title and question difficulty
const submissionDetailsQuery = {
Expand Down Expand Up @@ -949,19 +946,7 @@ LeetCodeV2.prototype.addManualSubmitButton = function () {
submitButton.className = 'relative inline-flex gap-2 items-center justify-center font-medium cursor-pointer focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50 transition-colors bg-transparent enabled:hover:bg-fill-secondary enabled:active:bg-fill-primary text-caption rounded text-text-primary group ml-auto p-1';
submitButton.textContent = 'Push ';
submitButton.appendChild(getGitIcon());

let timer;
submitButton.addEventListener('mouseenter', () => {
timer = setTimeout(() => {
var confirmDialog = confirm('Push code to GitHub?');
if (confirmDialog) {
loader(this);
}
}, 300);
});
submitButton.addEventListener('mouseleave', () => {
clearTimeout(timer);
});
submitButton.addEventListener('click', () => loader(this));

let notesIcon = document.querySelectorAll('.ml-auto svg.fa-bookmark');
if (checkElem(notesIcon)) {
Expand All @@ -970,6 +955,16 @@ LeetCodeV2.prototype.addManualSubmitButton = function () {
}
};

LeetCodeV2.prototype.addUrlChangeListener = function () {
window.navigation.addEventListener("navigate", (event) => {
const problem = window.location.href.match(/leetcode.com\/problems\/(.*)\/submissions/);
const submissionId = window.location.href.match(/\/(\d+)(\/|\?|$)/);
if(problem && problem.length > 1 && submissionId && submissionId.length > 1){
chrome.storage.local.set({ [problem[1]]: submissionId[1] });
}
})
};

/* Sync to local storage */
chrome.storage.local.get('isSync', data => {
keys = [
Expand Down Expand Up @@ -1132,8 +1127,9 @@ setTimeout(() => {
});
}, 2000);

// add manual submit button if it does not exist already
// add url change listener & manual submit button if it does not exist already
setTimeout(() => {
const leetCode = new LeetCodeV2();
leetCode.addManualSubmitButton();
leetCode.addUrlChangeListener();
}, 6000);

0 comments on commit ec9deb5

Please sign in to comment.