AtCoder Easy Test v2

Make testing sample cases easy

As of 2022-01-19. See the latest version.

  1. // ==UserScript==
  2. // @name AtCoder Easy Test v2
  3. // @namespace https://atcoder.jp/
  4. // @version 2.9.14
  5. // @description Make testing sample cases easy
  6. // @author magurofly
  7. // @license MIT
  8. // @supportURL https://github.com/magurofly/atcoder-easy-test/
  9. // @match https://atcoder.jp/contests/*/tasks/*
  10. // @match https://yukicoder.me/problems/no/*
  11. // @match https://yukicoder.me/problems/*
  12. // @match http://codeforces.com/contest/*/problem/*
  13. // @match http://codeforces.com/gym/*/problem/*
  14. // @match http://codeforces.com/problemset/problem/*
  15. // @match http://codeforces.com/group/*/contest/*/problem/*
  16. // @match http://*.contest.codeforces.com/group/*/contest/*/problem/*
  17. // @match https://codeforces.com/contest/*/problem/*
  18. // @match https://codeforces.com/gym/*/problem/*
  19. // @match https://codeforces.com/problemset/problem/*
  20. // @match https://codeforces.com/group/*/contest/*/problem/*
  21. // @match https://*.contest.codeforces.com/group/*/contest/*/problem/*
  22. // @match https://m1.codeforces.com/contest/*/problem/*
  23. // @match https://m2.codeforces.com/contest/*/problem/*
  24. // @match https://m3.codeforces.com/contest/*/problem/*
  25. // @match https://greatest.deepsurf.us/*/scripts/433152-atcoder-easy-test-v2
  26. // @grant unsafeWindow
  27. // @grant GM_getValue
  28. // @grant GM_setValue
  29. // ==/UserScript==
  30. (function() {
  31. function buildParams(data) {
  32. return Object.entries(data).map(([key, value]) => encodeURIComponent(key) + "=" + encodeURIComponent(value)).join("&");
  33. }
  34. function sleep(ms) {
  35. return new Promise(done => setTimeout(done, ms));
  36. }
  37. function doneOrFail(p) {
  38. return p.then(() => Promise.resolve(), () => Promise.resolve());
  39. }
  40. function html2element(html) {
  41. const template = document.createElement("template");
  42. template.innerHTML = html;
  43. return template.content.firstChild;
  44. }
  45. function newElement(tagName, attrs = {}, children = []) {
  46. const e = document.createElement(tagName);
  47. for (const [key, value] of Object.entries(attrs)) {
  48. if (key == "style") {
  49. for (const [propKey, propValue] of Object.entries(value)) {
  50. e.style[propKey] = propValue;
  51. }
  52. }
  53. else {
  54. e[key] = value;
  55. }
  56. }
  57. for (const child of children) {
  58. e.appendChild(child);
  59. }
  60. return e;
  61. }
  62. function uuid() {
  63. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".
  64. replace(/x/g, () => "0123456789abcdef"[Math.random() * 16 | 0]).
  65. replace(/y/g, () => "89ab"[Math.random() * 4 | 0]);
  66. }
  67. async function loadScript(src, ctx = null, env = {}) {
  68. const js = await fetch(src).then(res => res.text());
  69. const keys = [];
  70. const values = [];
  71. for (const [key, value] of Object.entries(env)) {
  72. keys.push(key);
  73. values.push(value);
  74. }
  75. unsafeWindow["Function"](keys.join(), js).apply(ctx, values);
  76. }
  77. const eventListeners = {};
  78. const events = {
  79. on(name, listener) {
  80. const listeners = (name in eventListeners ? eventListeners[name] : eventListeners[name] = []);
  81. listeners.push(listener);
  82. },
  83. trig(name) {
  84. if (name in eventListeners) {
  85. for (const listener of eventListeners[name])
  86. listener();
  87. }
  88. },
  89. };
  90. class ObservableValue {
  91. _value;
  92. _listeners;
  93. constructor(value) {
  94. this._value = value;
  95. this._listeners = new Set();
  96. }
  97. get value() {
  98. return this._value;
  99. }
  100. set value(value) {
  101. this._value = value;
  102. for (const listener of this._listeners)
  103. listener(value);
  104. }
  105. addListener(listener) {
  106. this._listeners.add(listener);
  107. listener(this._value);
  108. }
  109. removeListener(listener) {
  110. this._listeners.delete(listener);
  111. }
  112. map(f) {
  113. const y = new ObservableValue(f(this.value));
  114. this.addListener(x => {
  115. y.value = f(x);
  116. });
  117. return y;
  118. }
  119. }
  120.  
  121. var hPage = "<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n <title>AtCoder Easy Test</title>\n <link href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css\" rel=\"stylesheet\">\n </head>\n <body>\n <div class=\"container\" id=\"root\">\n </div>\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js\"></script>\n <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js\"></script>\n </body>\n</html>";
  122.  
  123. const components = [];
  124. const settings = {
  125. add(title, generator) {
  126. components.push({ title, generator });
  127. },
  128. open() {
  129. const win = window.open("about:blank");
  130. const doc = win.document;
  131. doc.open();
  132. doc.write(hPage);
  133. doc.close();
  134. const root = doc.getElementById("root");
  135. for (const { title, generator } of components) {
  136. const panel = newElement("div", { className: "panel panel-default" }, [
  137. newElement("div", { className: "panel-heading", textContent: title }),
  138. newElement("div", { className: "panel-body" }, [generator(win)]),
  139. ]);
  140. root.appendChild(panel);
  141. }
  142. },
  143. };
  144.  
  145. const options = [];
  146. let data = {};
  147. function toString() {
  148. return JSON.stringify(data);
  149. }
  150. function save() {
  151. GM_setValue("config", toString());
  152. }
  153. function load() {
  154. data = JSON.parse(GM_getValue("config") || "{}");
  155. }
  156. function reset() {
  157. data = {};
  158. save();
  159. }
  160. load();
  161. // 設定ページ
  162. settings.add("config", (win) => {
  163. const root = newElement("form", { className: "form-horizontal" });
  164. options.sort((a, b) => {
  165. const x = a.key.split(".");
  166. const y = b.key.split(".");
  167. return x < y ? -1 : x > y ? 1 : 0;
  168. });
  169. for (const { type, key, defaultValue, description } of options) {
  170. const id = uuid();
  171. const control = newElement("div", { className: "col-sm-3 text-center" });
  172. const group = newElement("div", { className: "form-group" }, [
  173. control,
  174. newElement("label", {
  175. className: "col-sm-3",
  176. htmlFor: id,
  177. textContent: key,
  178. style: {
  179. fontFamily: "monospace",
  180. },
  181. }),
  182. newElement("label", {
  183. className: "col-sm-6",
  184. htmlFor: id,
  185. textContent: description,
  186. }),
  187. ]);
  188. root.appendChild(group);
  189. switch (type) {
  190. case "flag": {
  191. control.appendChild(newElement("input", {
  192. id,
  193. type: "checkbox",
  194. checked: config.get(key, defaultValue),
  195. onchange() {
  196. config.set(key, this.checked);
  197. },
  198. }));
  199. break;
  200. }
  201. case "count": {
  202. control.appendChild(newElement("input", {
  203. id,
  204. type: "number",
  205. min: "0",
  206. value: config.get(key, defaultValue),
  207. onchange() {
  208. config.set(key, +this.value);
  209. },
  210. }));
  211. break;
  212. }
  213. default:
  214. throw new TypeError(`AtCoderEasyTest.setting: undefined option type ${type} for ${key}`);
  215. }
  216. }
  217. root.appendChild(newElement("button", {
  218. className: "btn btn-danger",
  219. textContent: "Reset",
  220. type: "button",
  221. onclick() {
  222. if (win.confirm("Configuration data will be cleared. Are you sure?")) {
  223. config.reset();
  224. }
  225. },
  226. }));
  227. return root;
  228. });
  229. const config = {
  230. getString(key, defaultValue = "") {
  231. if (!(key in data))
  232. config.setString(key, defaultValue);
  233. return data[key];
  234. },
  235. setString(key, value) {
  236. data[key] = value;
  237. save();
  238. },
  239. has(key) {
  240. return key in data;
  241. },
  242. get(key, defaultValue = null) {
  243. if (!(key in data))
  244. config.set(key, defaultValue);
  245. return JSON.parse(data[key]);
  246. },
  247. set(key, value) {
  248. config.setString(key, JSON.stringify(value));
  249. },
  250. save,
  251. load,
  252. toString,
  253. reset,
  254. /** 設定項目を登録 */
  255. registerFlag(key, defaultValue, description) {
  256. options.push({
  257. type: "flag",
  258. key,
  259. defaultValue,
  260. description,
  261. });
  262. },
  263. registerCount(key, defaultValue, description) {
  264. options.push({
  265. type: "count",
  266. key,
  267. defaultValue,
  268. description,
  269. });
  270. },
  271. };
  272.  
  273. config.registerCount("codeSaver.limit", 10, "Max number to save codes");
  274. const codeSaver = {
  275. get() {
  276. // `json` は、ソースコード文字列またはJSON文字列
  277. let json = unsafeWindow.localStorage.AtCoderEasyTest$lastCode;
  278. let data = [];
  279. try {
  280. if (typeof json == "string") {
  281. data.push(...JSON.parse(json));
  282. }
  283. else {
  284. data = [];
  285. }
  286. }
  287. catch (e) {
  288. data.push({
  289. path: unsafeWindow.localStorage.AtCoderEasyTset$lastPage,
  290. code: json,
  291. });
  292. }
  293. return data;
  294. },
  295. set(data) {
  296. unsafeWindow.localStorage.AtCoderEasyTest$lastCode = JSON.stringify(data);
  297. },
  298. save(code) {
  299. let data = codeSaver.get();
  300. const idx = data.findIndex(({ path }) => path == location.pathname);
  301. if (idx != -1)
  302. data.splice(idx, idx + 1);
  303. data.push({
  304. path: location.pathname,
  305. code,
  306. });
  307. while (data.length > config.get("codeSaver.limit", 10))
  308. data.shift();
  309. codeSaver.set(data);
  310. },
  311. restore() {
  312. const data = codeSaver.get();
  313. const idx = data.findIndex(({ path }) => path == location.pathname);
  314. if (idx == -1 || !(data[idx] instanceof Object))
  315. return Promise.reject(`No saved code found for ${location.pathname}`);
  316. return Promise.resolve(data[idx].code);
  317. }
  318. };
  319. settings.add(`codeSaver (${location.host})`, (win) => {
  320. const root = newElement("table", { className: "table" }, [
  321. newElement("thead", {}, [
  322. newElement("tr", {}, [
  323. newElement("th", { textContent: "path" }),
  324. newElement("th", { textContent: "code" }),
  325. ]),
  326. ]),
  327. newElement("tbody"),
  328. ]);
  329. root.tBodies;
  330. for (const savedCode of codeSaver.get()) {
  331. root.tBodies[0].appendChild(newElement("tr", {}, [
  332. newElement("td", { textContent: savedCode.path }),
  333. newElement("td", {}, [
  334. newElement("textarea", {
  335. rows: 1,
  336. cols: 30,
  337. textContent: savedCode.code,
  338. }),
  339. ]),
  340. ]));
  341. }
  342. return root;
  343. });
  344.  
  345. function similarLangs(targetLang, candidateLangs) {
  346. const [targetName, targetDetail] = targetLang.split(" ", 2);
  347. const selectedLangs = candidateLangs.filter(candidateLang => {
  348. const [name, _] = candidateLang.split(" ", 2);
  349. return name == targetName;
  350. }).map(candidateLang => {
  351. const [_, detail] = candidateLang.split(" ", 2);
  352. return [candidateLang, similarity(detail, targetDetail)];
  353. });
  354. return selectedLangs.sort((a, b) => a[1] - b[1]).map(([lang, _]) => lang);
  355. }
  356. function similarity(s, t) {
  357. const n = s.length, m = t.length;
  358. let dp = new Array(m + 1).fill(0);
  359. for (let i = 0; i < n; i++) {
  360. const dp2 = new Array(m + 1).fill(0);
  361. for (let j = 0; j < m; j++) {
  362. const cost = (s.charCodeAt(i) - t.charCodeAt(j)) ** 2;
  363. dp2[j + 1] = Math.min(dp[j] + cost, dp[j + 1] + cost * 0.25, dp2[j] + cost * 0.25);
  364. }
  365. dp = dp2;
  366. }
  367. return dp[m];
  368. }
  369.  
  370. class CodeRunner {
  371. get label() {
  372. return this._label;
  373. }
  374. constructor(label, site) {
  375. this._label = `${label} [${site}]`;
  376. }
  377. async test(sourceCode, input, expectedOutput, options) {
  378. let result = { status: "IE", input };
  379. try {
  380. result = await this.run(sourceCode, input);
  381. }
  382. catch (e) {
  383. result.error = e.toString();
  384. return result;
  385. }
  386. if (expectedOutput != null)
  387. result.expectedOutput = expectedOutput;
  388. if (result.status != "OK" || typeof expectedOutput != "string")
  389. return result;
  390. let output = result.output || "";
  391. if (options.trim) {
  392. expectedOutput = expectedOutput.trim();
  393. output = output.trim();
  394. }
  395. let equals = (x, y) => x === y;
  396. if (options.allowableError) {
  397. const floatPattern = /^[-+]?[0-9]*\.[0-9]+([eE][-+]?[0-9]+)?$/;
  398. const superEquals = equals;
  399. equals = (x, y) => {
  400. if (floatPattern.test(x) || floatPattern.test(y))
  401. return Math.abs(parseFloat(x) - parseFloat(y)) <= options.allowableError;
  402. return superEquals(x, y);
  403. };
  404. }
  405. if (options.split) {
  406. const superEquals = equals;
  407. equals = (x, y) => {
  408. const xs = x.split(/\s+/);
  409. const ys = y.split(/\s+/);
  410. if (xs.length != ys.length)
  411. return false;
  412. const len = xs.length;
  413. for (let i = 0; i < len; i++) {
  414. if (!superEquals(xs[i], ys[i]))
  415. return false;
  416. }
  417. return true;
  418. };
  419. }
  420. result.status = equals(output, expectedOutput) ? "AC" : "WA";
  421. return result;
  422. }
  423. }
  424.  
  425. class CustomRunner extends CodeRunner {
  426. run;
  427. constructor(label, run) {
  428. super(label, "Browser");
  429. this.run = run;
  430. }
  431. }
  432.  
  433. let waitAtCoderCustomTest = Promise.resolve();
  434. const AtCoderCustomTestBase = location.href.replace(/\/tasks\/.+$/, "/custom_test");
  435. const AtCoderCustomTestResultAPI = AtCoderCustomTestBase + "/json?reload=true";
  436. const AtCoderCustomTestSubmitAPI = AtCoderCustomTestBase + "/submit/json";
  437. class AtCoderRunner extends CodeRunner {
  438. languageId;
  439. constructor(languageId, label) {
  440. super(label, "AtCoder");
  441. this.languageId = languageId;
  442. }
  443. async run(sourceCode, input) {
  444. const promise = this.submit(sourceCode, input);
  445. waitAtCoderCustomTest = promise;
  446. return await promise;
  447. }
  448. async submit(sourceCode, input) {
  449. try {
  450. await waitAtCoderCustomTest;
  451. }
  452. catch (error) {
  453. console.error(error);
  454. }
  455. const error = await fetch(AtCoderCustomTestSubmitAPI, {
  456. method: "POST",
  457. credentials: "include",
  458. headers: {
  459. "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
  460. },
  461. body: buildParams({
  462. "data.LanguageId": String(this.languageId),
  463. sourceCode,
  464. input,
  465. csrf_token: unsafeWindow.csrfToken,
  466. }),
  467. }).then(r => r.text());
  468. if (error) {
  469. throw new Error(error);
  470. }
  471. await sleep(100);
  472. for (;;) {
  473. const data = await fetch(AtCoderCustomTestResultAPI, {
  474. method: "GET",
  475. credentials: "include",
  476. }).then(r => r.json());
  477. if (!("Result" in data))
  478. continue;
  479. const result = data.Result;
  480. if ("Interval" in data) {
  481. await sleep(data.Interval);
  482. continue;
  483. }
  484. return {
  485. status: (result.ExitCode == 0) ? "OK" : (result.TimeConsumption == -1) ? "CE" : "RE",
  486. exitCode: result.ExitCode,
  487. execTime: result.TimeConsumption,
  488. memory: result.MemoryConsumption,
  489. input,
  490. output: data.Stdout,
  491. error: data.Stderr,
  492. };
  493. }
  494. }
  495. }
  496.  
  497. class PaizaIORunner extends CodeRunner {
  498. name;
  499. constructor(name, label) {
  500. super(label, "PaizaIO");
  501. this.name = name;
  502. }
  503. async run(sourceCode, input) {
  504. let id, status, error;
  505. try {
  506. const res = await fetch("https://api.paiza.io/runners/create?" + buildParams({
  507. source_code: sourceCode,
  508. language: this.name,
  509. input,
  510. longpoll: "true",
  511. longpoll_timeout: "10",
  512. api_key: "guest",
  513. }), {
  514. method: "POST",
  515. mode: "cors",
  516. }).then(r => r.json());
  517. id = res.id;
  518. status = res.status;
  519. error = res.error;
  520. }
  521. catch (error) {
  522. return {
  523. status: "IE",
  524. input,
  525. error: String(error),
  526. };
  527. }
  528. while (status == "running") {
  529. const res = await fetch("https://api.paiza.io/runners/get_status?" + buildParams({
  530. id,
  531. api_key: "guest",
  532. }), {
  533. mode: "cors",
  534. }).then(res => res.json());
  535. status = res.status;
  536. error = res.error;
  537. }
  538. const res = await fetch("https://api.paiza.io/runners/get_details?" + buildParams({
  539. id,
  540. api_key: "guest",
  541. }), {
  542. mode: "cors",
  543. }).then(r => r.json());
  544. const result = {
  545. status: "OK",
  546. exitCode: String(res.exit_code),
  547. execTime: +res.time * 1e3,
  548. memory: +res.memory * 1e-3,
  549. input,
  550. };
  551. if (res.build_result == "failure") {
  552. result.status = "CE";
  553. result.exitCode = res.build_exit_code;
  554. result.output = res.build_stdout;
  555. result.error = res.build_stderr;
  556. }
  557. else {
  558. result.status = (res.result == "timeout") ? "TLE" : (res.result == "failure") ? "RE" : "OK";
  559. result.exitCode = res.exit_code;
  560. result.output = res.stdout;
  561. result.error = res.stderr;
  562. }
  563. return result;
  564. }
  565. }
  566.  
  567. class WandboxRunner extends CodeRunner {
  568. name;
  569. options;
  570. constructor(name, label, options = {}) {
  571. super(label, "Wandbox");
  572. this.name = name;
  573. this.options = options;
  574. }
  575. getOptions(sourceCode, input) {
  576. if (typeof this.options == "function")
  577. return this.options(sourceCode, input);
  578. return this.options;
  579. }
  580. run(sourceCode, input) {
  581. const options = this.getOptions(sourceCode, input);
  582. return this.request(Object.assign({
  583. compiler: this.name,
  584. code: sourceCode,
  585. stdin: input,
  586. }, options));
  587. }
  588. async request(body) {
  589. const startTime = Date.now();
  590. let res;
  591. try {
  592. res = await fetch("https://wandbox.org/api/compile.json", {
  593. method: "POST",
  594. mode: "cors",
  595. headers: {
  596. "Content-Type": "application/json",
  597. },
  598. body: JSON.stringify(body),
  599. }).then(r => r.json());
  600. }
  601. catch (error) {
  602. console.error(error);
  603. return {
  604. status: "IE",
  605. input: body.stdin,
  606. error: String(error),
  607. };
  608. }
  609. const endTime = Date.now();
  610. const result = {
  611. status: "OK",
  612. exitCode: String(res.status),
  613. execTime: endTime - startTime,
  614. input: body.stdin,
  615. output: String(res.program_output || ""),
  616. error: String(res.program_error || ""),
  617. };
  618. // 正常終了以外の場合
  619. if (res.status != 0) {
  620. if (res.signal) {
  621. result.exitCode += ` (${res.signal})`;
  622. }
  623. result.output = String(res.compiler_output || "") + String(result.output || "");
  624. result.error = String(res.compiler_error || "") + String(result.error || "");
  625. if (res.compiler_output || res.compiler_error) {
  626. result.status = "CE";
  627. }
  628. else {
  629. result.status = "RE";
  630. }
  631. }
  632. return result;
  633. }
  634. }
  635.  
  636. class WandboxCppRunner extends WandboxRunner {
  637. async run(sourceCode, input) {
  638. // ACL を結合する
  639. const ACLBase = "https://cdn.jsdelivr.net/gh/atcoder/ac-library/";
  640. const files = new Map();
  641. const includeHeader = async (source) => {
  642. const pattern = /^#\s*include\s*[<"]atcoder\/([^>"]+)[>"]/gm;
  643. const loaded = [];
  644. let match;
  645. while (match = pattern.exec(source)) {
  646. const file = "atcoder/" + match[1];
  647. if (files.has(file))
  648. continue;
  649. files.set(file, null);
  650. loaded.push([file, fetch(ACLBase + file, { mode: "cors", cache: "force-cache", }).then(r => r.text())]);
  651. }
  652. const included = await Promise.all(loaded.map(async ([file, r]) => {
  653. const source = await r;
  654. files.set(file, source);
  655. return source;
  656. }));
  657. for (const source of included) {
  658. await includeHeader(source);
  659. }
  660. };
  661. await includeHeader(sourceCode);
  662. const codes = [];
  663. for (const [file, code] of files) {
  664. codes.push({ file, code, });
  665. }
  666. const options = this.getOptions(sourceCode, input);
  667. return await this.request(Object.assign({
  668. compiler: this.name,
  669. code: sourceCode,
  670. stdin: input,
  671. codes,
  672. "compiler-option-raw": "-I.",
  673. }, options));
  674. }
  675. }
  676.  
  677. let brythonRunnerLoaded = false;
  678. const brythonRunner = new CustomRunner("Brython", async (sourceCode, input) => {
  679. if (!brythonRunnerLoaded) {
  680. // BrythonRunner を読み込む
  681. await new Promise((resolve) => {
  682. const script = document.createElement("script");
  683. script.src = "https://cdn.jsdelivr.net/gh/pythonpad/brython-runner/lib/brython-runner.bundle.js";
  684. script.onload = () => {
  685. brythonRunnerLoaded = true;
  686. resolve(null);
  687. };
  688. document.head.appendChild(script);
  689. });
  690. }
  691. let stdout = "";
  692. let stderr = "";
  693. let stdinOffset = 0;
  694. const BrythonRunner = unsafeWindow.BrythonRunner;
  695. const runner = new BrythonRunner({
  696. stdout: { write(content) { stdout += content; }, flush() { } },
  697. stderr: { write(content) { stderr += content; }, flush() { } },
  698. stdin: { async readline() {
  699. let index = input.indexOf("\n", stdinOffset) + 1;
  700. if (index == 0)
  701. index = input.length;
  702. const text = input.slice(stdinOffset, index);
  703. stdinOffset = index;
  704. return text;
  705. } },
  706. });
  707. const timeStart = Date.now();
  708. await runner.runCode(sourceCode);
  709. const timeEnd = Date.now();
  710. return {
  711. status: "OK",
  712. exitCode: "0",
  713. execTime: (timeEnd - timeStart),
  714. input,
  715. output: stdout,
  716. error: stderr,
  717. };
  718. });
  719.  
  720. async function loadPyodide() {
  721. const script = await fetch("https://cdn.jsdelivr.net/pyodide/v0.18.1/full/pyodide.js").then(res => res.text());
  722. unsafeWindow["Function"](script)();
  723. const pyodide = await unsafeWindow["loadPyodide"]({
  724. indexURL: "https://cdn.jsdelivr.net/pyodide/v0.18.1/full/",
  725. });
  726. await pyodide.runPythonAsync(`
  727. import contextlib, io, platform
  728. class __redirect_stdin(contextlib._RedirectStream):
  729. _stream = "stdin"
  730. `);
  731. return pyodide;
  732. }
  733. let _pyodide = Promise.reject("Pyodide is not yet loaded");
  734. let _serial = Promise.resolve();
  735. const pyodideRunner = new CustomRunner("Pyodide", (sourceCode, input) => new Promise((resolve, reject) => {
  736. _serial = _serial.finally(async () => {
  737. const pyodide = await (_pyodide = _pyodide.catch(loadPyodide));
  738. const code = `
  739. def __run():
  740. global __stdout, __stderr, __stdin, __code
  741. with __redirect_stdin(io.StringIO(__stdin)):
  742. with contextlib.redirect_stdout(io.StringIO()) as __stdout:
  743. with contextlib.redirect_stderr(io.StringIO()) as __stderr:
  744. try:
  745. pass
  746. ` + sourceCode.split("\n").map(line => " " + line).join("\n") + `
  747. except SystemExit as e:
  748. __code = e.code
  749. `;
  750. let status = "OK";
  751. let exitCode = "0";
  752. let stdout = "";
  753. let stderr = "";
  754. let startTime = -Infinity;
  755. let endTime = Infinity;
  756. pyodide.globals.__stdin = input;
  757. try {
  758. pyodide.globals.__code = null;
  759. await pyodide.loadPackagesFromImports(code);
  760. await pyodide.runPythonAsync(code);
  761. startTime = Date.now();
  762. pyodide.runPython("__run()");
  763. endTime = Date.now();
  764. stdout += pyodide.globals.__stdout.getvalue();
  765. stderr += pyodide.globals.__stderr.getvalue();
  766. if (typeof pyodide.globals.__code == "number") {
  767. exitCode = String(pyodide.globals.__code);
  768. if (pyodide.globals.__code != 0)
  769. status = "RE";
  770. }
  771. }
  772. catch (error) {
  773. status = "RE";
  774. exitCode = "-1";
  775. stderr += error.toString();
  776. }
  777. resolve({
  778. status,
  779. exitCode,
  780. execTime: (endTime - startTime),
  781. input,
  782. output: stdout,
  783. error: stderr,
  784. });
  785. });
  786. }));
  787.  
  788. function pairs(list) {
  789. const pairs = [];
  790. const len = list.length >> 1;
  791. for (let i = 0; i < len; i++)
  792. pairs.push([list[i * 2], list[i * 2 + 1]]);
  793. return pairs;
  794. }
  795. async function init$5() {
  796. if (location.host != "atcoder.jp")
  797. throw "Not AtCoder";
  798. const doc = unsafeWindow.document;
  799. const eLanguage = unsafeWindow.$("#select-lang>select");
  800. const langMap = {
  801. 4001: "C GCC 9.2.1",
  802. 4002: "C Clang 10.0.0",
  803. 4003: "C++ GCC 9.2.1",
  804. 4004: "C++ Clang 10.0.0",
  805. 4005: "Java OpenJDK 11.0.6",
  806. 4006: "Python3 CPython 3.8.2",
  807. 4007: "Bash 5.0.11",
  808. 4008: "bc 1.07.1",
  809. 4009: "Awk GNU Awk 4.1.4",
  810. 4010: "C# .NET Core 3.1.201",
  811. 4011: "C# Mono-mcs 6.8.0.105",
  812. 4012: "C# Mono-csc 3.5.0",
  813. 4013: "Clojure 1.10.1.536",
  814. 4014: "Crystal 0.33.0",
  815. 4015: "D DMD 2.091.0",
  816. 4016: "D GDC 9.2.1",
  817. 4017: "D LDC 1.20.1",
  818. 4018: "Dart 2.7.2",
  819. 4019: "dc 1.4.1",
  820. 4020: "Erlang 22.3",
  821. 4021: "Elixir 1.10.2",
  822. 4022: "F# .NET Core 3.1.201",
  823. 4023: "F# Mono 10.2.3",
  824. 4024: "Forth gforth 0.7.3",
  825. 4025: "Fortran GNU Fortran 9.2.1",
  826. 4026: "Go 1.14.1",
  827. 4027: "Haskell GHC 8.8.3",
  828. 4028: "Haxe 4.0.3",
  829. 4029: "Haxe 4.0.3",
  830. 4030: "JavaScript Node.js 12.16.1",
  831. 4031: "Julia 1.4.0",
  832. 4032: "Kotlin 1.3.71",
  833. 4033: "Lua Lua 5.3.5",
  834. 4034: "Lua LuaJIT 2.1.0",
  835. 4035: "Dash 0.5.8",
  836. 4036: "Nim 1.0.6",
  837. 4037: "Objective-C Clang 10.0.0",
  838. 4038: "Lisp SBCL 2.0.3",
  839. 4039: "OCaml 4.10.0",
  840. 4040: "Octave 5.2.0",
  841. 4041: "Pascal FPC 3.0.4",
  842. 4042: "Perl 5.26.1",
  843. 4043: "Raku Rakudo 2020.02.1",
  844. 4044: "PHP 7.4.4",
  845. 4045: "Prolog SWI-Prolog 8.0.3",
  846. 4046: "Python PyPy2 7.3.0",
  847. 4047: "Python3 PyPy3 7.3.0",
  848. 4048: "Racket 7.6",
  849. 4049: "Ruby 2.7.1",
  850. 4050: "Rust 1.42.0",
  851. 4051: "Scala 2.13.1",
  852. 4052: "Java OpenJDK 1.8.0",
  853. 4053: "Scheme Gauche 0.9.9",
  854. 4054: "ML MLton 20130715",
  855. 4055: "Swift 5.2.1",
  856. 4056: "Text cat 8.28",
  857. 4057: "TypeScript 3.8",
  858. 4058: "Basic .NET Core 3.1.101",
  859. 4059: "Zsh 5.4.2",
  860. 4060: "COBOL Fixed OpenCOBOL 1.1.0",
  861. 4061: "COBOL Free OpenCOBOL 1.1.0",
  862. 4062: "Brainfuck bf 20041219",
  863. 4063: "Ada Ada2012 GNAT 9.2.1",
  864. 4064: "Unlambda 2.0.0",
  865. 4065: "Cython 0.29.16",
  866. 4066: "Sed 4.4",
  867. 4067: "Vim 8.2.0460",
  868. };
  869. const languageId = new ObservableValue(eLanguage.val());
  870. eLanguage.change(() => {
  871. languageId.value = eLanguage.val();
  872. });
  873. const language = languageId.map(lang => langMap[lang]);
  874. function getTestCases() {
  875. const selectors = [
  876. ["#task-statement p+pre.literal-block", ".section"],
  877. ["#task-statement pre.source-code-for-copy", ".part"],
  878. ["#task-statement .lang>*:nth-child(1) .div-btn-copy+pre", ".part"],
  879. ["#task-statement .div-btn-copy+pre", ".part"],
  880. ["#task-statement>.part pre.linenums", ".part"],
  881. ["#task-statement>.part section>pre", ".part"],
  882. ["#task-statement>.part:not(.io-style)>h3+section>pre", ".part"],
  883. ["#task-statement pre", ".part"],
  884. ];
  885. for (const [selector, closestSelector] of selectors) {
  886. let e = [...doc.querySelectorAll(selector)];
  887. e = e.filter(e => {
  888. if (e.closest(".io-style"))
  889. return false; // practice2
  890. if (e.querySelector("var"))
  891. return false;
  892. return true;
  893. });
  894. if (e.length == 0)
  895. continue;
  896. return pairs(e).map(([input, output], index) => {
  897. const container = input.closest(closestSelector) || input.parentElement;
  898. return {
  899. selector,
  900. title: `Sample ${index + 1}`,
  901. input: input.textContent,
  902. output: output.textContent,
  903. anchor: container.querySelector(".btn-copy") || container.querySelector("h1,h2,h3,h4,h5,h6"),
  904. };
  905. });
  906. }
  907. { // maximum_cup_2018_d
  908. let e = [...doc.querySelectorAll("#task-statement .div-btn-copy+pre")];
  909. e = e.filter(f => !f.childElementCount);
  910. if (e.length) {
  911. return pairs(e).map(([input, output], index) => ({
  912. selector: "#task-statement .div-btn-copy+pre",
  913. title: `Sample ${index + 1}`,
  914. input: input.textContent,
  915. output: output.textContent,
  916. anchor: (input.closest(".part") || input.parentElement).querySelector(".btn-copy"),
  917. }));
  918. }
  919. }
  920. return [];
  921. }
  922. return {
  923. name: "AtCoder",
  924. language,
  925. get sourceCode() {
  926. return unsafeWindow.getSourceCode();
  927. },
  928. set sourceCode(sourceCode) {
  929. doc.querySelector(".plain-textarea").value = sourceCode;
  930. unsafeWindow.$(".editor").data("editor").doc.setValue(sourceCode);
  931. },
  932. submit() {
  933. doc.querySelector("#submit").click();
  934. },
  935. get testButtonContainer() {
  936. return doc.querySelector("#submit").parentElement;
  937. },
  938. get sideButtonContainer() {
  939. return doc.querySelector(".editor-buttons");
  940. },
  941. get bottomMenuContainer() {
  942. return doc.getElementById("main-div");
  943. },
  944. get resultListContainer() {
  945. return doc.querySelector(".form-code-submit");
  946. },
  947. get testCases() {
  948. return getTestCases();
  949. },
  950. get jQuery() {
  951. return unsafeWindow["jQuery"];
  952. },
  953. };
  954. }
  955.  
  956. async function init$4() {
  957. if (location.host != "yukicoder.me")
  958. throw "Not yukicoder";
  959. const $ = unsafeWindow.$;
  960. const doc = unsafeWindow.document;
  961. const editor = unsafeWindow.ace.edit("rich_source");
  962. const eSourceObject = $("#source");
  963. const eLang = $("#lang");
  964. const eSamples = $(".sample");
  965. const langMap = {
  966. "cpp14": "C++ C++14 GCC 11.1.0 + Boost 1.77.0",
  967. "cpp17": "C++ C++17 GCC 11.1.0 + Boost 1.77.0",
  968. "cpp-clang": "C++ C++17 Clang 10.0.0 + Boost 1.76.0",
  969. "cpp23": "C++ C++11 GCC 8.4.1",
  970. "c11": "C++ C++11 GCC 11.1.0",
  971. "c": "C C90 GCC 8.4.1",
  972. "java8": "Java Java16 OpenJDK 16.0.1",
  973. "csharp": "C# CSC 3.9.0",
  974. "csharp_mono": "C# Mono 6.12.0.147",
  975. "csharp_dotnet": "C# .NET 5.0",
  976. "perl": "Perl 5.26.3",
  977. "raku": "Raku Rakudo v2021-07-2-g74d7ff771",
  978. "php": "PHP 7.2.24",
  979. "php7": "PHP 8.0.8",
  980. "python3": "Python3 3.9.6 + numpy 1.14.5 + scipy 1.1.0",
  981. "pypy2": "Python PyPy2 7.3.5",
  982. "pypy3": "Python3 PyPy3 7.3.5",
  983. "ruby": "Ruby 3.0.2p107",
  984. "d": "D DMD 2.097.1",
  985. "go": "Go 1.16.6",
  986. "haskell": "Haskell 8.10.5",
  987. "scala": "Scala 2.13.6",
  988. "nim": "Nim 1.4.8",
  989. "rust": "Rust 1.53.0",
  990. "kotlin": "Kotlin 1.5.21",
  991. "scheme": "Scheme Gauche 0.9.10",
  992. "crystal": "Crystal 1.1.1",
  993. "swift": "Swift 5.4.2",
  994. "ocaml": "OCaml 4.12.0",
  995. "clojure": "Clojure 1.10.2.790",
  996. "fsharp": "F# 5.0",
  997. "elixir": "Elixir 1.7.4",
  998. "lua": "Lua LuaJIT 2.0.5",
  999. "fortran": "Fortran gFortran 8.4.1",
  1000. "node": "JavaScript Node.js 15.5.0",
  1001. "typescript": "TypeScript 4.3.5",
  1002. "lisp": "Lisp Common Lisp sbcl 2.1.6",
  1003. "sml": "ML Standard ML MLton 20180207-6",
  1004. "kuin": "Kuin KuinC++ v.2021.7.17",
  1005. "vim": "Vim v8.2",
  1006. "sh": "Bash 4.4.19",
  1007. "nasm": "Assembler nasm 2.13.03",
  1008. "clay": "cLay 20210917-1",
  1009. "bf": "Brainfuck BFI 1.1",
  1010. "Whitespace": "Whitespace 0.3",
  1011. "text": "Text cat 8.3",
  1012. };
  1013. // place anchor elements
  1014. for (const btnCopyInput of doc.querySelectorAll(".copy-sample-input")) {
  1015. btnCopyInput.parentElement.insertBefore(newElement("span", { className: "atcoder-easy-test-anchor" }), btnCopyInput);
  1016. }
  1017. const language = new ObservableValue(langMap[eLang.val()]);
  1018. eLang.on("change", () => {
  1019. language.value = langMap[eLang.val()];
  1020. });
  1021. return {
  1022. name: "yukicoder",
  1023. language,
  1024. get sourceCode() {
  1025. if (eSourceObject.is(":visible"))
  1026. return eSourceObject.val();
  1027. return editor.getSession().getValue();
  1028. },
  1029. set sourceCode(sourceCode) {
  1030. eSourceObject.val(sourceCode);
  1031. editor.getSession().setValue(sourceCode);
  1032. },
  1033. submit() {
  1034. doc.querySelector(`#submit_form input[type="submit"]`).click();
  1035. },
  1036. get testButtonContainer() {
  1037. return doc.querySelector("#submit_form");
  1038. },
  1039. get sideButtonContainer() {
  1040. return doc.querySelector("#toggle_source_editor").parentElement;
  1041. },
  1042. get bottomMenuContainer() {
  1043. return doc.body;
  1044. },
  1045. get resultListContainer() {
  1046. return doc.querySelector("#content");
  1047. },
  1048. get testCases() {
  1049. const testCases = [];
  1050. let sampleId = 1;
  1051. for (let i = 0; i < eSamples.length; i++) {
  1052. const eSample = eSamples.eq(i);
  1053. const [eInput, eOutput] = eSample.find("pre");
  1054. testCases.push({
  1055. title: `Sample ${sampleId++}`,
  1056. input: eInput.textContent,
  1057. output: eOutput.textContent,
  1058. anchor: eSample.find(".atcoder-easy-test-anchor")[0],
  1059. });
  1060. }
  1061. return testCases;
  1062. },
  1063. get jQuery() {
  1064. return $;
  1065. },
  1066. };
  1067. }
  1068.  
  1069. class Editor {
  1070. _element;
  1071. constructor(lang) {
  1072. this._element = document.createElement("textarea");
  1073. this._element.style.fontFamily = "monospace";
  1074. this._element.style.width = "100%";
  1075. this._element.style.minHeight = "5em";
  1076. }
  1077. get element() {
  1078. return this._element;
  1079. }
  1080. get sourceCode() {
  1081. return this._element.value;
  1082. }
  1083. set sourceCode(sourceCode) {
  1084. this._element.value = sourceCode;
  1085. }
  1086. setLanguage(lang) {
  1087. }
  1088. }
  1089.  
  1090. var langMap = {
  1091. 3: "Delphi 7",
  1092. 4: "Pascal Free Pascal 3.0.2",
  1093. 6: "PHP 7.2.13",
  1094. 7: "Python 2.7.18",
  1095. 9: "C# Mono 6.8",
  1096. 12: "Haskell GHC 8.10.1",
  1097. 13: "Perl 5.20.1",
  1098. 19: "OCaml 4.02.1",
  1099. 20: "Scala 2.12.8",
  1100. 28: "D DMD32 v2.091.0",
  1101. 31: "Python3 3.8.10",
  1102. 32: "Go 1.15.6",
  1103. 34: "JavaScript V8 4.8.0",
  1104. 36: "Java 1.8.0_241",
  1105. 40: "Python PyPy2 2.7 (7.3.0)",
  1106. 41: "Python3 PyPy3 3.7 (7.3.0)",
  1107. 43: "C C11 GCC 5.1.0",
  1108. 48: "Kotlin 1.5.31",
  1109. 49: "Rust 1.49.0",
  1110. 50: "C++ C++14 G++ 6.4.0",
  1111. 51: "Pascal PascalABC.NET 3.4.1",
  1112. 52: "C++ C++17 Clang++",
  1113. 54: "C++ C++17 G++ 7.3.0",
  1114. 55: "JavaScript Node.js 12.6.3",
  1115. 59: "C++ Microsoft Visual C++ 2017",
  1116. 60: "Java 11.0.6",
  1117. 61: "C++ C++17 9.2.0 (64 bit, msys 2)",
  1118. 65: "C# 8, .NET Core 3.1",
  1119. 67: "Ruby 3.0.0",
  1120. 70: "Python3 PyPy 3.7 (7.3.5, 64bit)",
  1121. 72: "Kotlin 1.5.31",
  1122. 73: "C++ GNU G++ 11.2.0 (64 bit, winlibs)",
  1123. };
  1124.  
  1125. config.registerFlag("site.codeforces.showEditor", true, "Show Editor in Codeforces Problem Page");
  1126. async function init$3() {
  1127. if (location.host != "codeforces.com")
  1128. throw "not Codeforces";
  1129. //TODO: m1.codeforces.com, m2.codeforces.com, m3.codeforces.com に対応する
  1130. const doc = unsafeWindow.document;
  1131. const eLang = doc.querySelector("select[name='programTypeId']");
  1132. doc.head.appendChild(newElement("link", {
  1133. rel: "stylesheet",
  1134. href: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css",
  1135. }));
  1136. doc.head.appendChild(newElement("style", {
  1137. textContent: `
  1138. .atcoder-easy-test-btn-run-case {
  1139. float: right;
  1140. line-height: 1.1rem;
  1141. }
  1142. `,
  1143. }));
  1144. const eButtons = newElement("span");
  1145. doc.querySelector(".submitForm").appendChild(eButtons);
  1146. await loadScript("https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js");
  1147. const jQuery = unsafeWindow["jQuery"].noConflict();
  1148. unsafeWindow["jQuery"] = unsafeWindow["$"];
  1149. unsafeWindow["jQuery11"] = jQuery;
  1150. await loadScript("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js", null, { jQuery, $: jQuery });
  1151. const language = new ObservableValue(langMap[eLang.value]);
  1152. eLang.addEventListener("change", () => {
  1153. language.value = langMap[eLang.value];
  1154. });
  1155. let _sourceCode = "";
  1156. const eFile = doc.querySelector(".submitForm").elements["sourceFile"];
  1157. eFile.addEventListener("change", async () => {
  1158. if (eFile.files[0]) {
  1159. _sourceCode = await eFile.files[0].text();
  1160. if (editor)
  1161. editor.sourceCode = _sourceCode;
  1162. }
  1163. });
  1164. let editor = null;
  1165. let waitCfFastSubmitCount = 0;
  1166. const waitCfFastSubmit = setInterval(() => {
  1167. if (document.getElementById("editor")) {
  1168. // cf-fast-submit
  1169. if (editor && editor.element)
  1170. editor.element.style.display = "none";
  1171. // 言語セレクトを同期させる
  1172. const eLang2 = doc.querySelector(".submit-form select[name='programTypeId']");
  1173. if (eLang2) {
  1174. eLang.addEventListener("change", () => {
  1175. eLang2.value = eLang.value;
  1176. });
  1177. eLang2.addEventListener("change", () => {
  1178. eLang.value = eLang2.value;
  1179. language.value = langMap[eLang.value];
  1180. });
  1181. }
  1182. // TODO: 選択されたファイルをどうかする
  1183. // エディタを使う
  1184. const aceEditor = unsafeWindow["ace"].edit("editor");
  1185. editor = {
  1186. get sourceCode() {
  1187. return aceEditor.getValue();
  1188. },
  1189. set sourceCode(sourceCode) {
  1190. aceEditor.setValue(sourceCode);
  1191. },
  1192. setLanguage(lang) { },
  1193. };
  1194. // ボタンを追加する
  1195. const buttonContainer = doc.querySelector(".submit-form .submit").parentElement;
  1196. buttonContainer.appendChild(newElement("button", {
  1197. type: "button",
  1198. className: "btn btn-info",
  1199. textContent: "Test & Submit",
  1200. onclick: () => events.trig("testAndSubmit"),
  1201. }));
  1202. buttonContainer.appendChild(newElement("button", {
  1203. type: "button",
  1204. className: "btn btn-default",
  1205. textContent: "Test All Samples",
  1206. onclick: () => events.trig("testAllSamples"),
  1207. }));
  1208. clearInterval(waitCfFastSubmit);
  1209. }
  1210. else {
  1211. waitCfFastSubmitCount++;
  1212. if (waitCfFastSubmitCount >= 100)
  1213. clearInterval(waitCfFastSubmit);
  1214. }
  1215. }, 100);
  1216. if (config.get("site.codeforces.showEditor", true)) {
  1217. editor = new Editor(langMap[eLang.value].split(" ")[0]);
  1218. doc.getElementById("pageContent").appendChild(editor.element);
  1219. language.addListener(lang => {
  1220. editor.setLanguage(lang);
  1221. });
  1222. }
  1223. return {
  1224. name: "Codeforces",
  1225. language,
  1226. get sourceCode() {
  1227. if (editor)
  1228. return editor.sourceCode;
  1229. return _sourceCode;
  1230. },
  1231. set sourceCode(sourceCode) {
  1232. const container = new DataTransfer();
  1233. container.items.add(new File([sourceCode], "prog.txt", { type: "text/plain" }));
  1234. const eFile = doc.querySelector(".submitForm").elements["sourceFile"];
  1235. eFile.files = container.files;
  1236. _sourceCode = sourceCode;
  1237. if (editor)
  1238. editor.sourceCode = sourceCode;
  1239. },
  1240. submit() {
  1241. if (editor)
  1242. _sourceCode = editor.sourceCode;
  1243. this.sourceCode = _sourceCode;
  1244. doc.querySelector(`.submitForm .submit`).click();
  1245. },
  1246. get testButtonContainer() {
  1247. return eButtons;
  1248. },
  1249. get sideButtonContainer() {
  1250. return eButtons;
  1251. },
  1252. get bottomMenuContainer() {
  1253. return doc.body;
  1254. },
  1255. get resultListContainer() {
  1256. return doc.querySelector("#pageContent");
  1257. },
  1258. get testCases() {
  1259. const testcases = [];
  1260. let num = 1;
  1261. for (const eSampleTest of doc.querySelectorAll(".sample-test")) {
  1262. const inputs = eSampleTest.querySelectorAll(".input pre");
  1263. const outputs = eSampleTest.querySelectorAll(".output pre");
  1264. const anchors = eSampleTest.querySelectorAll(".input .title .input-output-copier");
  1265. const count = Math.min(inputs.length, outputs.length, anchors.length);
  1266. for (let i = 0; i < count; i++) {
  1267. testcases.push({
  1268. title: `Sample ${num++}`,
  1269. input: inputs[i].textContent,
  1270. output: outputs[i].textContent,
  1271. anchor: anchors[i],
  1272. });
  1273. }
  1274. }
  1275. return testcases;
  1276. },
  1277. get jQuery() {
  1278. return jQuery;
  1279. },
  1280. };
  1281. }
  1282.  
  1283. config.registerFlag("site.codeforcesMobile.showEditor", true, "Show Editor in Mobile Codeforces (m[1-3].codeforces.com) Problem Page");
  1284. async function init$2() {
  1285. if (!/^m[1-3]\.codeforces\.com$/.test(location.host))
  1286. throw "not Codeforces Mobile";
  1287. const url = /\/contest\/(\d+)\/problem\/([^/]+)/.exec(location.pathname);
  1288. const contestId = url[1];
  1289. const problemId = url[2];
  1290. const doc = unsafeWindow.document;
  1291. const main = doc.querySelector("main");
  1292. doc.head.appendChild(newElement("link", {
  1293. rel: "stylesheet",
  1294. href: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css",
  1295. }));
  1296. await loadScript("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js");
  1297. const language = new ObservableValue("");
  1298. let submit = () => { };
  1299. let getSourceCode = () => "";
  1300. let setSourceCode = (_) => { };
  1301. // make Editor
  1302. if (config.get("site.codeforcesMobile.showEditor", true)) {
  1303. const frame = newElement("iframe", {
  1304. src: `/contest/${contestId}/submit`,
  1305. style: {
  1306. display: "none",
  1307. },
  1308. });
  1309. doc.body.appendChild(frame);
  1310. await new Promise(done => frame.onload = done);
  1311. const fdoc = frame.contentDocument;
  1312. const form = fdoc.querySelector("._SubmitPage_submitForm");
  1313. form.elements["problemIndex"].value = problemId;
  1314. form.elements["problemIndex"].readonly = true;
  1315. form.elements["programTypeId"].addEventListener("change", function () {
  1316. language.value = langMap[this.value];
  1317. });
  1318. for (const row of form.children) {
  1319. if (row.tagName != "DIV")
  1320. continue;
  1321. row.classList.add("form-group");
  1322. const control = row.querySelector("*[name]");
  1323. if (control)
  1324. control.classList.add("form-control");
  1325. }
  1326. form.parentElement.removeChild(form);
  1327. main.appendChild(form);
  1328. submit = () => form.submit();
  1329. getSourceCode = () => form.elements["source"].value;
  1330. setSourceCode = sourceCode => {
  1331. form.elements["source"].value = sourceCode;
  1332. };
  1333. }
  1334. return {
  1335. name: "Codeforces",
  1336. language,
  1337. get sourceCode() {
  1338. return getSourceCode();
  1339. },
  1340. set sourceCode(sourceCode) {
  1341. setSourceCode(sourceCode);
  1342. },
  1343. submit,
  1344. get testButtonContainer() {
  1345. return main;
  1346. },
  1347. get sideButtonContainer() {
  1348. return main;
  1349. },
  1350. get bottomMenuContainer() {
  1351. return doc.body;
  1352. },
  1353. get resultListContainer() {
  1354. return main;
  1355. },
  1356. get testCases() {
  1357. const testcases = [];
  1358. let index = 1;
  1359. for (const container of doc.querySelectorAll(".sample-test")) {
  1360. const input = container.querySelector(".input pre.content").textContent;
  1361. const output = container.querySelector(".output pre.content").textContent;
  1362. const anchor = container.querySelector(".input .title");
  1363. testcases.push({
  1364. input, output, anchor,
  1365. title: `Sample ${index++}`,
  1366. });
  1367. }
  1368. return testcases;
  1369. },
  1370. get jQuery() {
  1371. return unsafeWindow["jQuery"];
  1372. },
  1373. };
  1374. }
  1375.  
  1376. async function init$1() {
  1377. if (location.host != "greatest.deepsurf.us" && !location.href.match(/433152-atcoder-easy-test-v2/))
  1378. throw "Not about page";
  1379. const doc = unsafeWindow.document;
  1380. await loadScript("https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js");
  1381. const jQuery = unsafeWindow["jQuery"];
  1382. await loadScript("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js", null, { jQuery, $: jQuery });
  1383. const e = newElement("div");
  1384. doc.getElementById("install-area").appendChild(newElement("button", {
  1385. type: "button",
  1386. textContent: "Open config",
  1387. onclick: () => settings.open(),
  1388. }));
  1389. return {
  1390. name: "About Page",
  1391. language: new ObservableValue(""),
  1392. get sourceCode() { return ""; },
  1393. set sourceCode(sourceCode) { },
  1394. submit() { },
  1395. get testButtonContainer() { return e; },
  1396. get sideButtonContainer() { return e; },
  1397. get bottomMenuContainer() { return e; },
  1398. get resultListContainer() { return e; },
  1399. get testCases() { return []; },
  1400. get jQuery() { return jQuery; },
  1401. };
  1402. }
  1403.  
  1404. // 設定ページが開けなくなるのを避ける
  1405. const inits = [init$1()];
  1406. config.registerFlag("site.atcoder", true, "Use AtCoder Easy Test in AtCoder");
  1407. if (config.get("site.atcoder", true))
  1408. inits.push(init$5());
  1409. config.registerFlag("site.yukicoder", true, "Use AtCoder Easy Test in yukicoder");
  1410. if (config.get("site.yukicoder", true))
  1411. inits.push(init$4());
  1412. config.registerFlag("site.codeforces", true, "Use AtCoder Easy Test in Codeforces");
  1413. if (config.get("site.codeforces", true))
  1414. inits.push(init$3());
  1415. config.registerFlag("site.codeforcesMobile", true, "Use AtCoder Easy Test in Codeforces Mobile (m[1-3].codeforces.com)");
  1416. if (config.get("site.codeforcesMobile", true))
  1417. inits.push(init$2());
  1418. var pSite = Promise.any(inits);
  1419.  
  1420. const runners = {
  1421. "C GCC 10.2.0 Wandbox": new WandboxRunner("gcc-10.2.0-c", "C (GCC 10.2.0)"),
  1422. "C C17 Clang 10.0.0 paiza.io": new PaizaIORunner("c", "C (C17 / Clang 10.0.0)"),
  1423. "C++ GCC 10.2.0 + Boost 1.73.0 + ACL Wandbox": new WandboxCppRunner("gcc-10.2.0", "C++ (GCC 10.2.0) + ACL", { options: "warning,boost-1.73.0-gcc-9.2.0,gnu++17" }),
  1424. "C++ Clang 10.0.1 + ACL Wandbox": new WandboxCppRunner("clang-10.0.1", "C++ (Clang 10.0.1) + ACL", { options: "warning,boost-nothing-clang-10.0.0,c++17" }),
  1425. "Python3 CPython 3.8.2 paiza.io": new PaizaIORunner("python3", "Python (3.8.2)"),
  1426. "Python3 Brython": brythonRunner,
  1427. "Python3 Pyodide": pyodideRunner,
  1428. "Bash 5.0.17 paiza.io": new PaizaIORunner("bash", "Bash (5.0.17)"),
  1429. "Bash 5.0.17 Wandbox": new WandboxRunner("bash", "Bash (5.0.17(1)-release)"),
  1430. "C# .NET Core 3.1.407 Wandbox": new WandboxRunner("dotnetcore-3.1.407", "C# (.NET Core 3.1.407)"),
  1431. "C# Mono-mcs 6.12.0.122 Wandbox": new WandboxRunner("mono-6.12.0.122", "C# (Mono-mcs 6.12.0.122)"),
  1432. "Clojure 1.10.1-1 paiza.io": new PaizaIORunner("clojure", "Clojure (1.10.1-1)"),
  1433. "Crystal 0.36.1 Wandbox": new WandboxRunner("crystal-0.36.1", "Crystal (0.36.1)"),
  1434. "D LDC 1.23.0 paiza.io": new PaizaIORunner("d", "D (LDC 1.23.0)"),
  1435. "D DMD 2.093.1": new WandboxRunner("dmd-2.093.1", "D (DMD 2.093.1)"),
  1436. "D LDC 1.23.0": new WandboxRunner("ldc-1.23.0", "D (LDC 1.23.0)"),
  1437. "Erlang 10.6.4 paiza.io": new PaizaIORunner("erlang", "Erlang (10.6.4)"),
  1438. "Erlang 22.3.4.16": new WandboxRunner("erlang-22.3.4.16", "Erlang (22.3.4.16)"),
  1439. "Elixir 1.10.4": new WandboxRunner("elixir-1.10.4", "Elixir (1.10.4)"),
  1440. "Elixir 1.10.4 paiza.io": new PaizaIORunner("elixir", "Elixir (1.10.4)"),
  1441. "F# Interactive 4.0 paiza.io": new PaizaIORunner("fsharp", "F# (Interactive 4.0)"),
  1442. "Go 1.14.15 Wandbox": new WandboxRunner("go-1.14.15", "Go (1.14.15)"),
  1443. "Haskell GHC 8.8.4 Wandbox": new WandboxRunner("ghc-8.8.4", "Haskell (GHC 8.8.4)"),
  1444. "Haskell GHC 8.6.5 paiza.io": new PaizaIORunner("haskell", "Haskell (GHC 8.6.5)"),
  1445. "Java openjdk-jdk-15.0.3+2 Wandbox": new WandboxRunner("openjdk-jdk-15.0.3+2", "Java (JDK 15.0.3+2)"),
  1446. "Java openjdk-jdk-14.0.2+12 Wandbox": new WandboxRunner("openjdk-jdk-14.0.2+12", "Java (JDK 14.0.2+12)"),
  1447. "JavaScript Node.js paiza.io": new PaizaIORunner("javascript", "JavaScript (Node.js 12.18.3)"),
  1448. "JavaScript Node.js 12.22.1 Wandbox": new WandboxRunner("nodejs-12.22.1", "JavaScript (Node.js 12.22.1)"),
  1449. "Julia 1.6.1 Wandbox": new WandboxRunner("julia-1.6.1", "Julia (1.6.1)"),
  1450. "Kotlin 1.4.0 paiza.io": new PaizaIORunner("kotlin", "Kotlin (1.4.0)"),
  1451. "Lua 5.3.6 Wandbox": new WandboxRunner("lua-5.3.6", "Lua (Lua 5.3.6)"),
  1452. "Lua LuaJIT 2.0.5 Wandbox": new WandboxRunner("luajit-2.0.5", "Lua (LuaJIT 2.0.5)"),
  1453. "Nim 1.0.10 Wandbox": new WandboxRunner("nim-1.0.10", "Nim (1.0.10)"),
  1454. "Objective-C Clang 10.0.0 paiza.io": new PaizaIORunner("objective-c", "Objective-C (Clang 10.0.0)"),
  1455. "OCaml 4.10.2 Wandbox": new WandboxRunner("ocaml-4.10.2", "OCaml (4.10.2)"),
  1456. "Pascal FPC 3.0.4 Wandbox": new WandboxRunner("fpc-3.0.4", "Pascal (FPC 3.0.4)"),
  1457. "Perl 5.30.0 paiza.io": new PaizaIORunner("perl", "Perl (5.30.0)"),
  1458. "Perl 5.30.3 Wandbox": new WandboxRunner("perl-5.30.3", "Perl (5.30.3)"),
  1459. "PHP 7.4.10 paiza.io": new PaizaIORunner("php", "PHP (7.4.10)"),
  1460. "PHP 7.4.16 Wandbox": new WandboxRunner("php-7.4.16", "PHP (7.4.16)"),
  1461. "Python PyPy 7.3.4 Wandbox": new WandboxRunner("pypy-2.7-v7.3.4", "PyPy2 (7.3.4)"),
  1462. "Python3 PyPy3 7.3.4 Wandbox": new WandboxRunner("pypy-3.7-v7.3.4", "PyPy3 (7.3.4)"),
  1463. "Ruby 2.7.1 paiza.io": new PaizaIORunner("ruby", "Ruby (2.7.1)"),
  1464. "Ruby 3.1.0 Wandbox": new WandboxRunner("ruby-3.1.0", "Ruby (3.1.0)"),
  1465. "Ruby 2.7.3 Wandbox": new WandboxRunner("ruby-2.7.3", "Ruby (2.7.1)"),
  1466. "Rust 1.42.0 AtCoder": new AtCoderRunner("4050", "Rust (1.42.0)"),
  1467. "Rust 1.50.0 Wandbox": new WandboxRunner("rust-1.50.0", "Rust (1.50.0)"),
  1468. "Rust 1.43.0 paiza.io": new PaizaIORunner("rust", "Rust (1.43.0)"),
  1469. "Scala 2.13.3 paiza": new PaizaIORunner("scala", "Scala (2.13.3)"),
  1470. "Scala 2.13.5 Wandbox": new WandboxRunner("scala-2.13.5", "Scala (2.13.5)"),
  1471. "Scheme Gauche 0.9.6 paiza.io": new PaizaIORunner("scheme", "Scheme (Gauche 0.9.6)"),
  1472. "Swift 5.2.5 paiza.io": new PaizaIORunner("swift", "Swift (5.2.5)"),
  1473. "Swift 5.3.3 Wandbox": new WandboxRunner("swift-5.3.3", "Swift (5.3.3)"),
  1474. "TypeScript typescript-3.9.9 nodejs 14.16.1 Wandbox": new WandboxRunner("typescript-3.9.9 nodejs 14.16.1", "TypeScript (3.9.9)"),
  1475. "Text local": new CustomRunner("Text", async (sourceCode, input) => {
  1476. return {
  1477. status: "OK",
  1478. exitCode: "0",
  1479. input,
  1480. output: sourceCode,
  1481. };
  1482. }),
  1483. "Basic Visual Basic .NET Core 4.0.1 paiza.io": new PaizaIORunner("vb", "Visual Basic (.NET Core 4.0.1)"),
  1484. "COBOL Free OpenCOBOL 2.2.0 paiza.io": new PaizaIORunner("cobol", "COBOL - Free (OpenCOBOL 2.2.0)"),
  1485. "COBOL Fixed OpenCOBOL 1.1.0 AtCoder": new AtCoderRunner("4060", "COBOL - Fixed (OpenCOBOL 1.1.0)"),
  1486. "COBOL Free OpenCOBOL 1.1.0 AtCoder": new AtCoderRunner("4061", "COBOL - Free (OpenCOBOL 1.1.0)"),
  1487. "C++ GCC 9.3.0 + ACL Wandbox": new WandboxCppRunner("gcc-9.3.0", "C++ (GCC 9.3.0) + ACL"),
  1488. };
  1489. pSite.then(site => {
  1490. if (site.name == "AtCoder") {
  1491. // AtCoderRunner がない場合は、追加する
  1492. for (const e of document.querySelectorAll("#select-lang option[value]")) {
  1493. const m = e.textContent.match(/([^ ]+) \(([^)]+)\)/);
  1494. if (m) {
  1495. const name = `${m[1]} ${m[2]} AtCoder`;
  1496. const languageId = e.value;
  1497. runners[name] = new AtCoderRunner(languageId, e.textContent);
  1498. }
  1499. }
  1500. }
  1501. });
  1502. console.info("AtCoder Easy Test: codeRunner OK");
  1503. config.registerCount("codeRunner.maxRetry", 3, "Max count of retry when IE (Internal Error)");
  1504. var codeRunner = {
  1505. // 指定した環境でコードを実行する
  1506. async run(runnerId, sourceCode, input, expectedOutput, options = { trim: true, split: true }) {
  1507. // CodeRunner が存在しない言語ID
  1508. if (!(runnerId in runners))
  1509. return Promise.reject("Language not supported");
  1510. // 最後に実行したコードを保存
  1511. if (sourceCode.length > 0)
  1512. codeSaver.save(sourceCode);
  1513. // 実行
  1514. const maxRetry = config.get("codeRunner.maxRetry", 3);
  1515. for (let retry = 0; retry < maxRetry; retry++) {
  1516. try {
  1517. const result = await runners[runnerId].test(sourceCode, input, expectedOutput, options);
  1518. const lang = runnerId.split(" ")[0];
  1519. if (result.status == "IE") {
  1520. console.error(result);
  1521. const runnerIds = Object.keys(runners).filter(runnerId => runnerId.split(" ")[0] == lang);
  1522. const index = runnerIds.indexOf(runnerId);
  1523. runnerId = runnerIds[(index + 1) % runnerIds.length];
  1524. continue;
  1525. }
  1526. return result;
  1527. }
  1528. catch (e) {
  1529. console.error(e);
  1530. }
  1531. }
  1532. },
  1533. // 環境の名前の一覧を取得する
  1534. // @return runnerIdとラベルのペアの配列
  1535. async getEnvironment(languageId) {
  1536. const langs = similarLangs(languageId, Object.keys(runners));
  1537. if (langs.length == 0)
  1538. throw `Undefined language: ${languageId}`;
  1539. return langs.map(runnerId => [runnerId, runners[runnerId].label]);
  1540. },
  1541. };
  1542.  
  1543. var hBottomMenu = "<div id=\"bottom-menu-wrapper\" class=\"navbar navbar-default navbar-fixed-bottom\">\n <div class=\"container\">\n <div class=\"navbar-header\">\n <button id=\"bottom-menu-key\" type=\"button\" class=\"navbar-toggle collapsed glyphicon glyphicon-menu-down\" data-toggle=\"collapse\" data-target=\"#bottom-menu\"></button>\n </div>\n <div id=\"bottom-menu\" class=\"collapse navbar-collapse\">\n <ul id=\"bottom-menu-tabs\" class=\"nav nav-tabs\"></ul>\n <div id=\"bottom-menu-contents\" class=\"tab-content\"></div>\n </div>\n </div>\n</div>";
  1544.  
  1545. var hStyle$1 = "<style>\n#bottom-menu-wrapper {\n background: transparent !important;\n border: none !important;\n pointer-events: none;\n padding: 0;\n}\n\n#bottom-menu-wrapper>.container {\n position: absolute;\n bottom: 0;\n width: 100%;\n padding: 0;\n}\n\n#bottom-menu-wrapper>.container>.navbar-header {\n float: none;\n}\n\n#bottom-menu-key {\n display: block;\n float: none;\n margin: 0 auto;\n padding: 10px 3em;\n border-radius: 5px 5px 0 0;\n background: #000;\n opacity: 0.5;\n color: #FFF;\n cursor: pointer;\n pointer-events: auto;\n text-align: center;\n}\n\n@media screen and (max-width: 767px) {\n #bottom-menu-key {\n opacity: 0.25;\n }\n}\n\n#bottom-menu-key.collapsed:before {\n content: \"\\e260\";\n}\n\n#bottom-menu-tabs {\n padding: 3px 0 0 10px;\n cursor: n-resize;\n}\n\n#bottom-menu-tabs a {\n pointer-events: auto;\n}\n\n#bottom-menu {\n pointer-events: auto;\n background: rgba(0, 0, 0, 0.8);\n color: #fff;\n max-height: unset;\n}\n\n#bottom-menu.collapse:not(.in) {\n display: none !important;\n}\n\n#bottom-menu-tabs>li>a {\n background: rgba(150, 150, 150, 0.5);\n color: #000;\n border: solid 1px #ccc;\n filter: brightness(0.75);\n}\n\n#bottom-menu-tabs>li>a:hover {\n background: rgba(150, 150, 150, 0.5);\n border: solid 1px #ccc;\n color: #111;\n filter: brightness(0.9);\n}\n\n#bottom-menu-tabs>li.active>a {\n background: #eee;\n border: solid 1px #ccc;\n color: #333;\n filter: none;\n}\n\n.bottom-menu-btn-close {\n font-size: 8pt;\n vertical-align: baseline;\n padding: 0 0 0 6px;\n margin-right: -6px;\n}\n\n#bottom-menu-contents {\n padding: 5px 15px;\n max-height: 50vh;\n overflow-y: auto;\n}\n\n#bottom-menu-contents .panel {\n color: #333;\n}\n</style>";
  1546.  
  1547. async function init() {
  1548. const site = await pSite;
  1549. const style = html2element(hStyle$1);
  1550. const bottomMenu = html2element(hBottomMenu);
  1551. unsafeWindow.document.head.appendChild(style);
  1552. site.bottomMenuContainer.appendChild(bottomMenu);
  1553. const bottomMenuKey = bottomMenu.querySelector("#bottom-menu-key");
  1554. const bottomMenuTabs = bottomMenu.querySelector("#bottom-menu-tabs");
  1555. const bottomMenuContents = bottomMenu.querySelector("#bottom-menu-contents");
  1556. // メニューのリサイズ
  1557. {
  1558. let resizeStart = null;
  1559. const onStart = (event) => {
  1560. const target = event.target;
  1561. const pageY = event.pageY;
  1562. if (target.id != "bottom-menu-tabs")
  1563. return;
  1564. resizeStart = { y: pageY, height: bottomMenuContents.getBoundingClientRect().height };
  1565. };
  1566. const onMove = (event) => {
  1567. if (!resizeStart)
  1568. return;
  1569. event.preventDefault();
  1570. bottomMenuContents.style.height = `${resizeStart.height - (event.pageY - resizeStart.y)}px`;
  1571. };
  1572. const onEnd = () => {
  1573. resizeStart = null;
  1574. };
  1575. bottomMenuTabs.addEventListener("mousedown", onStart);
  1576. bottomMenuTabs.addEventListener("mousemove", onMove);
  1577. bottomMenuTabs.addEventListener("mouseup", onEnd);
  1578. bottomMenuTabs.addEventListener("mouseleave", onEnd);
  1579. }
  1580. let tabs = new Set();
  1581. let selectedTab = null;
  1582. /** 下メニューの操作 */
  1583. const menuController = {
  1584. /** タブを選択 */
  1585. selectTab(tabId) {
  1586. const tab = site.jQuery(`#bottom-menu-tab-${tabId}`);
  1587. if (tab && tab[0]) {
  1588. tab.tab("show"); // Bootstrap 3
  1589. selectedTab = tabId;
  1590. }
  1591. },
  1592. /** 下メニューにタブを追加する */
  1593. addTab(tabId, tabLabel, paneContent, options = {}) {
  1594. console.log(`AtCoder Easy Test: addTab: ${tabLabel} (${tabId})`, paneContent);
  1595. // タブを追加
  1596. const tab = document.createElement("a");
  1597. tab.textContent = tabLabel;
  1598. tab.id = `bottom-menu-tab-${tabId}`;
  1599. tab.href = "#";
  1600. tab.dataset.target = `#bottom-menu-pane-${tabId}`;
  1601. tab.dataset.toggle = "tab";
  1602. tab.addEventListener("click", event => {
  1603. event.preventDefault();
  1604. menuController.selectTab(tabId);
  1605. });
  1606. const tabLi = document.createElement("li");
  1607. tabLi.appendChild(tab);
  1608. bottomMenuTabs.appendChild(tabLi);
  1609. // 内容を追加
  1610. const pane = document.createElement("div");
  1611. pane.className = "tab-pane";
  1612. pane.id = `bottom-menu-pane-${tabId}`;
  1613. pane.appendChild(paneContent);
  1614. bottomMenuContents.appendChild(pane);
  1615. const controller = {
  1616. get id() {
  1617. return tabId;
  1618. },
  1619. close() {
  1620. bottomMenuTabs.removeChild(tabLi);
  1621. bottomMenuContents.removeChild(pane);
  1622. tabs.delete(tab);
  1623. if (selectedTab == tabId) {
  1624. selectedTab = null;
  1625. if (tabs.size > 0) {
  1626. menuController.selectTab(tabs.values().next().value.id);
  1627. }
  1628. }
  1629. },
  1630. show() {
  1631. menuController.show();
  1632. menuController.selectTab(tabId);
  1633. },
  1634. set color(color) {
  1635. tab.style.backgroundColor = color;
  1636. },
  1637. };
  1638. // 閉じるボタン
  1639. if (options.closeButton) {
  1640. const btn = document.createElement("a");
  1641. btn.className = "bottom-menu-btn-close btn btn-link glyphicon glyphicon-remove";
  1642. btn.addEventListener("click", () => {
  1643. controller.close();
  1644. });
  1645. tab.appendChild(btn);
  1646. }
  1647. // 選択されているタブがなければ選択
  1648. if (!selectedTab)
  1649. menuController.selectTab(tabId);
  1650. return controller;
  1651. },
  1652. /** 下メニューを表示する */
  1653. show() {
  1654. if (bottomMenuKey.classList.contains("collapsed"))
  1655. bottomMenuKey.click();
  1656. },
  1657. /** 下メニューの表示/非表示を切り替える */
  1658. toggle() {
  1659. bottomMenuKey.click();
  1660. },
  1661. };
  1662. console.info("AtCoder Easy Test: bottomMenu OK");
  1663. return menuController;
  1664. }
  1665.  
  1666. var hRowTemplate = "<div class=\"atcoder-easy-test-cases-row alert alert-dismissible\">\n <button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">\n <span aria-hidden=\"true\">×</span>\n </button>\n <div class=\"progress\">\n <div class=\"progress-bar\" style=\"width: 0%;\">0 / 0</div>\n </div>\n <div class=\"atcoder-easy-test-cases-row-date\" style=\"font-family: monospace; text-align: right; position: absolute; right: 1em;\"></div>\n</div>";
  1667.  
  1668. class ResultRow {
  1669. _tabs;
  1670. _element;
  1671. _promise;
  1672. constructor(pairs) {
  1673. this._tabs = pairs.map(([_, tab]) => tab);
  1674. this._element = html2element(hRowTemplate);
  1675. this._element.querySelector(".close").addEventListener("click", () => this.remove());
  1676. {
  1677. const date = new Date();
  1678. const h = date.getHours().toString().padStart(2, "0");
  1679. const m = date.getMinutes().toString().padStart(2, "0");
  1680. const s = date.getSeconds().toString().padStart(2, "0");
  1681. this._element.querySelector(".atcoder-easy-test-cases-row-date").textContent = `${h}:${m}:${s}`;
  1682. }
  1683. const numCases = pairs.length;
  1684. let numFinished = 0;
  1685. let numAccepted = 0;
  1686. const progressBar = this._element.querySelector(".progress-bar");
  1687. progressBar.textContent = `${numFinished} / ${numCases}`;
  1688. this._promise = Promise.all(pairs.map(([pResult, tab]) => {
  1689. const button = html2element(`<div class="label label-default" style="margin: 3px; cursor: pointer;">WJ</div>`);
  1690. button.addEventListener("click", async () => {
  1691. (await tab).show();
  1692. });
  1693. this._element.appendChild(button);
  1694. return pResult.then(result => {
  1695. button.textContent = result.status;
  1696. if (result.status == "AC") {
  1697. button.classList.add("label-success");
  1698. }
  1699. else if (result.status != "OK") {
  1700. button.classList.add("label-warning");
  1701. }
  1702. numFinished++;
  1703. if (result.status == "AC")
  1704. numAccepted++;
  1705. progressBar.textContent = `${numFinished} / ${numCases}`;
  1706. progressBar.style.width = `${100 * numFinished / numCases}%`;
  1707. if (numFinished == numCases) {
  1708. if (numAccepted == numCases)
  1709. this._element.classList.add("alert-success");
  1710. else
  1711. this._element.classList.add("alert-warning");
  1712. }
  1713. }).catch(reason => {
  1714. button.textContent = "IE";
  1715. button.classList.add("label-danger");
  1716. console.error(reason);
  1717. });
  1718. }));
  1719. }
  1720. get element() {
  1721. return this._element;
  1722. }
  1723. onFinish(listener) {
  1724. this._promise.then(listener);
  1725. }
  1726. remove() {
  1727. for (const pTab of this._tabs)
  1728. pTab.then(tab => tab.close());
  1729. const parent = this._element.parentElement;
  1730. if (parent)
  1731. parent.removeChild(this._element);
  1732. }
  1733. }
  1734.  
  1735. var hResultList = "<div class=\"row\"></div>";
  1736.  
  1737. const eResultList = html2element(hResultList);
  1738. pSite.then(site => site.resultListContainer.appendChild(eResultList));
  1739. const resultList = {
  1740. addResult(pairs) {
  1741. const result = new ResultRow(pairs);
  1742. eResultList.insertBefore(result.element, eResultList.firstChild);
  1743. return result;
  1744. },
  1745. };
  1746.  
  1747. const version = {
  1748. currentProperty: new ObservableValue("2.9.14"),
  1749. get current() {
  1750. return this.currentProperty.value;
  1751. },
  1752. latestProperty: new ObservableValue(config.get("version.latest", "2.9.14")),
  1753. get latest() {
  1754. return this.latestProperty.value;
  1755. },
  1756. lastCheckProperty: new ObservableValue(config.get("version.lastCheck", 0)),
  1757. get lastCheck() {
  1758. return this.lastCheckProperty.value;
  1759. },
  1760. get hasUpdate() {
  1761. return this.compare(this.current, this.latest) < 0;
  1762. },
  1763. compare(a, b) {
  1764. const x = a.split(".").map((s) => parseInt(s, 10));
  1765. const y = b.split(".").map((s) => parseInt(s, 10));
  1766. for (let i = 0; i < 3; i++) {
  1767. if (x[i] < y[i]) {
  1768. return -1;
  1769. }
  1770. else if (x[i] > y[i]) {
  1771. return 1;
  1772. }
  1773. }
  1774. return 0;
  1775. },
  1776. async checkUpdate(force = false) {
  1777. const now = Date.now();
  1778. if (!force && now - version.lastCheck < config.get("version.checkInterval", aDay)) {
  1779. return this.current;
  1780. }
  1781. const packageJson = await fetch("https://raw.githubusercontent.com/magurofly/atcoder-easy-test/main/v2/package.json").then(r => r.json());
  1782. console.log(packageJson);
  1783. const latest = packageJson["version"];
  1784. this.latestProperty.value = latest;
  1785. config.set("version.latest", latest);
  1786. this.lastCheckProperty.value = now;
  1787. config.set("version.lastCheck", now);
  1788. return latest;
  1789. },
  1790. };
  1791. // 更新チェック
  1792. const aDay = 24 * 60 * 60 * 1e3;
  1793. config.registerCount("version.checkInterval", aDay, "Interval [ms] of checking for new version");
  1794. config.get("version.checkInterval", aDay);
  1795. setInterval(() => {
  1796. version.checkUpdate(false);
  1797. }, 60e3);
  1798. settings.add("version", (win) => {
  1799. const root = newElement("div");
  1800. const text = win.document.createTextNode.bind(win.document);
  1801. const textAuto = (property) => {
  1802. const t = text(property.value);
  1803. property.addListener(value => {
  1804. t.textContent = value;
  1805. });
  1806. return t;
  1807. };
  1808. const tCurrent = textAuto(version.currentProperty);
  1809. const tLatest = textAuto(version.latestProperty);
  1810. const tLastCheck = textAuto(version.lastCheckProperty.map(time => new Date(time).toLocaleString()));
  1811. root.appendChild(newElement("p", {}, [
  1812. text("AtCoder Easy Test v"),
  1813. tCurrent,
  1814. ]));
  1815. const updateButton = newElement("a", {
  1816. className: "btn btn-info",
  1817. textContent: "Install",
  1818. href: "https://github.com/magurofly/atcoder-easy-test/raw/main/v2/atcoder-easy-test.user.js",
  1819. target: "_blank",
  1820. });
  1821. const showButton = () => {
  1822. if (version.hasUpdate)
  1823. updateButton.style.display = "inline";
  1824. else
  1825. updateButton.style.display = "none";
  1826. };
  1827. showButton();
  1828. version.lastCheckProperty.addListener(showButton);
  1829. root.appendChild(newElement("p", {}, [
  1830. text("Latest: v"),
  1831. tLatest,
  1832. text(" (Last Check: "),
  1833. tLastCheck,
  1834. text(") "),
  1835. updateButton,
  1836. ]));
  1837. root.appendChild(newElement("p", {}, [
  1838. newElement("a", {
  1839. className: "btn btn-primary",
  1840. textContent: "Check Update",
  1841. onclick() {
  1842. version.checkUpdate(true);
  1843. },
  1844. }),
  1845. ]));
  1846. return root;
  1847. });
  1848.  
  1849. var hTabTemplate = "<div class=\"atcoder-easy-test-result container\">\n <div class=\"row\">\n <div class=\"atcoder-easy-test-result-col-input col-xs-12\" data-if-expected-output=\"col-sm-6 col-sm-push-6\">\n <div class=\"form-group\">\n <label class=\"control-label col-xs-12\">\n Standard Input\n <div class=\"col-xs-12\">\n <textarea class=\"atcoder-easy-test-result-input form-control\" rows=\"3\" readonly=\"readonly\"></textarea>\n </div>\n </label>\n </div>\n </div>\n <div class=\"atcoder-easy-test-result-col-expected-output col-xs-12 col-sm-6 hidden\" data-if-expected-output=\"!hidden col-sm-pull-6\">\n <div class=\"form-group\">\n <label class=\"control-label col-xs-12\">\n Expected Output\n <div class=\"col-xs-12\">\n <textarea class=\"atcoder-easy-test-result-expected-output form-control\" rows=\"3\" readonly=\"readonly\"></textarea>\n </div>\n </label>\n </div>\n </div>\n </div>\n <div class=\"row\"><div class=\"col-sm-6 col-sm-offset-3\">\n <div class=\"panel panel-default\">\n <table class=\"table table-condensed\">\n <tbody>\n <tr>\n <th class=\"text-center\">Exit Code</th>\n <th class=\"text-center\">Exec Time</th>\n <th class=\"text-center\">Memory</th>\n </tr>\n <tr>\n <td class=\"atcoder-easy-test-result-exit-code text-center\"></td>\n <td class=\"atcoder-easy-test-result-exec-time text-center\"></td>\n <td class=\"atcoder-easy-test-result-memory text-center\"></td>\n </tr>\n </tbody>\n </table>\n </div>\n </div></div>\n <div class=\"row\">\n <div class=\"atcoder-easy-test-result-col-output col-xs-12\" data-if-error=\"col-md-6\">\n <div class=\"form-group\">\n <label class=\"control-label col-xs-12\">\n Standard Output\n <div class=\"col-xs-12\">\n <textarea class=\"atcoder-easy-test-result-output form-control\" rows=\"5\" readonly=\"readonly\"></textarea>\n </div>\n </label>\n </div>\n </div>\n <div class=\"atcoder-easy-test-result-col-error col-xs-12 col-md-6 hidden\" data-if-error=\"!hidden\">\n <div class=\"form-group\">\n <label class=\"control-label col-xs-12\">\n Standard Error\n <div class=\"col-xs-12\">\n <textarea class=\"atcoder-easy-test-result-error form-control\" rows=\"5\" readonly=\"readonly\"></textarea>\n </div>\n </label>\n </div>\n </div>\n </div>\n</div>";
  1850.  
  1851. function setClassFromData(element, name) {
  1852. const classes = element.dataset[name].split(/\s+/);
  1853. for (let className of classes) {
  1854. let flag = true;
  1855. if (className[0] == "!") {
  1856. className = className.slice(1);
  1857. flag = false;
  1858. }
  1859. element.classList.toggle(className, flag);
  1860. }
  1861. }
  1862. class ResultTabContent {
  1863. _title;
  1864. _uid;
  1865. _element;
  1866. _result;
  1867. constructor() {
  1868. this._uid = Date.now().toString(16);
  1869. this._result = null;
  1870. this._element = html2element(hTabTemplate);
  1871. this._element.id = `atcoder-easy-test-result-${this._uid}`;
  1872. }
  1873. set result(result) {
  1874. this._result = result;
  1875. if (result.status == "AC") {
  1876. this.outputStyle.backgroundColor = "#dff0d8";
  1877. }
  1878. else if (result.status != "OK") {
  1879. this.outputStyle.backgroundColor = "#fcf8e3";
  1880. }
  1881. this.input = result.input;
  1882. if ("expectedOutput" in result)
  1883. this.expectedOutput = result.expectedOutput;
  1884. this.exitCode = result.exitCode;
  1885. if ("execTime" in result)
  1886. this.execTime = `${result.execTime} ms`;
  1887. if ("memory" in result)
  1888. this.memory = `${result.memory} KB`;
  1889. if ("output" in result)
  1890. this.output = result.output;
  1891. if (result.error)
  1892. this.error = result.error;
  1893. }
  1894. get result() {
  1895. return this._result;
  1896. }
  1897. get uid() {
  1898. return this._uid;
  1899. }
  1900. get element() {
  1901. return this._element;
  1902. }
  1903. set title(title) {
  1904. this._title = title;
  1905. }
  1906. get title() {
  1907. return this._title;
  1908. }
  1909. set input(input) {
  1910. this._get("input").value = input;
  1911. }
  1912. get inputStyle() {
  1913. return this._get("input").style;
  1914. }
  1915. set expectedOutput(output) {
  1916. this._get("expected-output").value = output;
  1917. setClassFromData(this._get("col-input"), "ifExpectedOutput");
  1918. setClassFromData(this._get("col-expected-output"), "ifExpectedOutput");
  1919. }
  1920. get expectedOutputStyle() {
  1921. return this._get("expected-output").style;
  1922. }
  1923. set output(output) {
  1924. this._get("output").value = output;
  1925. }
  1926. get outputStyle() {
  1927. return this._get("output").style;
  1928. }
  1929. set error(error) {
  1930. this._get("error").value = error;
  1931. setClassFromData(this._get("col-output"), "ifError");
  1932. setClassFromData(this._get("col-error"), "ifError");
  1933. }
  1934. set exitCode(code) {
  1935. const element = this._get("exit-code");
  1936. element.textContent = code;
  1937. const isSuccess = code == "0";
  1938. element.classList.toggle("bg-success", isSuccess);
  1939. element.classList.toggle("bg-danger", !isSuccess);
  1940. }
  1941. set execTime(time) {
  1942. this._get("exec-time").textContent = time;
  1943. }
  1944. set memory(memory) {
  1945. this._get("memory").textContent = memory;
  1946. }
  1947. _get(name) {
  1948. return this._element.querySelector(`.atcoder-easy-test-result-${name}`);
  1949. }
  1950. }
  1951.  
  1952. var hRoot = "<form id=\"atcoder-easy-test-container\" class=\"form-horizontal\">\n <div class=\"row\">\n <div class=\"col-xs-12 col-lg-8\">\n <div class=\"form-group\">\n <label class=\"control-label col-sm-2\">Test Environment</label>\n <div class=\"col-sm-10\">\n <select class=\"form-control\" id=\"atcoder-easy-test-language\"></select>\n </div>\n </div>\n <div class=\"form-group\">\n <label class=\"control-label col-sm-2\" for=\"atcoder-easy-test-input\">Standard Input</label>\n <div class=\"col-sm-10\">\n <textarea id=\"atcoder-easy-test-input\" name=\"input\" class=\"form-control\" rows=\"3\"></textarea>\n </div>\n </div>\n </div>\n <div class=\"col-xs-12 col-lg-4\">\n <details close>\n <summary>Expected Output</summary>\n <div class=\"form-group\">\n <label class=\"control-label col-sm-2\" for=\"atcoder-easy-test-allowable-error-check\">Allowable Error</label>\n <div class=\"col-sm-10\">\n <div class=\"input-group\">\n <span class=\"input-group-addon\">\n <input id=\"atcoder-easy-test-allowable-error-check\" type=\"checkbox\" checked=\"checked\">\n </span>\n <input id=\"atcoder-easy-test-allowable-error\" type=\"text\" class=\"form-control\" value=\"1e-6\">\n </div>\n </div>\n </div>\n <div class=\"form-group\">\n <label class=\"control-label col-sm-2\" for=\"atcoder-easy-test-output\">Expected Output</label>\n <div class=\"col-sm-10\">\n <textarea id=\"atcoder-easy-test-output\" name=\"output\" class=\"form-control\" rows=\"3\"></textarea>\n </div>\n </div>\n </details>\n </div>\n <div class=\"col-xs-12 col-md-6\">\n <div class=\"col-xs-11 col-xs-offset=1\">\n <div class=\"form-group\">\n <a id=\"atcoder-easy-test-run\" class=\"btn btn-primary\">Run</a>\n </div>\n </div>\n </div>\n <div class=\"col-xs-12 col-md-6\">\n <div class=\"col-xs-11 col-xs-offset=1\">\n <div class=\"form-group text-right\">\n <small>AtCoder Easy Test v<span id=\"atcoder-easy-test-version\"></span></small>\n <a id=\"atcoder-easy-test-setting\" class=\"btn btn-xs btn-default\">Setting</a>\n </div>\n </div>\n </div>\n </div>\n <style>\n #atcoder-easy-test-language {\n border: none;\n background: transparent;\n font: inherit;\n color: #fff;\n }\n #atcoder-easy-test-language option {\n border: none;\n color: #333;\n font: inherit;\n }\n </style>\n</form>";
  1953.  
  1954. var hStyle = "<style>\n.atcoder-easy-test-result textarea {\n font-family: monospace;\n font-weight: normal;\n}\n</style>";
  1955.  
  1956. var hRunButton = "<button type=\"button\" class=\"btn btn-primary btn-sm atcoder-easy-test-btn-run-case\" style=\"vertical-align: top; margin-left: 0.5em\">Run</button>";
  1957.  
  1958. var hTestAndSubmit = "<button type=\"button\" id=\"atcoder-easy-test-btn-test-and-submit\" class=\"btn btn-info btn\" style=\"margin-left: 1rem\" title=\"Ctrl+Enter\" data-toggle=\"tooltip\">Test &amp; Submit</button>";
  1959.  
  1960. var hTestAllSamples = "<button type=\"button\" id=\"atcoder-easy-test-btn-test-all\" class=\"btn btn-default btn-sm\" style=\"margin-left: 1rem\" title=\"Alt+Enter\" data-toggle=\"tooltip\">Test All Samples</button>";
  1961.  
  1962. (async () => {
  1963. const site = await pSite;
  1964. const doc = unsafeWindow.document;
  1965. // init bottomMenu
  1966. const pBottomMenu = init();
  1967. pBottomMenu.then(bottomMenu => {
  1968. unsafeWindow.bottomMenu = bottomMenu;
  1969. });
  1970. await doneOrFail(pBottomMenu);
  1971. // external interfaces
  1972. unsafeWindow.codeRunner = codeRunner;
  1973. doc.head.appendChild(html2element(hStyle));
  1974. // interface
  1975. const atCoderEasyTest = {
  1976. version,
  1977. site,
  1978. config,
  1979. codeSaver,
  1980. enableButtons() {
  1981. events.trig("enable");
  1982. },
  1983. disableButtons() {
  1984. events.trig("disable");
  1985. },
  1986. runCount: 0,
  1987. runTest(title, language, sourceCode, input, output = null, options = { trim: true, split: true, }) {
  1988. this.disableButtons();
  1989. const content = new ResultTabContent();
  1990. const pTab = pBottomMenu.then(bottomMenu => bottomMenu.addTab("easy-test-result-" + content.uid, `#${++this.runCount} ${title}`, content.element, { active: true, closeButton: true }));
  1991. const pResult = codeRunner.run(language, sourceCode, input, output, options);
  1992. pResult.then(result => {
  1993. content.result = result;
  1994. if (result.status == "AC") {
  1995. pTab.then(tab => tab.color = "#dff0d8");
  1996. }
  1997. else if (result.status != "OK") {
  1998. pTab.then(tab => tab.color = "#fcf8e3");
  1999. }
  2000. }).finally(() => {
  2001. this.enableButtons();
  2002. });
  2003. return [pResult, pTab];
  2004. }
  2005. };
  2006. unsafeWindow.atCoderEasyTest = atCoderEasyTest;
  2007. // place "Easy Test" tab
  2008. {
  2009. // declare const hRoot: string;
  2010. const root = html2element(hRoot);
  2011. const E = (id) => root.querySelector(`#atcoder-easy-test-${id}`);
  2012. const eLanguage = E("language");
  2013. const eInput = E("input");
  2014. const eAllowableErrorCheck = E("allowable-error-check");
  2015. const eAllowableError = E("allowable-error");
  2016. const eOutput = E("output");
  2017. const eRun = E("run");
  2018. const eSetting = E("setting");
  2019. const eVersion = E("version");
  2020. eVersion.textContent = atCoderEasyTest.version.current;
  2021. events.on("enable", () => {
  2022. eRun.classList.remove("disabled");
  2023. });
  2024. events.on("disable", () => {
  2025. eRun.classList.add("disabled");
  2026. });
  2027. eSetting.addEventListener("click", () => {
  2028. settings.open();
  2029. });
  2030. // バージョン確認
  2031. {
  2032. let button = null;
  2033. const showButton = () => {
  2034. if (!version.hasUpdate)
  2035. return;
  2036. if (button) {
  2037. button.textContent = `Update to v${version.latest}`;
  2038. return;
  2039. }
  2040. console.info(`AtCoder Easy Test: New version available: v${version}`);
  2041. button = newElement("a", {
  2042. href: "https://github.com/magurofly/atcoder-easy-test/raw/main/v2/atcoder-easy-test.user.js",
  2043. target: "_blank",
  2044. className: "btn btn-xs btn-info",
  2045. textContent: `Update to v${version.latest}`,
  2046. });
  2047. eVersion.insertAdjacentElement("afterend", button);
  2048. };
  2049. version.latestProperty.addListener(showButton);
  2050. showButton();
  2051. }
  2052. // 言語選択関係
  2053. {
  2054. eLanguage.addEventListener("change", async () => {
  2055. const langSelection = config.get("langSelection", {});
  2056. langSelection[site.language.value] = eLanguage.value;
  2057. config.set("langSelection", langSelection);
  2058. });
  2059. async function setLanguage() {
  2060. const languageId = site.language.value;
  2061. while (eLanguage.firstChild)
  2062. eLanguage.removeChild(eLanguage.firstChild);
  2063. try {
  2064. const langs = await codeRunner.getEnvironment(languageId);
  2065. console.log(`language: ${langs[1]} (${langs[0]})`);
  2066. // add <option>
  2067. for (const [languageId, label] of langs) {
  2068. const option = document.createElement("option");
  2069. option.value = languageId;
  2070. option.textContent = label;
  2071. eLanguage.appendChild(option);
  2072. }
  2073. // load
  2074. const langSelection = config.get("langSelection", {});
  2075. if (languageId in langSelection) {
  2076. const prev = langSelection[languageId];
  2077. const [lang, _] = langs.find(([lang, label]) => lang == prev);
  2078. if (lang)
  2079. eLanguage.value = lang;
  2080. }
  2081. events.trig("enable");
  2082. }
  2083. catch (error) {
  2084. console.log(`language: ? (${languageId})`);
  2085. console.error(error);
  2086. const option = document.createElement("option");
  2087. option.className = "fg-danger";
  2088. option.textContent = error;
  2089. eLanguage.appendChild(option);
  2090. events.trig("disable");
  2091. }
  2092. }
  2093. site.language.addListener(() => setLanguage());
  2094. eAllowableError.disabled = !eAllowableErrorCheck.checked;
  2095. eAllowableErrorCheck.addEventListener("change", event => {
  2096. eAllowableError.disabled = !eAllowableErrorCheck.checked;
  2097. });
  2098. }
  2099. // テスト実行
  2100. function runTest(title, input, output = null) {
  2101. const options = { trim: true, split: true, };
  2102. if (eAllowableErrorCheck.checked) {
  2103. options.allowableError = parseFloat(eAllowableError.value);
  2104. }
  2105. return atCoderEasyTest.runTest(title, eLanguage.value, site.sourceCode, input, output, options);
  2106. }
  2107. function runAllCases(testcases) {
  2108. const pairs = testcases.map(testcase => runTest(testcase.title, testcase.input, testcase.output));
  2109. resultList.addResult(pairs);
  2110. return Promise.all(pairs.map(([pResult, _]) => pResult.then(result => {
  2111. if (result.status == "AC")
  2112. return Promise.resolve(result);
  2113. else
  2114. return Promise.reject(result);
  2115. })));
  2116. }
  2117. eRun.addEventListener("click", _ => {
  2118. const title = "Run";
  2119. const input = eInput.value;
  2120. const output = eOutput.value;
  2121. runTest(title, input, output || null);
  2122. });
  2123. await doneOrFail(pBottomMenu.then(bottomMenu => bottomMenu.addTab("easy-test", "Easy Test", root)));
  2124. // place "Run" button on each sample
  2125. for (const testCase of site.testCases) {
  2126. const eRunButton = html2element(hRunButton);
  2127. eRunButton.addEventListener("click", async () => {
  2128. const [pResult, pTab] = runTest(testCase.title, testCase.input, testCase.output);
  2129. await pResult;
  2130. (await pTab).show();
  2131. });
  2132. testCase.anchor.insertAdjacentElement("afterend", eRunButton);
  2133. events.on("disable", () => {
  2134. eRunButton.classList.add("disabled");
  2135. });
  2136. events.on("enable", () => {
  2137. eRunButton.classList.remove("disabled");
  2138. });
  2139. }
  2140. // place "Test & Submit" button
  2141. {
  2142. const button = html2element(hTestAndSubmit);
  2143. site.testButtonContainer.appendChild(button);
  2144. const testAndSubmit = async () => {
  2145. await runAllCases(site.testCases);
  2146. site.submit();
  2147. };
  2148. button.addEventListener("click", testAndSubmit);
  2149. events.on("testAndSubmit", testAndSubmit);
  2150. events.on("disable", () => button.classList.add("disabled"));
  2151. events.on("enable", () => button.classList.remove("disabled"));
  2152. }
  2153. // place "Test All Samples" button
  2154. {
  2155. const button = html2element(hTestAllSamples);
  2156. site.testButtonContainer.appendChild(button);
  2157. const testAllSamples = () => runAllCases(site.testCases);
  2158. button.addEventListener("click", testAllSamples);
  2159. events.on("testAllSamples", testAllSamples);
  2160. events.on("disable", () => button.classList.add("disabled"));
  2161. events.on("enable", () => button.classList.remove("disabled"));
  2162. }
  2163. }
  2164. // place "Restore Last Play" button
  2165. try {
  2166. const restoreButton = doc.createElement("a");
  2167. restoreButton.className = "btn btn-danger btn-sm";
  2168. restoreButton.textContent = "Restore Last Play";
  2169. restoreButton.addEventListener("click", async () => {
  2170. try {
  2171. const lastCode = await codeSaver.restore();
  2172. if (site.sourceCode.length == 0 || confirm("Your current code will be replaced. Are you sure?")) {
  2173. site.sourceCode = lastCode;
  2174. }
  2175. }
  2176. catch (reason) {
  2177. alert(reason);
  2178. }
  2179. });
  2180. site.sideButtonContainer.appendChild(restoreButton);
  2181. }
  2182. catch (e) {
  2183. console.error(e);
  2184. }
  2185. // キーボードショートカット
  2186. config.registerFlag("ui.useKeyboardShortcut", true, "Use Keyboard Shortcuts");
  2187. unsafeWindow.addEventListener("keydown", (event) => {
  2188. if (config.get("ui.useKeyboardShortcut", true)) {
  2189. if (event.key == "Enter" && event.ctrlKey) {
  2190. events.trig("testAndSubmit");
  2191. }
  2192. else if (event.key == "Enter" && event.altKey) {
  2193. events.trig("testAllSamples");
  2194. }
  2195. else if (event.key == "Escape" && event.altKey) {
  2196. pBottomMenu.then(bottomMenu => bottomMenu.toggle());
  2197. }
  2198. }
  2199. });
  2200. })();
  2201. })();