CoCalc is a real-time collaborative commercial alternative to JupyterHub and Overleaf that provides Jupyter Notebooks, LaTeX documents, and SageMath.
CoCalc is a real-time collaborative commercial alternative to JupyterHub and Overleaf that provides Jupyter Notebooks, LaTeX documents, and SageMath.
Path: blob/master/PHEx/src/popup.js
Views: 720
(async() => {1function set(key, value) {2chrome.storage.local.set({ [key]: value })3};4function get(key) {5return new Promise(resolve => {6chrome.storage.local.get([key], result => {7resolve(result[key])8})9})10};11function validURL(str) {12var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol13'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name14'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address15'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path16'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string17'(\\#[-a-z\\d_]*)?$','i'); // fragment locator18return !!pattern.test(str) || new URL(str).hostname === "localhost";19}2021const checkbox = document.querySelector(".check")22const input = document.querySelector("input")2324input.value = await get("url") || "";25checkbox.checked = await get("checked") || false;2627input.onchange = () => {28document.querySelector("p").innerHTML = ""29}3031checkbox.addEventListener("click", async (event) => {32if (await get("checked")) {33// if already checked, no need to run checks34// set checked to new value, which should be false35set("checked", checkbox.checked);36} else {37// if we're turning on checked, we need to run a few checks38if (validURL(input.value)) {39// if the URL is valid, update url and checked to their latest values.40set("url", input.value);41set("checked", checkbox.checked);42} else {43// if the URL is invalid, scream at them until they burst into tears44document.querySelector("p").innerHTML = "Invalid URL";45checkbox.checked = false;46}47}48})49})();5051