Skip to content

Commit

Permalink
Merge pull request QasimWani#30 from JeremyTsaii/dev-repolink
Browse files Browse the repository at this point in the history
Add Problem Difficulty Distribution and Repo Link
  • Loading branch information
QasimWani authored Dec 3, 2020
2 parents f80945b + 860999f commit a5e6857
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 21 deletions.
12 changes: 12 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,21 @@ <h1 id="title">

<!-- Commit mode -->
<div id="commit_mode" hidden>
<p id="repo_url" class="ui small header"></p>
<p class="onboarding">
Problems Solved: <span id="p_solved">0</span>
</p>
<p class="ui small header">
<span style="color: #5cb85c">Easy:</span>
<span id="p_solved_easy" style="color: #5cb85c">0 </span>
<span style="color: #f0ad4e">Medium:</span>
<span id="p_solved_medium" style="color: #f0ad4e"
>0
</span>
<span style="color: #d9534f">Hard:</span>
<span id="p_solved_hard" style="color: #d9534f">0 </span>
</p>

<div class="ui small header">
Want more features?
<a
Expand Down
26 changes: 19 additions & 7 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,25 @@ chrome.storage.sync.get('leethub_token', (data) => {
chrome.storage.sync.get('mode_type', (data2) => {
if (data2 && data2.mode_type === 'commit') {
$('#commit_mode').show();
/* Get problems solved count */
chrome.storage.sync.get('stats', (psolved) => {
const { stats } = psolved;
if (stats && stats.solved) {
$('#p_solved').text(stats.solved);
}
});
/* Get problem stats and repo link */
chrome.storage.sync.get(
['stats', 'leethub_hook'],
(data3) => {
const { stats } = data3;
if (stats && stats.solved) {
$('#p_solved').text(stats.solved);
$('#p_solved_easy').text(stats.easy);
$('#p_solved_medium').text(stats.medium);
$('#p_solved_hard').text(stats.hard);
}
const leethubHook = data3.leethub_hook;
if (leethubHook) {
$('#repo_url').html(
`<a target="blank" style="color: cadetblue !important" href="https://github.com/${leethubHook}">Linked Repo</a>`,
);
}
},
);
} else {
$('#hook_mode').show();
}
Expand Down
23 changes: 17 additions & 6 deletions scripts/leetcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const languages = {
Oracle: '.sql',
};

/* Difficulty of most recenty submitted question */
let difficulty = '';

/* Get file extension for submission */
function findLanguage() {
const tag = [
Expand Down Expand Up @@ -66,13 +69,19 @@ const upload = (token, hook, code, directory, filename, sha) => {
// create stats object
stats = {};
stats.solved = 0;
stats.easy = 0;
stats.medium = 0;
stats.hard = 0;
stats.sha = {};
}
const filePath = directory + filename;
// Only increment solved problems statistics once
// New submission commits twice (README and problem)
if (filename !== 'README.md') {
if (filename === 'README.md') {
stats.solved += 1;
stats.easy += difficulty === 'Easy' ? 1 : 0;
stats.medium += difficulty === 'Medium' ? 1 : 0;
stats.hard += difficulty === 'Hard' ? 1 : 0;
}
stats.sha[filePath] = updatedSha; // update sha key.
chrome.storage.sync.set({ stats }, () => {
Expand Down Expand Up @@ -159,10 +168,12 @@ function parseQuestion() {
const qbody = questionElem[0].innerHTML;

// Problem title.
const qtitlte = document.getElementsByClassName('css-v3d350')[0]
.innerHTML;

let difficulty = '';
let qtitle = document.getElementsByClassName('css-v3d350')[0];
if (checkElem(qtitle)) {
qtitle = qtitle.innerHTML;
} else {
qtitle = 'unknown-problem';
}

// Problem difficulty, each problem difficulty has its own class.
const isHard = document.getElementsByClassName('css-t42afm');
Expand All @@ -177,7 +188,7 @@ function parseQuestion() {
difficulty = 'Hard';
}
// Final formatting of the contents of the README for each problem
const markdown = `<h2>${qtitlte}</h2><h3>${difficulty}</h3><hr>${qbody}`;
const markdown = `<h2>${qtitle}</h2><h3>${difficulty}</h3><hr>${qbody}`;
return markdown;
}

Expand Down
23 changes: 15 additions & 8 deletions scripts/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,18 @@ const linkRepo = (token, name) => {
'none';
} else {
/* Change mode type to commit */
chrome.storage.sync.set({ mode_type: 'commit' }, () => {
$('#error').hide();
$('#success').html(
`Successfully linked <a target="blank" href="${res.html_url}">${name}</a> to LeetHub. Start <a href="http://leetcode.com">LeetCoding</a> now!`,
);
$('#success').show();
$('#unlink').show();
});
/* Save repo url to chrome storage */
chrome.storage.sync.set(
{ mode_type: 'commit', repo: res.html_url },
() => {
$('#error').hide();
$('#success').html(
`Successfully linked <a target="blank" href="${res.html_url}">${name}</a> to LeetHub. Start <a href="http://leetcode.com">LeetCoding</a> now!`,
);
$('#success').show();
$('#unlink').show();
},
);
/* Set Repo Hook */
chrome.storage.sync.set(
{ leethub_hook: res.full_name },
Expand All @@ -184,6 +188,9 @@ const linkRepo = (token, name) => {
const { stats } = psolved;
if (stats && stats.solved) {
$('#p_solved').text(stats.solved);
$('#p_solved_easy').text(stats.easy);
$('#p_solved_medium').text(stats.medium);
$('#p_solved_hard').text(stats.hard);
}
});
},
Expand Down
13 changes: 13 additions & 0 deletions welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@
>
Problems Solved: <span id="p_solved">0</span>
</div>
<div
styl="font-size: 2.3em"
class="ui inverted large header"
>
<span style="color: #5cb85c">Easy:</span>
<span id="p_solved_easy" style="color: #5cb85c">0 </span>
<span style="color: #f0ad4e">Medium:</span>
<span id="p_solved_medium" style="color: #f0ad4e"
>0
</span>
<span style="color: #d9534f">Hard:</span>
<span id="p_solved_hard" style="color: #d9534f">0 </span>
</div>
</div>
<div class="eight wide center aligned column">
<br /><br /><br />
Expand Down

0 comments on commit a5e6857

Please sign in to comment.