Skip to content

Instantly share code, notes, and snippets.

@kiwiyou
Created April 23, 2023 04:58
Show Gist options
  • Save kiwiyou/b5f76d556f848f1583e3600071319f56 to your computer and use it in GitHub Desktop.
Save kiwiyou/b5f76d556f848f1583e3600071319f56 to your computer and use it in GitHub Desktop.
BOJ Group Practice Tier
// ==UserScript==
// @name BOJ Group Practice Tier
// @namespace Violentmonkey Scripts
// @match https://www.acmicpc.net/group/practice/view/*
// @grant GM_xmlhttpRequest
// @version 1.0
// @author kiwiyou
// ==/UserScript==
const problemAnchors = document.querySelectorAll('a[href^="/problem/"]');
const problemMap = new Map();
for (const anchor of problemAnchors) {
const groups = anchor.href.match(/\/problem\/(\d+)$/);
if (groups === null) {
continue;
}
const key = +groups[1];
const list = problemMap.get(key);
if (!list) {
problemMap.set(key, [anchor]);
} else {
list.push(anchor);
}
}
const request = GM_xmlhttpRequest({
url: `https://solved.ac/api/v3/problem/lookup?problemIds=${[...problemMap.keys()].join(",")}`,
method: 'GET',
responseType: 'json',
onloadend(res) {
if (res.response === null) {
return;
}
for (const { problemId, level } of res.response) {
for (const anchor of problemMap.get(problemId)) {
const tier = document.createElement('img');
tier.src = `https://static.solved.ac/tier_small/${level}.svg`;
const computedStyle = window.getComputedStyle(anchor, null);
const fontSize = computedStyle.getPropertyValue('font-size');
tier.style = `height: calc(${fontSize} * 1.2); margin-right: calc(${fontSize} * 0.5);`;
anchor.prepend(tier);
}
}
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment