Download tasks/leetcode/environment/reference/clone/static/js/workbench.js from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 5.06 kB
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/leetcode/environment/reference/clone/static/js/workbench.js
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/leetcode/environment/reference/clone/static/js/workbench.js
-
curl -L -o workbench.js https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/leetcode/environment/reference/clone/static/js/workbench.js
5.06 kB
| /* Workspace interactions. | |
| * | |
| * Run and Submit are ordinary form submissions to /problems/<slug>/judge, so | |
| * the workspace works with scripting disabled. This file adds the editor | |
| * affordances the captured pane shows: line numbers, the Ln/Col readout, tab | |
| * insertion, the language switch, the case tabs, the console tabs and the | |
| * stopwatch. No guest code is ever executed here or on the server. */ | |
| (function () { | |
| "use strict"; | |
| var editor = document.querySelector("[data-editor]"); | |
| var gutter = document.querySelector("[data-gutter]"); | |
| var cursor = document.querySelector("[data-cursor]"); | |
| var saved = document.querySelector("[data-saved-state]"); | |
| function lineCount(value) { | |
| return value.split("\n").length; | |
| } | |
| function paintGutter() { | |
| if (!gutter || !editor) { | |
| return; | |
| } | |
| var total = lineCount(editor.value); | |
| var numbers = []; | |
| for (var index = 1; index <= total; index += 1) { | |
| numbers.push(index); | |
| } | |
| gutter.textContent = numbers.join("\n"); | |
| } | |
| function paintCursor() { | |
| if (!cursor || !editor) { | |
| return; | |
| } | |
| var upto = editor.value.slice(0, editor.selectionStart); | |
| var lines = upto.split("\n"); | |
| cursor.textContent = | |
| "Ln " + lines.length + ", Col " + (lines[lines.length - 1].length + 1); | |
| } | |
| if (editor) { | |
| paintGutter(); | |
| paintCursor(); | |
| editor.addEventListener("input", function () { | |
| paintGutter(); | |
| if (saved) { | |
| saved.textContent = "Unsaved"; | |
| } | |
| }); | |
| ["keyup", "click", "select"].forEach(function (name) { | |
| editor.addEventListener(name, paintCursor); | |
| }); | |
| editor.addEventListener("scroll", function () { | |
| if (gutter) { | |
| gutter.style.transform = "translateY(" + -editor.scrollTop + "px)"; | |
| } | |
| }); | |
| editor.addEventListener("keydown", function (event) { | |
| if (event.key !== "Tab") { | |
| return; | |
| } | |
| event.preventDefault(); | |
| var start = editor.selectionStart; | |
| var end = editor.selectionEnd; | |
| editor.value = | |
| editor.value.slice(0, start) + " " + editor.value.slice(end); | |
| editor.selectionStart = editor.selectionEnd = start + 4; | |
| paintGutter(); | |
| paintCursor(); | |
| }); | |
| } | |
| /* ---- language switch: reload with the chosen language -------------- */ | |
| var language = document.querySelector("[data-language]"); | |
| if (language) { | |
| language.addEventListener("change", function () { | |
| var url = new URL(window.location.href); | |
| url.searchParams.set("lang", language.value); | |
| window.location.href = url.pathname + url.search; | |
| }); | |
| } | |
| /* ---- testcase tabs -------------------------------------------------- */ | |
| var caseTabs = Array.prototype.slice.call( | |
| document.querySelectorAll("[data-case-tab]") | |
| ); | |
| var casePanels = Array.prototype.slice.call( | |
| document.querySelectorAll("[data-case-panel]") | |
| ); | |
| caseTabs.forEach(function (tab) { | |
| tab.addEventListener("click", function () { | |
| var wanted = tab.getAttribute("data-case-tab"); | |
| caseTabs.forEach(function (other) { | |
| var active = other === tab; | |
| other.classList.toggle("is-active", active); | |
| other.setAttribute("aria-selected", active ? "true" : "false"); | |
| }); | |
| casePanels.forEach(function (panel) { | |
| panel.classList.toggle( | |
| "is-hidden", | |
| panel.getAttribute("data-case-panel") !== wanted | |
| ); | |
| }); | |
| }); | |
| }); | |
| /* ---- console tabs --------------------------------------------------- */ | |
| var consoleTabs = Array.prototype.slice.call( | |
| document.querySelectorAll("[data-console-tab]") | |
| ); | |
| var consolePanels = Array.prototype.slice.call( | |
| document.querySelectorAll("[data-console-panel]") | |
| ); | |
| consoleTabs.forEach(function (tab) { | |
| tab.addEventListener("click", function () { | |
| var wanted = tab.getAttribute("data-console-tab"); | |
| consoleTabs.forEach(function (other) { | |
| other.classList.toggle("is-active", other === tab); | |
| }); | |
| consolePanels.forEach(function (panel) { | |
| panel.classList.toggle( | |
| "is-hidden", | |
| panel.getAttribute("data-console-panel") !== wanted | |
| ); | |
| }); | |
| }); | |
| }); | |
| /* ---- stopwatch ------------------------------------------------------ */ | |
| var stopwatch = document.querySelector("[data-stopwatch]"); | |
| if (stopwatch) { | |
| var elapsed = 0; | |
| var running = false; | |
| var pad = function (value) { | |
| return value < 10 ? "0" + value : String(value); | |
| }; | |
| var paint = function () { | |
| stopwatch.textContent = | |
| pad(Math.floor(elapsed / 3600)) + | |
| ":" + | |
| pad(Math.floor((elapsed % 3600) / 60)) + | |
| ":" + | |
| pad(elapsed % 60); | |
| }; | |
| stopwatch.setAttribute("role", "button"); | |
| stopwatch.setAttribute("tabindex", "0"); | |
| stopwatch.title = "Start or pause the stopwatch"; | |
| stopwatch.addEventListener("click", function () { | |
| running = !running; | |
| }); | |
| window.setInterval(function () { | |
| if (running) { | |
| elapsed += 1; | |
| paint(); | |
| } | |
| }, 1000); | |
| paint(); | |
| } | |
| })(); | |