Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Constant Polling to Only On Click #35

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 43 additions & 32 deletions scripts/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,38 +192,49 @@ function parseQuestion() {
return markdown;
}

const loader = setInterval(() => {
let code = null;
let probStatement = null;

const successTag = document.getElementsByClassName('success__3Ai7');
/* Only poll when submit button clicked */
document.addEventListener('click', (event) => {
const element = event.target;
if (
successTag !== undefined &&
successTag.length > 0 &&
successTag[0].innerText.trim() === 'Success'
element.classList.contains('css-gahzfj-sm') ||
element.parentElement.classList.contains('css-gahzfj-sm')
) {
code = parseCode();
probStatement = parseQuestion();
}
if (code !== null && probStatement !== null) {
clearTimeout(loader);
const problemName = window.location.pathname.split('/')[2]; // must be true.
const language = findLanguage();
if (language !== null) {
uploadGit(
btoa(unescape(encodeURIComponent(code))),
problemName,
problemName + language,
); // Encode `code` to base64

/* @TODO: Change this setTimeout to Promise */
setTimeout(function () {
uploadGit(
btoa(unescape(encodeURIComponent(probStatement))),
problemName,
'README.md',
);
}, 2000);
}
const loader = setInterval(() => {
let code = null;
let probStatement = null;

const successTag = document.getElementsByClassName(
'success__3Ai7',
);
if (
successTag !== undefined &&
successTag.length > 0 &&
successTag[0].innerText.trim() === 'Success'
) {
code = parseCode();
probStatement = parseQuestion();
}
if (code !== null && probStatement !== null) {
clearTimeout(loader);
const problemName = window.location.pathname.split('/')[2]; // must be true.
const language = findLanguage();
if (language !== null) {
uploadGit(
btoa(unescape(encodeURIComponent(code))),
problemName,
problemName + language,
); // Encode `code` to base64

/* @TODO: Change this setTimeout to Promise */
setTimeout(function () {
uploadGit(
btoa(unescape(encodeURIComponent(probStatement))),
problemName,
'README.md',
);
}, 2000);
}
}
}, 1000);
}
}, 1000);
});
1 change: 0 additions & 1 deletion scripts/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ const linkRepo = (token, name) => {
'none';
} else {
/* Change mode type to commit */
/* Save repo url to chrome storage */
chrome.storage.sync.set(
{ mode_type: 'commit', repo: res.html_url },
() => {
Expand Down