Improved アルゴ式

提出とか実行を楽にしたいな

目前為 2021-12-21 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Improved アルゴ式
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  提出とか実行を楽にしたいな
// @author       eggplants
// @homepage     https://github.com/eggplants
// @match        https://algo-method.com/tasks/*
// @license      MIT

// ==/UserScript==

/*jshint esversion: 6 */

const addOpt = (i, t, target) => {
  opt = document.createElement("option");
  opt.value = i;
  opt.text = t;
  target.appendChild(opt);
};

const checkCorrect = () => {
  var v = document.getElementById("exSelect").value;
  var a = document.querySelector(".EditorWrapper_codeTestOutputArea__7Ty3v");
  var ans_show = document.getElementById("ansShow");
  if (v < 1) {
    a.style.backgroundColor = "#d6d6d0";
    ans_show.value = "";
  } else {
    ans = pre[v * 2].innerText.replace(/\nCOPY$/, "\n");
    ans_show.value = ans;
    a.style.backgroundColor = ans === a.value ? "#98fb98" : "#ffffa8";
  }
};

const addShortcutRun = (evt) => {
  if (evt.metaKey || evt.ctrlKey) {
    if (evt.keyCode == 13) {
      document.querySelectorAll(".Button_button__HxzDS")[5].click();
    }
  }
};

// set style
ed = document.querySelector("section");
ed_wrap = document.querySelector(".Task_component__pgBHU");
ed.style.height = "10vh";

// insert textarea for checking answer
ans_show = document.createElement("div");
ans_show.innerHTML =
  "<div>出力例:</div>" +
  '<textarea class="EditorWrapper_codeTestErrorArea__KClBp" ' +
  'id="ansShow" disabled=""></textarea>';
ans_show.classList.add("EditorWrapper_codeTestFlex__q5EsJ");
document
  .querySelectorAll(".EditorWrapper_codeTestFlex__q5EsJ")[2]
  .after(ans_show);

// create select menu
pre = document.querySelectorAll("pre:not([class])");
select_ex = document.createElement("select");
select_ex.id = "exSelect";
select_ex.classList.add("EditorWrapper_languageChanger___Fl02");
select_ex.style.marginLeft = "5px";
select_ex.style.textAlignLast = "center";
addOpt(0, `---`, select_ex);
for (var i = 1; i <= (pre.length - 1) / 2; i++) addOpt(i, `例 ${i}`, select_ex);
select_ex.onchange = () => {
  var v = document.getElementById("exSelect").value;
  var ipt = document.querySelector(".EditorWrapper_codeTestInputArea__fxPTR");
  if (v == 0) {
    ipt.value = "";
  } else {
    ipt.value = pre[(v - 1) * 2 + 1].innerText.replace(/\nCOPY$/, "\n");
  }
};

// insert select menu
document.querySelector(".EditorWrapper_codeTestHeader__SEnNi").after(select_ex);

// add timer of checking answer
setInterval(checkCorrect, 100);
// document.querySelector(".EditorWrapper_codeTestOutputArea__7Ty3v").addEventListener("inputs", checkCorrect);
Array.from(document.getElementsByTagName("textarea"))
  .slice(1)
  .forEach((e) => (e.style.height = "20vh"));

// add shortcut
var ipt = document.querySelector(".EditorWrapper_codeTestInputArea__fxPTR");
ipt.placeholder = "Run: (ctrl||cmd) + Enter";
ipt.addEventListener("keydown", addShortcutRun);