Changed around line 1
+ const ELO_K = 32;
+ let items = [];
+ let currentPair = [];
+
+ function initializeRatings(urls) {
+ return urls.map((url) => ({
+ url: url.trim(),
+ rating: 1000,
+ matches: 0,
+ wins: 0,
+ }));
+ }
+
+ function getExpectedScore(a, b) {
+ return 1 / (1 + Math.pow(10, (b - a) / 400));
+ }
+
+ function updateRatings(winner, loser) {
+ const expectedWin = getExpectedScore(winner.rating, loser.rating);
+ const expectedLoss = getExpectedScore(loser.rating, winner.rating);
+
+ winner.rating += ELO_K * (1 - expectedWin);
+ loser.rating += ELO_K * (0 - expectedLoss);
+
+ winner.matches++;
+ loser.matches++;
+ winner.wins++;
+ }
+
+ function getNextPair() {
+ items.sort((a, b) => a.rating - b.rating);
+ const mid = Math.floor(items.length / 2);
+ return [itemsid], itemsid + 1] || items[0]];
+ }
+
+ function showPair() {
+ currentPair = getNextPair();
+ document.getElementById("frameA").src = currentPair[0].url;
+ document.getElementById("frameB").src = currentPair[1].url;
+ }
+
+ function handleChoice(winnerIndex) {
+ const [a, b] = currentPair;
+ updateRatings(winnerIndex === 0 ? a : b, winnerIndex === 0 ? b : a);
+ showPair();
+ updateResults();
+ }
+
+ function updateResults() {
+ const sorted = [...items].sort((a, b) => b.rating - a.rating);
+ const tbody = document.querySelector("#resultsTable tbody");
+ tbody.innerHTML = sorted
+ .map(
+ (item, i) => `
+
+ ${i + 1}
+ ${item.url}
+ ${Math.round(item.rating)}
+
+ `,
+ )
+ .join("");
+ }
+
+ function exportCSV() {
+ const csv = items
+ .map((item) => `${item.url},${item.rating},${item.wins},${item.matches}`)
+ .join(
+ "\
+ ",
+ );
+ const blob = new Blob(
+ [
+ `URL,Rating,Wins,Matches\
+ ${csv}`,
+ ],
+ { type: "text/csv" },
+ );
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement("a");
+ a.href = url;
+ a.download = "elo_rankings.csv";
+ a.click();
+ }
+
+ document.getElementById("startBtn").addEventListener("click", () => {
+ const urls = document
+ .getElementById("urlInput")
+ .value.split(
+ "\
+ ",
+ )
+ .filter(Boolean);
+ if (urls.length < 2) return alert("Please enter at least 2 URLs");
+ items = initializeRatings(urls);
+ document.querySelector(".input-section").hidden = true;
+ document.querySelector(".compare-section").hidden = false;
+ document.querySelector(".results-section").hidden = false;
+ showPair();
+ });
+
+ document.querySelectorAll(".choice-overlay").forEach((overlay) => {
+ overlay.addEventListener("click", (e) => {
+ handleChoice(parseInt(e.target.dataset.choice === "A" ? 0 : 1));
+ });
+ });
+
+ document.getElementById("exportBtn").addEventListener("click", exportCSV);
+
+ // Initialize from localStorage
+ try {
+ const saved = localStorage.getItem("eloItems");
+ if (saved) {
+ items = JSON.parse(saved);
+ updateResults();
+ }
+ } catch {}
+
+ window.addEventListener("beforeunload", () => {
+ localStorage.setItem("eloItems", JSON.stringify(items));
+ });