-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
executable file
·44 lines (40 loc) · 1.68 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
document.addEventListener('DOMContentLoaded', function () {
chrome.tabs.onUpdated.addListener(
function(tabId, changeInfo, tab) {
// console.log("onUpdated", new Date(), JSON.stringify(changeInfo), "tab", JSON.stringify(tab));
// removePreviousDivs(tabId);
if(tab && tab.url && tab.url.includes("https://leetcode.com/list")) {
chrome.tabs.executeScript(
tabId,
{
code: `
var el = document.getElementById("leetcode-stat-extension-id");
if(el) {
el.parentNode.removeChild(el)
}
`
}
);
chrome.tabs.executeScript(
tabId,
{
code: `
var elems = document.getElementsByClassName("panel-heading");
// console.log("elems length", elems.length);
if(elems.length>=2 && elems[2].parentNode) {
var totalProblems = document.getElementsByClassName('css-alevek').length;
var solvedProblems = document.getElementsByClassName('text-success fa fa-check css-alevek').length;
var perc = ((solvedProblems/totalProblems) * 100).toFixed(0);
var el = document.createElement('div');
el.setAttribute('class', 'panel-heading');
el.setAttribute('id', 'leetcode-stat-extension-id')
el.innerText="Problems solved: "+solvedProblems+"/"+totalProblems+" - " + perc+"%";
document.getElementsByClassName("panel-heading")[2].parentNode.insertBefore(el, document.getElementsByClassName("panel-heading")[2].nextSibling);
}
`
}
);
}
}
);
});