Skip to content
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
83 changes: 82 additions & 1 deletion Chrome/content.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Config

const CACHE_TTL = 5 * 60 * 1000; // Cache Time-To-Live in milliseconds
const CONCURRENT_LIMIT = 4; // Max Parallel Fetch Requests

Expand Down Expand Up @@ -198,6 +197,7 @@ async function refreshScores(force = true) {
updateSidebar();
updateTotalScore();


await storeStorageCache();
}

Expand Down Expand Up @@ -244,6 +244,33 @@ async function refreshSingleTask(url, task) {
}

function createControls() {
const prev = document.createElement("button");
const next = document.createElement("button");
prev.setAttribute("hidden",true);
next.setAttribute("hidden",true);
prev.className = "move-button";
next.className = "move-button";
if(!!window.location.href.match(`${baseURL}/tasks`)){
prev.textContent = "Prev";
next.textContent = "Next";
const prevUrl = moveProblem(-1);
const nextUrl = moveProblem(+1);
if(!!prevUrl){
prev.removeAttribute("hidden");
}
if(!!nextUrl){
next.removeAttribute("hidden");
}
prev.addEventListener("click", () => {
sessionStorage.setItem("cms-extension-scroll", window.scrollY);
window.location.href = prevUrl;
})
next.addEventListener("click", () => {
sessionStorage.setItem("cms-extension-scroll", window.scrollY);
window.location.href = nextUrl;
})
}

const controlsContainer = document.createElement("div");
controlsContainer.className = "cms-extension-controls";
const totalScoreContainer = document.createElement("div");
Expand All @@ -263,6 +290,8 @@ function createControls() {
}
})
);
controlsContainer.appendChild(prev);
controlsContainer.appendChild(next);
controlsContainer.appendChild(totalScoreContainer);
controlsContainer.appendChild(refreshButton);
// last refreshed timestamp
Expand Down Expand Up @@ -351,3 +380,55 @@ function updateSidebar() {
}
});
}

function moveProblem(delta) {
const urlSplit = splitProblemURL();
const problem = urlSplit[1];

let query;
if(delta === +1){
query = handleMove(problem,1)
}else if(delta === -1){
query = handleMove(problem,-1)
}

if(!query)
return query;

return urlSplit[0]+query+urlSplit[2];
}

function handleMove(item,delta){
const headers = document.getElementsByClassName("nav-header");


let index = Array.from(headers).findIndex(el => {
const span = el.querySelector("span");
return span && span.textContent.trim() === item;
});

index += delta;

if(index < 0 || index >= headers.length){
return null;
}

const target = headers[index].querySelector("span").textContent;
return target;
}

function splitProblemURL() {
const u = window.location.href
.split(/\?submission_id/)[0];

const parts = u.split("/").filter(Boolean);

const i = parts.indexOf("tasks");
if (i === -1 || i + 2 >= parts.length) return null;

const prefix = "https://" + parts.slice(1, i + 1).join("/") + "/";
const problem = parts[i + 1];
const page = "/"+parts.slice(i + 2).join("/");

return [prefix, problem, page];
}
12 changes: 12 additions & 0 deletions Chrome/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
font-weight: bold;
}
.move-button {
background-color: #f0f0f0;
padding: 10px;
border: none;
cursor: pointer;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
font-weight: bold;
}
.move-button:hover {
background-color: #e5e5e5;
}