Old PE Progress Grid

Restores old PE Progress Grid

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name         Old PE Progress Grid
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Restores old PE Progress Grid
// @license MIT
// @match        https://projecteuler.net/progress*
// @match        http://projecteuler.net/progress*
// @grant        none
// ==/UserScript==

// based on https://gist.github.com/avirukt/2370881cdc76419aac67078181e8dea9

(function () {
  "use strict";

  const DIFFICULTIES = [
    5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
    5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
    5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
    5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
    5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
    15, 5, 5, 10, 5, 5, 5, 5, 5, 20,
    20, 15, 5, 20, 15, 25, 5, 25, 10, 20,
    10, 20, 15, 15, 25, 10, 25, 30, 5, 20,
    10, 20, 25, 35, 15, 35, 20, 40, 20, 40,
    25, 5, 35, 35, 30, 25, 5, 35, 10, 30,
    // 100s
    35, 15, 45, 25, 45, 50, 35, 30, 45, 40,
    45, 15, 30, 35, 35, 30, 35, 45, 30, 25,
    35, 40, 30, 25, 25, 55, 50, 55, 45, 45,
    40, 45, 50, 45, 45, 50, 50, 45, 50, 55,
    60, 45, 65, 50, 20, 50, 65, 50, 50, 55,
    50, 65, 65, 65, 60, 70, 65, 55, 60, 60,
    70, 45, 70, 45, 65, 50, 75, 65, 50, 70,
    65, 55, 30, 40, 70, 70, 80, 55, 25, 75,
    70, 60, 45, 75, 55, 60, 25, 35, 70, 50,
    35, 75, 55, 75, 75, 65, 45, 80, 70, 65,
    // 200s
    65, 60, 25, 30, 15, 5, 40, 70, 60, 70,
    50, 70, 60, 40, 50, 45, 70, 55, 70, 55,
    65, 60, 70, 75, 45, 65, 65, 70, 70, 50,
    40, 65, 70, 50, 40, 80, 70, 75, 65, 60,
    80, 75, 35, 70, 80, 80, 65, 70, 60, 55,
    70, 80, 75, 75, 75, 80, 85, 70, 70, 70,
    85, 80, 75, 85, 40, 65, 50, 70, 80, 80,
    60, 80, 70, 65, 85, 75, 35, 50, 60, 65,
    55, 70, 75, 55, 55, 50, 40, 35, 90, 50,
    45, 65, 30, 45, 75, 60, 35, 60, 60, 50,
    // 300s
    15, 60, 35, 40, 60, 55, 40, 60, 50, 40,
    70, 50, 30, 80, 20, 55, 35, 50, 90, 50,
    30, 70, 20, 50, 80, 55, 40, 95, 25, 70,
    100, 50, 35, 65, 65, 25, 70, 95, 70, 30,
    45, 50, 35, 100, 15, 15, 15, 25, 35, 60,
    25, 55, 50, 65, 70, 60, 10, 25, 25, 50,
    90, 70, 35, 50, 40, 40, 55, 45, 60, 65,
    30, 60, 75, 40, 40, 70, 45, 35, 70, 60,
    15, 60, 50, 65, 70, 40, 10, 55, 30, 60,
    75, 35, 50, 55, 40, 40, 70, 55, 45, 55,
    // 400s
    25, 55, 55, 60, 40, 50, 20, 50, 55, 70,
    45, 50, 75, 60, 100, 80, 35, 40, 50, 60,
    50, 75, 45, 60, 25, 75, 95, 90, 20, 35,
    40, 70, 65, 75, 30, 55, 35, 95, 100, 60,
    65, 60, 30, 60, 50, 60, 95, 80, 40, 100,
    30, 45, 95, 50, 40, 55, 35, 30, 100, 60,
    30, 60, 35, 60, 85, 65, 50, 70, 40, 65,
    75, 60, 35, 50, 50, 45, 65, 100, 25, 45,
    70, 85, 100, 100, 30, 70, 40, 80, 100, 95,
    20, 60, 10, 100, 100, 50, 40, 40, 100, 15,
    // 500s
    40, 100, 60, 15, 90, 30, 90, 85, 45, 30,
    55, 25, 65, 90, 40, 20, 45, 20, 50, 45,
    50, 85, 30, 75, 45, 60, 30, 60, 85, 60,
    25, 55, 50, 55, 60, 60, 35, 40, 35, 30,
    90, 65, 30, 90, 35, 85, 70, 35, 15, 60,
    50, 40, 85, 80, 30, 85, 55, 65, 100, 75,
    30, 75, 45, 60, 35, 100, 55, 55, 45, 55,
    25, 50, 80, 50, 35, 55, 25, 80, 100, 75,
    30, 50, 50, 100, 100, 75, 20, 40, 95, 60,
    95, 60, 35, 85, 35, 50, 100, 40, 60, 35,
    // 600s
    20, 35, 45, 40, 25, 50, 20, 80, 20, 35,
    60, 30, 20, 55, 35, 40, 40, 20, 45, 80,
    35, 15, 45, 30, 35, 70, 60, 30, 55, 20,
    65, 35, 50, 40, 40, 90, 45, 40, 70, 50,
    35, 45, 25, 90, 75, 40, 30, 45, 30, 10,
    70, 70, 45, 45, 30, 50, 30, 55, 20, 40,
    55, 25, 35, 65, 55, 45, 80, 20, 45, 40,
    80, 50, 35, 75, 25, 50, 90, 55, 20, 65,
    50, 50, 40, 5, 65, 5, 45, 20, 60, 60,
    40, 10, 40, 15, 70, 100, 30, 30, 80, 5,
    // 700s
    40, 95, 45, 20, 25, 25, 55, 50, 15, 10,
    35, 25, 20, 25, 65, 45, 25, 35, 5, 35,
    30, 25, 65, 30, 10, 50, 25, 40, 65, 65,
    20, 40, 25, 35, 65, 50, 30, 35, 25, 55,
    80, 75, 10, 35, 10, 40, 60, 40, 15, 35,
    5, 25, 40, 20, 15, 30, 10, 50, 25, 35,
    90, 50, 100, 40, 65, 35, 60, 95, 90, 30,
    80, 20, 50, 90, 40, 25, 95, 30, 25, 100,
    95, 70, 55, 30, 55, 100, 45, 10, 50, 45,
    60, 100, 20, 35, 30, 55, 50, 100, 50, 5,
    // 800s
    50, 35, 55, 20, 60, 100, 90, 5, 35, 20,
    45, 100, 20, 50, 25, 5, 20, 85, 45, 10,
    65, 15, 50, 95, 60, 45, 50, 15, 45, 75,
    60, 30, 65, 25, 25, 5, 55, 20, 30, 25,
    45, 75, 80, 40, 15, 50, 85, 45, 45, 85,
    85, 50, 5, 40, 65, 20, 60, 50, 55, 20,
    40, 10, 35, 65, 35, 20, 55, 20, 15, 60,
    25, 5, 25, 15, 35, 95, 20, 40, 25, 75,
    20, 75, 95, 20, 10, 40, 30, 45, 70, 55,
    65, 60, 15, 35, 100, 50, 25, 35, 15, 60,
    // 900s
    25, 50, 90, 45, 35, 35, 35, 65, 70, 100,
    50, 50, 60, 20, 45, 55, 50, 10, 35, 30,
    45, 70, 85, 45, 55, 10, 45, 35, 35, 75,
    55, 5, 50, 25, 80, 90, 50, 5, 60, 15,
    70, 100, 95, 10, 40, 30, 60, 25, 100, 75,
    25, 30, 40, 50, 15, 15, 90, 40, 40, 50,
    10, 80, 95, 45, 15, 60, 25, 85, 35, 65,
    40, 40, 90, 15, 70, 95, 70, 20, 30, 15,
    25, 60, 100, 80

  ];

  function percentToRGB(p) {
    if (p ==  5) return "rgba(254, 184, 0)";
    if (p == 10) return "rgba(253, 182, 0)";
    if (p == 15) return "rgba(255, 175, 1)";
    if (p == 20) return "rgba(254, 169, 0)";
    if (p == 25) return "rgba(254, 166, 0)";
    if (p == 30) return "rgba(253, 163, 4)";
    if (p == 35) return "rgba(254, 155, 0)";
    if (p == 40) return "rgba(255, 151, 0)";
    if (p == 45) return "rgba(255, 147, 0)";
    if (p == 50) return "rgba(255, 141, 0)";
    if (p == 55) return "rgba(254, 138, 0)";
    if (p == 60) return "rgba(245, 133, 0)";
    if (p == 65) return "rgba(241, 127, 1)";
    if (p == 70) return "rgba(235, 123, 5)";
    if (p == 75) return "rgba(226, 119, 0)";
    if (p == 80) return "rgba(217, 114, 0)";
    if (p == 85) return "rgba(205, 108, 2)";
    if (p == 90) return "rgba(194, 102, 1)";
    if (p == 95) return "rgba(187, 100, 3)";
    if (p == 100) return "rgba(179, 93, 0)";
    return "rgba(120, 73, 31)";
  }

  function getProblemDifficulty(pid) {
    return pid < 1 || pid > DIFFICULTIES.length ? -1 : DIFFICULTIES[pid-1];
  }

  function restoreProblemDifficulty(td) {
    const divs = td.querySelectorAll("div");
    let pid = -1
    for (let i = 0; i < divs.length; ++i) {
    	const match = divs[i].textContent.match(/^Problem (\d+)$/);
      if (match)
        pid = parseInt(match[1], 10);
    }
    let difficulty = getProblemDifficulty(pid);
    for (let i = 0; i < divs.length; ++i) {
    	const match = divs[i].textContent.match(/^Difficulty level: (\d+)$/);
      if (match) {
        if (difficulty == -1) {
          divs[i].remove();
        }
       	else {
          divs[i].textContent = "Difficulty level: " + difficulty + "%";
        }
      }

    }

    if (td.classList.contains("problem_solved")) {
      td.style.setProperty("background-color", percentToRGB(difficulty), "important");
      td.style.setProperty("background-image", "none", "important");
    }
  }

  function restoreDifficulties() {
    // Only target the 10x10 grids, not the difficulty-sorted grid.
    const tables = document.querySelectorAll(
      "#problems_solved_section .problems_solved_table"
    );

    tables.forEach((table) => {
      table.querySelectorAll("td.problem_solved, td.problem_unsolved").forEach((td) => {
        restoreProblemDifficulty(td);
      });
    });
  }

  function removeBySelector(elName) {
    const el = document.querySelector(elName);
    if (el) el.remove();
  }

  function removeRanks() {
    removeBySelector("#heat_map_form");
    removeBySelector("#rank_progress_section");
    removeBySelector("#rank_image_box");

    const level = document.querySelector("#level_text");
    const profile = document.querySelector("#profile_name_text");

    if (level && profile) {
        profile.insertAdjacentElement("afterend", level);
    }
  }

  function removeBars() {
    document.querySelectorAll(".progress_bar.tooltip").forEach(el => el.remove());
  }

  function applyChanges() {
    restoreDifficulties();
    removeRanks();
    removeBars();
  }

  if (document.readyState === "loading") {
    document.addEventListener("DOMContentLoaded", applyChanges);
  } else {
    applyChanges();
  }
})();