Download tasks/leetcode/solution/site/implementation/clone/static/js/problemset.js from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 7.06 kB
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/leetcode/solution/site/implementation/clone/static/js/problemset.js
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/leetcode/solution/site/implementation/clone/static/js/problemset.js
-
curl -L -o problemset.js https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/leetcode/solution/site/implementation/clone/static/js/problemset.js
7.06 kB
| /* Problem-set interactions. | |
| * | |
| * Every filter, sort and page is expressed in the URL, so the page works with | |
| * scripting disabled: the popovers are <details>, the search box is a real | |
| * form field, and each control is a link. This file only adds the affordances | |
| * the captured page has on top of that — instant search submission, popover | |
| * dismissal, the topic-strip expander, the day countdown and company paging. */ | |
| (function () { | |
| "use strict"; | |
| /* ---- header: mobile navigation and search ------------------------- */ | |
| var navToggle = document.querySelector("[data-nav-toggle]"); | |
| var nav = document.querySelector("[data-nav]"); | |
| if (navToggle && nav) { | |
| navToggle.addEventListener("click", function () { | |
| var open = nav.classList.toggle("is-open"); | |
| navToggle.setAttribute("aria-expanded", open ? "true" : "false"); | |
| }); | |
| } | |
| var navMenus = Array.prototype.slice.call(document.querySelectorAll("[data-navmenu]")); | |
| navMenus.forEach(function (menu) { | |
| menu.addEventListener("mouseenter", function () { | |
| navMenus.forEach(function (other) { | |
| if (other !== menu) other.open = false; | |
| }); | |
| menu.open = true; | |
| }); | |
| menu.addEventListener("mouseleave", function () { | |
| menu.open = false; | |
| }); | |
| }); | |
| var searchToggle = document.querySelector("[data-site-search-toggle]"); | |
| var siteSearch = document.querySelector(".ap-search"); | |
| if (searchToggle && siteSearch) { | |
| searchToggle.addEventListener("click", function () { | |
| siteSearch.classList.toggle("is-open"); | |
| var field = siteSearch.querySelector("input"); | |
| if (field && siteSearch.classList.contains("is-open")) { | |
| field.focus(); | |
| } | |
| }); | |
| } | |
| var siteSearchField = document.querySelector("[data-site-search]"); | |
| if (siteSearchField) { | |
| siteSearchField.addEventListener("keydown", function (event) { | |
| if (event.key !== "Enter") { | |
| return; | |
| } | |
| event.preventDefault(); | |
| var term = siteSearchField.value.trim(); | |
| window.location.href = term | |
| ? "/problemset/?search=" + encodeURIComponent(term) | |
| : "/problemset/"; | |
| }); | |
| } | |
| /* ---- collapsible library rail ------------------------------------ */ | |
| var railToggle = document.querySelector("[data-rail-toggle]"); | |
| if (railToggle) { | |
| var railShell = railToggle.closest(".lc-shell, .ps"); | |
| var storageKey = "leetcode-library-rail-collapsed"; | |
| var setRail = function (collapsed) { | |
| if (!railShell) return; | |
| railShell.classList.toggle("is-rail-collapsed", collapsed); | |
| railToggle.setAttribute("aria-expanded", collapsed ? "false" : "true"); | |
| railToggle.setAttribute("aria-label", collapsed ? "Expand library sidebar" : "Collapse library sidebar"); | |
| var glyph = railToggle.querySelector("span"); | |
| if (glyph) glyph.textContent = collapsed ? "›" : "‹"; | |
| }; | |
| setRail(window.sessionStorage.getItem(storageKey) === "1"); | |
| railToggle.addEventListener("click", function () { | |
| var collapsed = !railShell.classList.contains("is-rail-collapsed"); | |
| setRail(collapsed); | |
| window.sessionStorage.setItem(storageKey, collapsed ? "1" : "0"); | |
| }); | |
| } | |
| /* ---- filter popovers ---------------------------------------------- */ | |
| var pops = Array.prototype.slice.call(document.querySelectorAll("[data-pop]")); | |
| pops.forEach(function (pop) { | |
| pop.addEventListener("toggle", function () { | |
| if (!pop.open) { | |
| return; | |
| } | |
| pops.forEach(function (other) { | |
| if (other !== pop) { | |
| other.open = false; | |
| } | |
| }); | |
| }); | |
| }); | |
| document.addEventListener("click", function (event) { | |
| pops.forEach(function (pop) { | |
| if (pop.open && !pop.contains(event.target)) { | |
| pop.open = false; | |
| } | |
| }); | |
| }); | |
| document.addEventListener("keydown", function (event) { | |
| if (event.key === "Escape") { | |
| pops.forEach(function (pop) { | |
| pop.open = false; | |
| }); | |
| } | |
| }); | |
| /* ---- debounced search --------------------------------------------- */ | |
| var controls = document.querySelector("[data-controls]"); | |
| if (controls) { | |
| var field = controls.querySelector('input[name="search"]'); | |
| if (field) { | |
| var timer = null; | |
| field.addEventListener("input", function () { | |
| window.clearTimeout(timer); | |
| timer = window.setTimeout(function () { | |
| controls.submit(); | |
| }, 400); | |
| }); | |
| } | |
| } | |
| /* ---- topic strip --------------------------------------------------- */ | |
| var strip = document.querySelector("[data-topic-strip]"); | |
| var expand = document.querySelector("[data-topic-expand]"); | |
| if (strip && expand) { | |
| expand.addEventListener("click", function () { | |
| var expanded = strip.classList.toggle("is-expanded"); | |
| expand.setAttribute("aria-expanded", expanded ? "true" : "false"); | |
| expand.childNodes[0].nodeValue = expanded ? "Collapse" : "Expand"; | |
| }); | |
| } | |
| /* ---- daily countdown ----------------------------------------------- */ | |
| var countdown = document.querySelector("[data-countdown]"); | |
| if (countdown) { | |
| var deadline = new Date(countdown.getAttribute("data-deadline")); | |
| var tick = function () { | |
| var remaining = Math.max(0, Math.floor((deadline - new Date()) / 1000)); | |
| var hours = Math.floor(remaining / 3600); | |
| var minutes = Math.floor((remaining % 3600) / 60); | |
| var seconds = remaining % 60; | |
| var pad = function (value) { | |
| return value < 10 ? "0" + value : String(value); | |
| }; | |
| countdown.textContent = | |
| pad(hours) + ":" + pad(minutes) + ":" + pad(seconds) + " left"; | |
| }; | |
| tick(); | |
| window.setInterval(tick, 1000); | |
| } | |
| /* ---- trending companies: paging and filtering ---------------------- */ | |
| var list = document.querySelector("[data-company-list]"); | |
| if (list) { | |
| var items = Array.prototype.slice.call(list.children); | |
| var pages = | |
| items.reduce(function (highest, item) { | |
| return Math.max(highest, Number(item.getAttribute("data-page"))); | |
| }, 0) + 1; | |
| var page = 0; | |
| var term = ""; | |
| var paint = function () { | |
| items.forEach(function (item) { | |
| var text = item.textContent.toLowerCase(); | |
| var matches = !term || text.indexOf(term) !== -1; | |
| var onPage = term | |
| ? true | |
| : Number(item.getAttribute("data-page")) === page; | |
| item.hidden = !(matches && onPage); | |
| }); | |
| }; | |
| var prev = document.querySelector("[data-company-prev]"); | |
| var next = document.querySelector("[data-company-next]"); | |
| if (prev) { | |
| prev.addEventListener("click", function () { | |
| page = (page - 1 + pages) % pages; | |
| paint(); | |
| }); | |
| } | |
| if (next) { | |
| next.addEventListener("click", function () { | |
| page = (page + 1) % pages; | |
| paint(); | |
| }); | |
| } | |
| var companySearch = document.querySelector("[data-company-search]"); | |
| if (companySearch) { | |
| companySearch.addEventListener("input", function () { | |
| term = companySearch.value.trim().toLowerCase(); | |
| paint(); | |
| }); | |
| } | |
| paint(); | |
| } | |
| })(); | |