// Given the name of an array saved to localStorage, return it (if possible). function savedArray(name) { try { let saved = JSON.parse(localStorage.getItem(name)); return saved; } catch { return []; }; } // Iterate over the commands-table and save each of the user’s valid // name+command rows to storage. function saveCommands() { let commands = []; for (commandTr of document.getElementsByClassName("nameCommandRow")) { let name = commandTr.getElementsByClassName("name")[0].value; let command = commandTr.getElementsByClassName("command")[0].value; if (name && command) commands.push([name, command]); } localStorage.setItem("commands", JSON.stringify(commands)); } // Iterate over the regex-table and save each of the user’s valid // regex+command-index rows to storage. function saveRegexRules() { let rules = []; for (regexTr of document.getElementsByClassName("regexCommandRow")) { let regex = regexTr.getElementsByClassName("regex")[0].value; let command_i = regexTr.getElementsByClassName("commandMenu")[0].value; if (regex && command_i) rules.push([regex, command_i]); } localStorage.setItem("urlRules", JSON.stringify(rules)); } // Iterate over the commands-table and save each of the user’s valid // name+command rows to storage. function saveDownloadCommands() { let downloads = []; for (downloadTr of document.getElementsByClassName("downloadCommandRow")) { let regex = downloadTr.getElementsByClassName("regex")[0].value; let command = downloadTr.getElementsByClassName("command")[0].value; let type = downloadTr.getElementsByClassName("startFinishMenu")[0].value; if (regex && command && type) downloads.push([regex, command, type]); } console.log(downloads); localStorage.setItem("downloadCommands", JSON.stringify(downloads)); } // Read the user’s saved name+command pairs from storage, and populate the // command-table with them. function populateCommandTable() { let commandTable = document.getElementById("commandTable"); try { let savedCommands = savedArray("commands"); for (cmdName of savedCommands) { let commandTr = createCommandTr(cmdName[0], cmdName[1]); commandTable.appendChild(commandTr); } } catch { }; // Always add a spare entry. commandTable.appendChild(createCommandTr("", "")); } // Read the user’s saved regex+command-index pairs from storage, and populate the // command-table with them. function populateRegexTable() { let regexTable = document.getElementById("regexTable"); try { let savedRegex = savedArray("urlRules"); for (let i = 0; i < savedRegex.length; i++) { let regexTr = createRegexTr(savedRegex[i][0], savedRegex[i][1], createCommandMenu()); regexTable.appendChild(regexTr); } } catch { }; // Always, again, have a spare tire!! regexTable.appendChild(createRegexTr("", "", createCommandMenu())); } // Read the user’s saved type+name+command pairs from storage, and populate the // downloads-table with them. function populateDownloadTable() { let downloadTable = document.getElementById("downloadTable"); try { let savedDownloads = savedArray("downloadCommands") || []; for (regexCommandType of savedDownloads) { let downloadTr = createDownloadTr(regexCommandType[0], regexCommandType[1], regexCommandType[2]); downloadTable.appendChild(downloadTr); } } catch {}; // And yet again! Have spares!!! downloadTable.appendChild(createDownloadTr("", "", 0)); } // Create a