From 81e1fc234b3b87bc97a5792a283b144c31e2b21e Mon Sep 17 00:00:00 2001 From: Akibara Date: Sun, 4 Jan 2026 18:02:18 +0700 Subject: [PATCH 1/4] Add function --- Chrome/content.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/Chrome/content.js b/Chrome/content.js index 5545144..631ad32 100644 --- a/Chrome/content.js +++ b/Chrome/content.js @@ -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 @@ -198,6 +197,7 @@ async function refreshScores(force = true) { updateSidebar(); updateTotalScore(); + await storeStorageCache(); } @@ -244,6 +244,10 @@ async function refreshSingleTask(url, task) { } function createControls() { + /** */ + testtest(); + /** */ + const controlsContainer = document.createElement("div"); controlsContainer.className = "cms-extension-controls"; const totalScoreContainer = document.createElement("div"); @@ -351,3 +355,42 @@ function updateSidebar() { } }); } + +function testtest() { + const item = window.location.href.match(/A\d*-\d{3}/)[0] + let [level,number] = item.split("-"); + level = parseInt(level[1]); + number = parseInt(number); + + console.log(level); + console.log(number); + const Next = CheckItem(level,number,"Next") + const Prev = CheckItem(level,number,"Prev") + + console.log(`Next is ${Next}`); + console.log(`Prev is ${Prev}`); +} + +function CheckItem(level,number,query){ + const headers = document.getElementsByClassName("nav-header"); + + const sel = `A${level}-${String(number).padStart(3, "0")}`; + + let index = Array.from(headers).findIndex(el => { + const span = el.querySelector("span"); + return span && span.textContent.trim() === sel; + }); + + if(query === "Next"){ + index += 1; + }else if(query === "Prev"){ + index -= 1; + } + + if(index < 0 || index >= headers.length){ + return null; + } + + const target = headers[index].querySelector("span").textContent; + return target; +} \ No newline at end of file From b291df534d8bcc59a436188144ebb3d8c79b18d5 Mon Sep 17 00:00:00 2001 From: Akibara Date: Sun, 4 Jan 2026 19:32:17 +0700 Subject: [PATCH 2/4] Add button --- Chrome/content.js | 85 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 24 deletions(-) diff --git a/Chrome/content.js b/Chrome/content.js index 631ad32..8d0a6cd 100644 --- a/Chrome/content.js +++ b/Chrome/content.js @@ -244,10 +244,33 @@ async function refreshSingleTask(url, task) { } function createControls() { - /** */ - testtest(); - /** */ - + const prev = document.createElement("button"); + const next = document.createElement("button"); + prev.setAttribute("hidden",true); + next.setAttribute("hidden",true); + if(!!window.location.href.match(`${baseURL}/tasks`)){ + prev.textContent = "Prev"; + next.textContent = "Next"; + const prevUrl = moveProblem(-1); + const nextUrl = moveProblem(+1); + console.log(prevUrl); + console.log(nextUrl); + 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"); @@ -267,6 +290,8 @@ function createControls() { } }) ); + controlsContainer.appendChild(prev); + controlsContainer.appendChild(next); controlsContainer.appendChild(totalScoreContainer); controlsContainer.appendChild(refreshButton); // last refreshed timestamp @@ -356,36 +381,33 @@ function updateSidebar() { }); } -function testtest() { - const item = window.location.href.match(/A\d*-\d{3}/)[0] - let [level,number] = item.split("-"); - level = parseInt(level[1]); - number = parseInt(number); +function moveProblem(delta) { + const urlSplit = splitTaskURL(); + const problem = urlSplit[1]; - console.log(level); - console.log(number); - const Next = CheckItem(level,number,"Next") - const Prev = CheckItem(level,number,"Prev") + let query; + if(delta === +1){ + query = handleMove(problem,1) + }else if(delta === -1){ + query = handleMove(problem,-1) + } + + if(!query) + return query; - console.log(`Next is ${Next}`); - console.log(`Prev is ${Prev}`); + return urlSplit[0]+query+urlSplit[2]; } -function CheckItem(level,number,query){ +function handleMove(item,delta){ const headers = document.getElementsByClassName("nav-header"); - const sel = `A${level}-${String(number).padStart(3, "0")}`; let index = Array.from(headers).findIndex(el => { const span = el.querySelector("span"); - return span && span.textContent.trim() === sel; + return span && span.textContent.trim() === item; }); - if(query === "Next"){ - index += 1; - }else if(query === "Prev"){ - index -= 1; - } + index += delta; if(index < 0 || index >= headers.length){ return null; @@ -393,4 +415,19 @@ function CheckItem(level,number,query){ const target = headers[index].querySelector("span").textContent; return target; -} \ No newline at end of file +} + +function splitTaskURL() { + const u = window.location.href; + + 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[i + 2]; + + return [prefix, problem, page]; +} \ No newline at end of file From 6c7ec4c40487f8ef75aa7e702331bcd6f64ecb4b Mon Sep 17 00:00:00 2001 From: Akibara Date: Sun, 4 Jan 2026 19:53:57 +0700 Subject: [PATCH 3/4] styling --- Chrome/content.js | 2 ++ Chrome/style.css | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/Chrome/content.js b/Chrome/content.js index 8d0a6cd..8812520 100644 --- a/Chrome/content.js +++ b/Chrome/content.js @@ -248,6 +248,8 @@ function createControls() { 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"; diff --git a/Chrome/style.css b/Chrome/style.css index 1fb3b12..9a4dd4e 100644 --- a/Chrome/style.css +++ b/Chrome/style.css @@ -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; +} \ No newline at end of file From 9653975d249f549ffa1e0b5b96a24848e181c482 Mon Sep 17 00:00:00 2001 From: Akibara Date: Mon, 5 Jan 2026 14:07:44 +0700 Subject: [PATCH 4/4] Delete console.log and change function name --- Chrome/content.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Chrome/content.js b/Chrome/content.js index 8812520..4711d4b 100644 --- a/Chrome/content.js +++ b/Chrome/content.js @@ -255,8 +255,6 @@ function createControls() { next.textContent = "Next"; const prevUrl = moveProblem(-1); const nextUrl = moveProblem(+1); - console.log(prevUrl); - console.log(nextUrl); if(!!prevUrl){ prev.removeAttribute("hidden"); } @@ -384,7 +382,7 @@ function updateSidebar() { } function moveProblem(delta) { - const urlSplit = splitTaskURL(); + const urlSplit = splitProblemURL(); const problem = urlSplit[1]; let query; @@ -419,17 +417,18 @@ function handleMove(item,delta){ return target; } -function splitTaskURL() { - const u = window.location.href; +function splitProblemURL() { + const u = window.location.href + .split(/\?submission_id/)[0]; - const parts = u.split("/").filter(Boolean); + const parts = u.split("/").filter(Boolean); - const i = parts.indexOf("tasks"); - if (i === -1 || i + 2 >= parts.length) return null; + 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[i + 2]; + 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]; + return [prefix, problem, page]; } \ No newline at end of file