Skip to content

Commit ad5dd14

Browse files
committed
add text-coloring for rating delta and update regex expression for url matching
1 parent 67375c0 commit ad5dd14

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

chrome-extension/background.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
22
if (
33
changeInfo.status === "complete" &&
4-
/^https:\/\/leetcode.com\/contest\/[a-zA-Z1-9-]*\/ranking\//.test(
5-
tab.url
6-
)
4+
/^https:\/\/leetcode.com\/contest\/.*\/ranking\//.test(tab.url)
75
) {
86
chrome.scripting
97
.executeScript({
108
target: { tabId: tabId },
119
files: ["./foreground.js"],
1210
})
1311
.then(() => {
14-
console.log("Injected the foreground script.");
12+
console.log(
13+
`Injected the foreground script into tab: ${tabId}`
14+
);
1515
})
1616
.catch((err) => console.error(err));
17-
console.log(tabId);
18-
console.log(changeInfo);
19-
console.log(tab);
2017
}
2118
});
2219

@@ -28,11 +25,9 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
2825
url.searchParams.set("contestId", request.data.contestId);
2926
let handles = "";
3027
request.data.handles.forEach((handle, index) => {
31-
console.log(handle, index);
3228
handles +=
3329
handle + (index !== request.data.handles.length - 1 ? ";" : "");
3430
});
35-
console.log(handles);
3631
url.searchParams.set("handles", handles);
3732
fetch(url)
3833
.then((res) => res.json())

chrome-extension/foreground.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ if (!window.CFPredictorInjected) {
3838
predictionsTimer = setTimeout(fetchPredictions, 100);
3939
return;
4040
}
41-
console.log("fetching!");
4241
const tbody = document.querySelector("tbody");
4342
const rows = tbody.querySelectorAll("tr");
4443
const contestId = document
@@ -105,16 +104,21 @@ if (!window.CFPredictorInjected) {
105104
} else {
106105
td = document.createElement("td");
107106
}
108-
const delta =
109-
Math.round(item.delta * 100) / 100;
110-
td.innerText = delta > 0 ? "+" + delta : delta;
111-
if (delta > 0) {
112-
td.style.color = "green";
113-
} else {
107+
if (item.delta == null) {
108+
td.innerText = "?";
114109
td.style.color = "gray";
110+
} else {
111+
const delta =
112+
Math.round(item.delta * 100) / 100;
113+
td.innerText =
114+
delta > 0 ? "+" + delta : delta;
115+
if (delta > 0) {
116+
td.style.color = "green";
117+
} else {
118+
td.style.color = "gray";
119+
}
120+
// td.style.fontWeight = "bold";
115121
}
116-
td.style.fontWeight = "bold";
117-
118122
if (!rowsChanged.has(rowIndex)) {
119123
row.appendChild(td);
120124
}

0 commit comments

Comments
 (0)