1
0

ui-options.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /*
  2. * Copyright 2010-2019 Gildas Lormeau
  3. * contact : gildas.lormeau <at> gmail.com
  4. *
  5. * This file is part of SingleFile.
  6. *
  7. * The code in this file is free software: you can redistribute it and/or
  8. * modify it under the terms of the GNU Affero General Public License
  9. * (GNU AGPL) as published by the Free Software Foundation, either version 3
  10. * of the License, or (at your option) any later version.
  11. *
  12. * The code in this file is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  15. * General Public License for more details.
  16. *
  17. * As additional permission under GNU AGPL version 3 section 7, you may
  18. * distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
  19. * AGPL normally required by section 4, provided you include this license
  20. * notice and a URL through which recipients can access the Corresponding
  21. * Source.
  22. */
  23. /* global browser, window, document, localStorage, FileReader, location, fetch, TextDecoder, DOMParser, HTMLElement */
  24. (async () => {
  25. const HELP_ICON_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABIUlEQVQ4y+2TsarCMBSGvxTBRdqiUZAWOrhJB9EXcPKFfCvfQYfulUKHDqXg4CYUJSioYO4mSDX3ttzt3n87fMlHTpIjlsulxpDZbEYYhgghSNOUOI5Ny2mZYBAELBYLer0eAJ7ncTweKYri4x7LJJRS0u12n7XrukgpjSc0CpVSXK/XZ32/31FKNW85z3PW6zXT6RSAJEnIsqy5UGvNZrNhu90CcDqd+C6tT6J+v//2Th+PB2VZ1hN2Oh3G4zGTyQTbtl/YbrdjtVpxu91+Ljyfz0RRhG3bzOfzF+Y4TvNXvlwuaK2pE4tfzr/wzwsty0IIURlL0998KxRCMBqN8H2/wlzXJQxD2u12vVkeDoeUZUkURRU+GAw4HA7s9/sK+wK6CWHasQ/S/wAAAABJRU5ErkJggg==";
  26. const HELP_PAGE_PATH = "/extension/ui/pages/help.html";
  27. const { DEFAULT_PROFILE_NAME, DISABLED_PROFILE_NAME, CURRENT_PROFILE_NAME } = await browser.runtime.sendMessage({ method: "config.getConstants" });
  28. const removeHiddenElementsLabel = document.getElementById("removeHiddenElementsLabel");
  29. const removeUnusedStylesLabel = document.getElementById("removeUnusedStylesLabel");
  30. const removeUnusedFontsLabel = document.getElementById("removeUnusedFontsLabel");
  31. const removeFramesLabel = document.getElementById("removeFramesLabel");
  32. const removeImportsLabel = document.getElementById("removeImportsLabel");
  33. const removeScriptsLabel = document.getElementById("removeScriptsLabel");
  34. const saveRawPageLabel = document.getElementById("saveRawPageLabel");
  35. const saveToClipboardLabel = document.getElementById("saveToClipboardLabel");
  36. const compressHTMLLabel = document.getElementById("compressHTMLLabel");
  37. const compressCSSLabel = document.getElementById("compressCSSLabel");
  38. const loadDeferredImagesLabel = document.getElementById("loadDeferredImagesLabel");
  39. const loadDeferredImagesMaxIdleTimeLabel = document.getElementById("loadDeferredImagesMaxIdleTimeLabel");
  40. const addMenuEntryLabel = document.getElementById("addMenuEntryLabel");
  41. const filenameTemplateLabel = document.getElementById("filenameTemplateLabel");
  42. const shadowEnabledLabel = document.getElementById("shadowEnabledLabel");
  43. const setMaxResourceSizeLabel = document.getElementById("setMaxResourceSizeLabel");
  44. const maxResourceSizeLabel = document.getElementById("maxResourceSizeLabel");
  45. const confirmFilenameLabel = document.getElementById("confirmFilenameLabel");
  46. const filenameConflictActionLabel = document.getElementById("filenameConflictActionLabel");
  47. const filenameConflictActionUniquifyLabel = document.getElementById("filenameConflictActionUniquifyLabel");
  48. const filenameConflictActionOverwriteLabel = document.getElementById("filenameConflictActionOverwriteLabel");
  49. const filenameConflictActionPromptLabel = document.getElementById("filenameConflictActionPromptLabel");
  50. const removeAudioLabel = document.getElementById("removeAudioLabel");
  51. const removeVideoLabel = document.getElementById("removeVideoLabel");
  52. const displayInfobarLabel = document.getElementById("displayInfobarLabel");
  53. const displayStatsLabel = document.getElementById("displayStatsLabel");
  54. const backgroundSaveLabel = document.getElementById("backgroundSaveLabel");
  55. const autoSaveDelayLabel = document.getElementById("autoSaveDelayLabel");
  56. const autoSaveLoadLabel = document.getElementById("autoSaveLoadLabel");
  57. const autoSaveUnloadLabel = document.getElementById("autoSaveUnloadLabel");
  58. const autoSaveLoadOrUnloadLabel = document.getElementById("autoSaveLoadOrUnloadLabel");
  59. const autoSaveRepeatLabel = document.getElementById("autoSaveRepeatLabel");
  60. const autoSaveRepeatDelayLabel = document.getElementById("autoSaveRepeatDelayLabel");
  61. const removeAlternativeFontsLabel = document.getElementById("removeAlternativeFontsLabel");
  62. const removeAlternativeImagesLabel = document.getElementById("removeAlternativeImagesLabel");
  63. const removeAlternativeMediasLabel = document.getElementById("removeAlternativeMediasLabel");
  64. const titleLabel = document.getElementById("titleLabel");
  65. const userInterfaceLabel = document.getElementById("userInterfaceLabel");
  66. const filenameLabel = document.getElementById("filenameLabel");
  67. const htmlContentLabel = document.getElementById("htmlContentLabel");
  68. const imagesLabel = document.getElementById("imagesLabel");
  69. const stylesheetsLabel = document.getElementById("stylesheetsLabel");
  70. const fontsLabel = document.getElementById("fontsLabel");
  71. const otherResourcesLabel = document.getElementById("otherResourcesLabel");
  72. const autoSaveLabel = document.getElementById("autoSaveLabel");
  73. const autoSettingsLabel = document.getElementById("autoSettingsLabel");
  74. const autoSettingsUrlLabel = document.getElementById("autoSettingsUrlLabel");
  75. const autoSettingsProfileLabel = document.getElementById("autoSettingsProfileLabel");
  76. const autoSettingsAutoSaveProfileLabel = document.getElementById("autoSettingsAutoSaveProfileLabel");
  77. const showAllProfilesLabel = document.getElementById("showAllProfilesLabel");
  78. const showAutoSaveProfileLabel = document.getElementById("showAutoSaveProfileLabel");
  79. const groupDuplicateImagesLabel = document.getElementById("groupDuplicateImagesLabel");
  80. const confirmInfobarLabel = document.getElementById("confirmInfobarLabel");
  81. const infobarTemplateLabel = document.getElementById("infobarTemplateLabel");
  82. const miscLabel = document.getElementById("miscLabel");
  83. const helpLabel = document.getElementById("helpLabel");
  84. const addProfileButton = document.getElementById("addProfileButton");
  85. const deleteProfileButton = document.getElementById("deleteProfileButton");
  86. const renameProfileButton = document.getElementById("renameProfileButton");
  87. const resetButton = document.getElementById("resetButton");
  88. const exportButton = document.getElementById("exportButton");
  89. const importButton = document.getElementById("importButton");
  90. const fileInput = document.getElementById("fileInput");
  91. const profileNamesInput = document.getElementById("profileNamesInput");
  92. const removeHiddenElementsInput = document.getElementById("removeHiddenElementsInput");
  93. const removeUnusedStylesInput = document.getElementById("removeUnusedStylesInput");
  94. const removeUnusedFontsInput = document.getElementById("removeUnusedFontsInput");
  95. const removeFramesInput = document.getElementById("removeFramesInput");
  96. const removeImportsInput = document.getElementById("removeImportsInput");
  97. const removeScriptsInput = document.getElementById("removeScriptsInput");
  98. const saveRawPageInput = document.getElementById("saveRawPageInput");
  99. const saveToClipboardInput = document.getElementById("saveToClipboardInput");
  100. const compressHTMLInput = document.getElementById("compressHTMLInput");
  101. const compressCSSInput = document.getElementById("compressCSSInput");
  102. const loadDeferredImagesInput = document.getElementById("loadDeferredImagesInput");
  103. const loadDeferredImagesMaxIdleTimeInput = document.getElementById("loadDeferredImagesMaxIdleTimeInput");
  104. const contextMenuEnabledInput = document.getElementById("contextMenuEnabledInput");
  105. const filenameTemplateInput = document.getElementById("filenameTemplateInput");
  106. const shadowEnabledInput = document.getElementById("shadowEnabledInput");
  107. const maxResourceSizeInput = document.getElementById("maxResourceSizeInput");
  108. const maxResourceSizeEnabledInput = document.getElementById("maxResourceSizeEnabledInput");
  109. const confirmFilenameInput = document.getElementById("confirmFilenameInput");
  110. const filenameConflictActionInput = document.getElementById("filenameConflictActionInput");
  111. const removeAudioSrcInput = document.getElementById("removeAudioSrcInput");
  112. const removeVideoSrcInput = document.getElementById("removeVideoSrcInput");
  113. const displayInfobarInput = document.getElementById("displayInfobarInput");
  114. const displayStatsInput = document.getElementById("displayStatsInput");
  115. const backgroundSaveInput = document.getElementById("backgroundSaveInput");
  116. const autoSaveDelayInput = document.getElementById("autoSaveDelayInput");
  117. const autoSaveLoadInput = document.getElementById("autoSaveLoadInput");
  118. const autoSaveUnloadInput = document.getElementById("autoSaveUnloadInput");
  119. const autoSaveLoadOrUnloadInput = document.getElementById("autoSaveLoadOrUnloadInput");
  120. const autoSaveRepeatInput = document.getElementById("autoSaveRepeatInput");
  121. const autoSaveRepeatDelayInput = document.getElementById("autoSaveRepeatDelayInput");
  122. const removeAlternativeFontsInput = document.getElementById("removeAlternativeFontsInput");
  123. const removeAlternativeImagesInput = document.getElementById("removeAlternativeImagesInput");
  124. const removeAlternativeMediasInput = document.getElementById("removeAlternativeMediasInput");
  125. const groupDuplicateImagesInput = document.getElementById("groupDuplicateImagesInput");
  126. const infobarTemplateInput = document.getElementById("infobarTemplateInput");
  127. const confirmInfobarInput = document.getElementById("confirmInfobarInput");
  128. const expandAllButton = document.getElementById("expandAllButton");
  129. const rulesDeleteAllButton = document.getElementById("rulesDeleteAllButton");
  130. const ruleUrlInput = document.getElementById("ruleUrlInput");
  131. const ruleProfileInput = document.getElementById("ruleProfileInput");
  132. const ruleAutoSaveProfileInput = document.getElementById("ruleAutoSaveProfileInput");
  133. const ruleEditProfileInput = document.getElementById("ruleEditProfileInput");
  134. const ruleEditAutoSaveProfileInput = document.getElementById("ruleEditAutoSaveProfileInput");
  135. const ruleAddButton = document.getElementById("ruleAddButton");
  136. const rulesElement = document.querySelector(".rules-table");
  137. const rulesContainerElement = document.querySelector(".rules-table-container");
  138. const ruleEditUrlInput = document.getElementById("ruleEditUrlInput");
  139. const ruleEditButton = document.getElementById("ruleEditButton");
  140. const createURLElement = rulesElement.querySelector(".rule-create");
  141. const showAllProfilesInput = document.getElementById("showAllProfilesInput");
  142. const showAutoSaveProfileInput = document.getElementById("showAutoSaveProfileInput");
  143. const resetAllButton = document.getElementById("resetAllButton");
  144. const resetCurrentButton = document.getElementById("resetCurrentButton");
  145. const resetCancelButton = document.getElementById("resetCancelButton");
  146. const confirmButton = document.getElementById("confirmButton");
  147. const cancelButton = document.getElementById("cancelButton");
  148. const promptInput = document.getElementById("promptInput");
  149. const promptCancelButton = document.getElementById("promptCancelButton");
  150. const promptConfirmButton = document.getElementById("promptConfirmButton");
  151. let sidePanelDisplay;
  152. browser.runtime.onMessage.addListener(message => {
  153. if (message.method == "options.refresh" || (message.method == "options.refreshPanel" && sidePanelDisplay)) {
  154. refresh(message.profileName);
  155. }
  156. });
  157. let pendingSave = Promise.resolve();
  158. let autoSaveProfileChanged;
  159. getHelpContents();
  160. ruleProfileInput.onchange = () => {
  161. if (!autoSaveProfileChanged && ruleProfileInput.value != CURRENT_PROFILE_NAME) {
  162. ruleAutoSaveProfileInput.value = ruleProfileInput.value;
  163. }
  164. };
  165. ruleAutoSaveProfileInput.onchange = () => {
  166. autoSaveProfileChanged = true;
  167. };
  168. rulesDeleteAllButton.addEventListener("click", async () => {
  169. if (await confirm(browser.i18n.getMessage("optionsDeleteDisplayedRulesConfirm"))) {
  170. await browser.runtime.sendMessage({ method: "config.deleteRules", profileName: !showAllProfilesInput.checked && profileNamesInput.value });
  171. await refresh();
  172. await refreshExternalComponents();
  173. }
  174. }, false);
  175. createURLElement.onsubmit = async event => {
  176. event.preventDefault();
  177. try {
  178. await browser.runtime.sendMessage({ method: "config.addRule", url: ruleUrlInput.value, profileName: ruleProfileInput.value, autoSaveProfileName: ruleAutoSaveProfileInput.value });
  179. } catch (error) {
  180. // ignored
  181. }
  182. ruleUrlInput.value = "";
  183. ruleProfileInput.value = ruleAutoSaveProfileInput.value = DEFAULT_PROFILE_NAME;
  184. autoSaveProfileChanged = false;
  185. await refresh();
  186. await refreshExternalComponents();
  187. ruleUrlInput.focus();
  188. };
  189. ruleUrlInput.onclick = ruleUrlInput.onkeyup = ruleUrlInput.onchange = async () => {
  190. ruleAddButton.disabled = !ruleUrlInput.value;
  191. const rules = await browser.runtime.sendMessage({ method: "config.getRules" });
  192. if (rules.find(rule => rule.url == ruleUrlInput.value)) {
  193. ruleAddButton.disabled = true;
  194. }
  195. };
  196. ruleEditUrlInput.onclick = ruleEditUrlInput.onkeyup = ruleEditUrlInput.onchange = async () => {
  197. ruleEditButton.disabled = !ruleEditUrlInput.value;
  198. const rules = await browser.runtime.sendMessage({ method: "config.getRules" });
  199. if (rules.find(rule => rule.url == ruleEditUrlInput.value)) {
  200. ruleEditButton.disabled = true;
  201. }
  202. };
  203. if (getLocalStorageItem("optionShowAutoSaveProfile")) {
  204. showAutoSaveProfileInput.checked = true;
  205. rulesContainerElement.classList.remove("compact");
  206. }
  207. showAutoSaveProfileInput.addEventListener("click", () => {
  208. if (showAutoSaveProfileInput.checked) {
  209. setLocalStorageItem("optionShowAutoSaveProfile", 1);
  210. rulesContainerElement.classList.remove("compact");
  211. } else {
  212. removeLocalStorageItem("optionShowAutoSaveProfile");
  213. rulesContainerElement.classList.add("compact");
  214. }
  215. }, false);
  216. if (getLocalStorageItem("optionShowAllProfiles")) {
  217. showAllProfilesInput.checked = true;
  218. }
  219. showAllProfilesInput.addEventListener("click", () => {
  220. if (showAllProfilesInput.checked) {
  221. setLocalStorageItem("optionShowAllProfiles", 1);
  222. } else {
  223. removeLocalStorageItem("optionShowAllProfiles");
  224. }
  225. }, false);
  226. addProfileButton.addEventListener("click", async () => {
  227. const profileName = await prompt(browser.i18n.getMessage("profileAddPrompt"));
  228. if (profileName) {
  229. try {
  230. await browser.runtime.sendMessage({ method: "config.createProfile", profileName });
  231. } catch (error) {
  232. // ignored
  233. }
  234. if (sidePanelDisplay) {
  235. await refresh();
  236. } else {
  237. await refresh(profileName);
  238. }
  239. await refreshExternalComponents();
  240. }
  241. }, false);
  242. deleteProfileButton.addEventListener("click", async () => {
  243. if (await confirm(browser.i18n.getMessage("profileDeleteConfirm"))) {
  244. try {
  245. await browser.runtime.sendMessage({ method: "config.deleteProfile", profileName: profileNamesInput.value });
  246. } catch (error) {
  247. // ignored
  248. }
  249. profileNamesInput.value = null;
  250. await refresh();
  251. await refreshExternalComponents();
  252. }
  253. }, false);
  254. renameProfileButton.addEventListener("click", async () => {
  255. const profileName = await prompt(browser.i18n.getMessage("profileRenamePrompt"), profileNamesInput.value);
  256. if (profileName) {
  257. try {
  258. await browser.runtime.sendMessage({ method: "config.renameProfile", profileName: profileNamesInput.value, newProfileName: profileName });
  259. } catch (error) {
  260. // ignored
  261. }
  262. await refresh(profileName);
  263. await refreshExternalComponents();
  264. }
  265. }, false);
  266. resetButton.addEventListener("click", async () => {
  267. const choice = await reset();
  268. if (choice) {
  269. if (choice == "all") {
  270. await browser.runtime.sendMessage({ method: "config.resetProfiles" });
  271. await refresh(DEFAULT_PROFILE_NAME);
  272. await refreshExternalComponents();
  273. }
  274. if (choice == "current") {
  275. await browser.runtime.sendMessage({ method: "config.resetProfile", profileName: profileNamesInput.value });
  276. await refresh();
  277. await refreshExternalComponents();
  278. }
  279. await update();
  280. }
  281. }, false);
  282. exportButton.addEventListener("click", async () => {
  283. await browser.runtime.sendMessage({ method: "config.exportConfig" });
  284. }, false);
  285. importButton.addEventListener("click", () => {
  286. fileInput.onchange = async () => {
  287. if (fileInput.files.length) {
  288. const reader = new FileReader();
  289. reader.readAsText(fileInput.files[0]);
  290. const serializedConfig = await new Promise((resolve, reject) => {
  291. reader.addEventListener("load", () => resolve(reader.result), false);
  292. reader.addEventListener("error", reject, false);
  293. });
  294. const config = JSON.parse(serializedConfig);
  295. await browser.runtime.sendMessage({ method: "config.importConfig", config });
  296. await refresh(DEFAULT_PROFILE_NAME);
  297. await refreshExternalComponents();
  298. fileInput.value = "";
  299. }
  300. };
  301. fileInput.click();
  302. }, false);
  303. autoSaveUnloadInput.addEventListener("click", async () => {
  304. if (!autoSaveLoadInput.checked && !autoSaveUnloadInput.checked) {
  305. autoSaveLoadOrUnloadInput.checked = true;
  306. }
  307. }, false);
  308. autoSaveLoadInput.addEventListener("click", async () => {
  309. if (!autoSaveLoadInput.checked && !autoSaveUnloadInput.checked) {
  310. autoSaveLoadOrUnloadInput.checked = true;
  311. }
  312. }, false);
  313. autoSaveLoadOrUnloadInput.addEventListener("click", async () => {
  314. if (autoSaveLoadOrUnloadInput.checked) {
  315. autoSaveUnloadInput.checked = autoSaveLoadInput.checked = false;
  316. } else {
  317. autoSaveUnloadInput.checked = false;
  318. autoSaveLoadInput.checked = true;
  319. }
  320. }, false);
  321. expandAllButton.addEventListener("click", () => {
  322. if (expandAllButton.className) {
  323. expandAllButton.className = "";
  324. } else {
  325. expandAllButton.className = "opened";
  326. }
  327. document.querySelectorAll("details").forEach(detailElement => detailElement.open = Boolean(expandAllButton.className));
  328. }, false);
  329. removeScriptsInput.addEventListener("click", () => {
  330. if (!removeScriptsInput.checked) {
  331. removeHiddenElementsInput.checked = false;
  332. removeUnusedStylesInput.checked = false;
  333. }
  334. }, false);
  335. document.body.onchange = async event => {
  336. let target = event.target;
  337. if (target != ruleUrlInput && target != ruleProfileInput && target != ruleAutoSaveProfileInput && target != ruleEditUrlInput && target != ruleEditProfileInput && target != ruleEditAutoSaveProfileInput && target != showAutoSaveProfileInput) {
  338. if (target != profileNamesInput && target != showAllProfilesInput) {
  339. await update();
  340. }
  341. if (target == profileNamesInput) {
  342. await refresh(profileNamesInput.value);
  343. if (sidePanelDisplay) {
  344. const tabsData = await browser.runtime.sendMessage({ method: "tabsData.get" });
  345. tabsData.profileName = profileNamesInput.value;
  346. await browser.runtime.sendMessage({ method: "tabsData.set", tabsData: tabsData });
  347. await browser.runtime.sendMessage({ method: "ui.refreshMenu" });
  348. }
  349. } else {
  350. if (target == contextMenuEnabledInput) {
  351. await browser.runtime.sendMessage({ method: "ui.refreshMenu" });
  352. }
  353. await refresh();
  354. }
  355. }
  356. };
  357. addProfileButton.title = browser.i18n.getMessage("profileAddButtonTooltip");
  358. deleteProfileButton.title = browser.i18n.getMessage("profileDeleteButtonTooltip");
  359. renameProfileButton.title = browser.i18n.getMessage("profileRenameButtonTooltip");
  360. removeHiddenElementsLabel.textContent = browser.i18n.getMessage("optionRemoveHiddenElements");
  361. removeUnusedStylesLabel.textContent = browser.i18n.getMessage("optionRemoveUnusedStyles");
  362. removeUnusedFontsLabel.textContent = browser.i18n.getMessage("optionRemoveUnusedFonts");
  363. removeFramesLabel.textContent = browser.i18n.getMessage("optionRemoveFrames");
  364. removeImportsLabel.textContent = browser.i18n.getMessage("optionRemoveImports");
  365. removeScriptsLabel.textContent = browser.i18n.getMessage("optionRemoveScripts");
  366. saveRawPageLabel.textContent = browser.i18n.getMessage("optionSaveRawPage");
  367. saveToClipboardLabel.textContent = browser.i18n.getMessage("optionSaveToClipboard");
  368. compressHTMLLabel.textContent = browser.i18n.getMessage("optionCompressHTML");
  369. compressCSSLabel.textContent = browser.i18n.getMessage("optionCompressCSS");
  370. loadDeferredImagesLabel.textContent = browser.i18n.getMessage("optionLoadDeferredImages");
  371. loadDeferredImagesMaxIdleTimeLabel.textContent = browser.i18n.getMessage("optionLoadDeferredImagesMaxIdleTime");
  372. addMenuEntryLabel.textContent = browser.i18n.getMessage("optionAddMenuEntry");
  373. filenameTemplateLabel.textContent = browser.i18n.getMessage("optionFilenameTemplate");
  374. shadowEnabledLabel.textContent = browser.i18n.getMessage("optionDisplayShadow");
  375. setMaxResourceSizeLabel.textContent = browser.i18n.getMessage("optionSetMaxResourceSize");
  376. maxResourceSizeLabel.textContent = browser.i18n.getMessage("optionMaxResourceSize");
  377. confirmFilenameLabel.textContent = browser.i18n.getMessage("optionConfirmFilename");
  378. filenameConflictActionLabel.textContent = browser.i18n.getMessage("optionFilenameConflictAction");
  379. filenameConflictActionUniquifyLabel.textContent = browser.i18n.getMessage("optionFilenameConflictActionUniquify");
  380. filenameConflictActionOverwriteLabel.textContent = browser.i18n.getMessage("optionFilenameConflictActionOverwrite");
  381. filenameConflictActionPromptLabel.textContent = browser.i18n.getMessage("optionFilenameConflictActionPrompt");
  382. removeAudioLabel.textContent = browser.i18n.getMessage("optionRemoveAudio");
  383. removeVideoLabel.textContent = browser.i18n.getMessage("optionRemoveVideo");
  384. displayInfobarLabel.textContent = browser.i18n.getMessage("optionDisplayInfobar");
  385. displayStatsLabel.textContent = browser.i18n.getMessage("optionDisplayStats");
  386. backgroundSaveLabel.textContent = browser.i18n.getMessage("optionBackgroundSave");
  387. autoSaveDelayLabel.textContent = browser.i18n.getMessage("optionAutoSaveDelay");
  388. autoSaveLoadLabel.textContent = browser.i18n.getMessage("optionAutoSaveLoad");
  389. autoSaveUnloadLabel.textContent = browser.i18n.getMessage("optionAutoSaveUnload");
  390. autoSaveLoadOrUnloadLabel.textContent = browser.i18n.getMessage("optionAutoSaveLoadOrUnload");
  391. autoSaveRepeatLabel.textContent = browser.i18n.getMessage("optionAutoSaveRepeat");
  392. autoSaveRepeatDelayLabel.textContent = browser.i18n.getMessage("optionAutoSaveRepeatDelay");
  393. removeAlternativeFontsLabel.textContent = browser.i18n.getMessage("optionRemoveAlternativeFonts");
  394. removeAlternativeImagesLabel.textContent = browser.i18n.getMessage("optionRemoveAlternativeImages");
  395. removeAlternativeMediasLabel.textContent = browser.i18n.getMessage("optionRemoveAlternativeMedias");
  396. groupDuplicateImagesLabel.textContent = browser.i18n.getMessage("optionGroupDuplicateImages");
  397. titleLabel.textContent = browser.i18n.getMessage("optionsTitle");
  398. userInterfaceLabel.textContent = browser.i18n.getMessage("optionsUserInterfaceSubTitle");
  399. filenameLabel.textContent = browser.i18n.getMessage("optionsFileNameSubTitle");
  400. htmlContentLabel.textContent = browser.i18n.getMessage("optionsHTMLContentSubTitle");
  401. imagesLabel.textContent = browser.i18n.getMessage("optionsImagesSubTitle");
  402. stylesheetsLabel.textContent = browser.i18n.getMessage("optionsStylesheetsSubTitle");
  403. fontsLabel.textContent = browser.i18n.getMessage("optionsFontsSubTitle");
  404. otherResourcesLabel.textContent = browser.i18n.getMessage("optionsOtherResourcesSubTitle");
  405. autoSaveLabel.textContent = browser.i18n.getMessage("optionsAutoSaveSubTitle");
  406. miscLabel.textContent = browser.i18n.getMessage("optionsMiscSubTitle");
  407. helpLabel.textContent = browser.i18n.getMessage("optionsHelpLink");
  408. infobarTemplateLabel.textContent = browser.i18n.getMessage("optionInfobarTemplate");
  409. confirmInfobarLabel.textContent = browser.i18n.getMessage("optionConfirmInfobar");
  410. resetButton.textContent = browser.i18n.getMessage("optionsResetButton");
  411. exportButton.textContent = browser.i18n.getMessage("optionsExportButton");
  412. importButton.textContent = browser.i18n.getMessage("optionsImportButton");
  413. resetButton.title = browser.i18n.getMessage("optionsResetTooltip");
  414. autoSettingsLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsSubTitle");
  415. autoSettingsUrlLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsUrl");
  416. autoSettingsProfileLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsProfile");
  417. autoSettingsAutoSaveProfileLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsAutoSaveProfile");
  418. ruleAddButton.title = browser.i18n.getMessage("optionsAddRuleTooltip");
  419. ruleEditButton.title = browser.i18n.getMessage("optionsValidateChangesTooltip");
  420. rulesDeleteAllButton.title = browser.i18n.getMessage("optionsDeleteRulesTooltip");
  421. showAllProfilesLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsShowAllProfiles");
  422. showAutoSaveProfileLabel.textContent = browser.i18n.getMessage("optionsAutoSettingsShowAutoSaveProfile");
  423. ruleUrlInput.placeholder = ruleEditUrlInput.placeholder = browser.i18n.getMessage("optionsAutoSettingsUrlPlaceholder");
  424. resetAllButton.textContent = browser.i18n.getMessage("optionsResetAllButton");
  425. resetCurrentButton.textContent = browser.i18n.getMessage("optionsResetCurrentButton");
  426. resetCancelButton.textContent = promptCancelButton.textContent = cancelButton.textContent = browser.i18n.getMessage("optionsCancelButton");
  427. confirmButton.textContent = promptConfirmButton.textContent = browser.i18n.getMessage("optionsOKButton");
  428. document.getElementById("resetConfirmLabel").textContent = browser.i18n.getMessage("optionsResetConfirm");
  429. if (location.href.endsWith("#")) {
  430. document.querySelector(".new-window-link").remove();
  431. document.documentElement.classList.add("maximized");
  432. }
  433. if (location.href.endsWith("#side-panel")) {
  434. sidePanelDisplay = true;
  435. document.querySelector(".options-title").remove();
  436. document.documentElement.classList.add("side-panel");
  437. const tabsData = await browser.runtime.sendMessage({ method: "tabsData.get" });
  438. refresh(tabsData.profileName);
  439. } else {
  440. refresh();
  441. }
  442. async function refresh(profileName) {
  443. const [profiles, rules] = await Promise.all([browser.runtime.sendMessage({ method: "config.getProfiles" }), browser.runtime.sendMessage({ method: "config.getRules" })]);
  444. const selectedProfileName = profileName || profileNamesInput.value || DEFAULT_PROFILE_NAME;
  445. Array.from(profileNamesInput.childNodes, node => node.remove());
  446. profileNamesInput.options.length = 0;
  447. ruleProfileInput.options.length = 0;
  448. ruleAutoSaveProfileInput.options.length = 0;
  449. ruleEditProfileInput.options.length = 0;
  450. ruleEditAutoSaveProfileInput.options.length = 0;
  451. let optionElement = document.createElement("option");
  452. optionElement.value = DEFAULT_PROFILE_NAME;
  453. optionElement.textContent = browser.i18n.getMessage("profileDefaultSettings");
  454. [CURRENT_PROFILE_NAME].concat(...Object.keys(profiles)).forEach(profileName => {
  455. const optionElement = document.createElement("option");
  456. optionElement.value = optionElement.textContent = profileName;
  457. if (profileName == DEFAULT_PROFILE_NAME) {
  458. optionElement.textContent = browser.i18n.getMessage("profileDefaultSettings");
  459. }
  460. if (profileName != CURRENT_PROFILE_NAME) {
  461. profileNamesInput.appendChild(optionElement);
  462. }
  463. ruleProfileInput.appendChild(optionElement.cloneNode(true));
  464. ruleAutoSaveProfileInput.appendChild(optionElement.cloneNode(true));
  465. ruleEditProfileInput.appendChild(optionElement.cloneNode(true));
  466. ruleEditAutoSaveProfileInput.appendChild(optionElement.cloneNode(true));
  467. });
  468. profileNamesInput.disabled = profileNamesInput.options.length == 1;
  469. optionElement = document.createElement("option");
  470. optionElement.value = DISABLED_PROFILE_NAME;
  471. optionElement.textContent = browser.i18n.getMessage("profileDisabled");
  472. ruleAutoSaveProfileInput.appendChild(optionElement);
  473. ruleEditAutoSaveProfileInput.appendChild(optionElement.cloneNode(true));
  474. const rulesDataElement = rulesElement.querySelector(".rules-data");
  475. Array.from(rulesDataElement.childNodes, node => (!node.className || !node.className.includes("rule-edit")) && node.remove());
  476. const editURLElement = rulesElement.querySelector(".rule-edit");
  477. createURLElement.hidden = false;
  478. editURLElement.hidden = true;
  479. ruleProfileInput.value = ruleAutoSaveProfileInput.value = selectedProfileName;
  480. let rulesDisplayed;
  481. rules.forEach(rule => {
  482. if (showAllProfilesInput.checked || selectedProfileName == rule.profile || selectedProfileName == rule.autoSaveProfile) {
  483. rulesDisplayed = true;
  484. const ruleElement = rulesElement.querySelector(".rule-view").cloneNode(true);
  485. const ruleUrlElement = ruleElement.querySelector(".rule-url");
  486. const ruleProfileElement = ruleElement.querySelector(".rule-profile");
  487. const ruleAutoSaveProfileElement = ruleElement.querySelector(".rule-autosave-profile");
  488. ruleUrlElement.textContent = ruleUrlElement.title = rule.url;
  489. ruleProfileElement.textContent = ruleProfileElement.title = getProfileText(rule.profile);
  490. ruleAutoSaveProfileElement.textContent = ruleAutoSaveProfileElement.title = getProfileText(rule.autoSaveProfile);
  491. ruleElement.hidden = false;
  492. ruleElement.className = "tr data";
  493. rulesDataElement.appendChild(ruleElement);
  494. const ruleDeleteButton = ruleElement.querySelector(".rule-delete-button");
  495. const ruleUpdateButton = ruleElement.querySelector(".rule-update-button");
  496. ruleDeleteButton.title = browser.i18n.getMessage("optionsDeleteRuleTooltip");
  497. ruleDeleteButton.addEventListener("click", async () => {
  498. if (await confirm(browser.i18n.getMessage("optionsDeleteRuleConfirm"))) {
  499. await browser.runtime.sendMessage({ method: "config.deleteRule", url: rule.url });
  500. await refresh();
  501. await refreshExternalComponents();
  502. }
  503. }, false);
  504. ruleUpdateButton.title = browser.i18n.getMessage("optionsUpdateRuleTooltip");
  505. ruleUpdateButton.addEventListener("click", async () => {
  506. if (editURLElement.hidden) {
  507. createURLElement.hidden = true;
  508. editURLElement.hidden = false;
  509. rulesDataElement.replaceChild(editURLElement, ruleElement);
  510. ruleEditUrlInput.value = rule.url;
  511. ruleEditProfileInput.value = rule.profile;
  512. ruleEditAutoSaveProfileInput.value = rule.autoSaveProfile;
  513. ruleEditUrlInput.focus();
  514. editURLElement.onsubmit = async event => {
  515. event.preventDefault();
  516. rulesElement.appendChild(editURLElement);
  517. await browser.runtime.sendMessage({ method: "config.updateRule", url: rule.url, newUrl: ruleEditUrlInput.value, profileName: ruleEditProfileInput.value, autoSaveProfileName: ruleEditAutoSaveProfileInput.value });
  518. await refresh();
  519. await refreshExternalComponents();
  520. ruleUrlInput.focus();
  521. };
  522. }
  523. }, false);
  524. }
  525. });
  526. rulesDeleteAllButton.disabled = !rulesDisplayed;
  527. rulesElement.appendChild(createURLElement);
  528. profileNamesInput.value = selectedProfileName;
  529. renameProfileButton.disabled = deleteProfileButton.disabled = profileNamesInput.value == DEFAULT_PROFILE_NAME;
  530. const profileOptions = profiles[selectedProfileName];
  531. removeHiddenElementsInput.checked = profileOptions.removeHiddenElements;
  532. removeUnusedStylesInput.checked = profileOptions.removeUnusedStyles;
  533. removeUnusedFontsInput.checked = profileOptions.removeUnusedFonts;
  534. removeFramesInput.checked = profileOptions.removeFrames;
  535. removeImportsInput.checked = profileOptions.removeImports;
  536. removeScriptsInput.checked = profileOptions.removeScripts;
  537. saveRawPageInput.checked = profileOptions.saveRawPage;
  538. saveToClipboardInput.checked = profileOptions.saveToClipboard;
  539. compressHTMLInput.checked = profileOptions.compressHTML;
  540. compressCSSInput.checked = profileOptions.compressCSS;
  541. loadDeferredImagesInput.checked = profileOptions.loadDeferredImages;
  542. loadDeferredImagesMaxIdleTimeInput.value = profileOptions.loadDeferredImagesMaxIdleTime;
  543. loadDeferredImagesMaxIdleTimeInput.disabled = !profileOptions.loadDeferredImages || profileOptions.saveRawPage;
  544. contextMenuEnabledInput.checked = profileOptions.contextMenuEnabled;
  545. filenameTemplateInput.value = profileOptions.filenameTemplate;
  546. filenameTemplateInput.disabled = profileOptions.saveToClipboard;
  547. shadowEnabledInput.checked = profileOptions.shadowEnabled;
  548. maxResourceSizeEnabledInput.checked = profileOptions.maxResourceSizeEnabled;
  549. maxResourceSizeInput.value = profileOptions.maxResourceSize;
  550. maxResourceSizeInput.disabled = !profileOptions.maxResourceSizeEnabled;
  551. confirmFilenameInput.checked = profileOptions.confirmFilename;
  552. confirmFilenameInput.disabled = profileOptions.saveToClipboard;
  553. filenameConflictActionInput.value = profileOptions.filenameConflictAction;
  554. filenameConflictActionInput.disabled = profileOptions.saveToClipboard;
  555. removeAudioSrcInput.checked = profileOptions.removeAudioSrc;
  556. removeVideoSrcInput.checked = profileOptions.removeVideoSrc;
  557. displayInfobarInput.checked = profileOptions.displayInfobar;
  558. displayStatsInput.checked = profileOptions.displayStats;
  559. backgroundSaveInput.checked = profileOptions.backgroundSave;
  560. autoSaveDelayInput.value = profileOptions.autoSaveDelay;
  561. autoSaveDelayInput.disabled = !profileOptions.autoSaveLoadOrUnload && !profileOptions.autoSaveLoad;
  562. autoSaveLoadInput.checked = !profileOptions.autoSaveLoadOrUnload && profileOptions.autoSaveLoad;
  563. autoSaveLoadOrUnloadInput.checked = profileOptions.autoSaveLoadOrUnload;
  564. autoSaveUnloadInput.checked = !profileOptions.autoSaveLoadOrUnload && profileOptions.autoSaveUnload;
  565. autoSaveLoadInput.disabled = profileOptions.autoSaveLoadOrUnload;
  566. autoSaveUnloadInput.disabled = profileOptions.autoSaveLoadOrUnload;
  567. autoSaveRepeatInput.checked = profileOptions.autoSaveRepeat;
  568. autoSaveRepeatInput.disabled = !profileOptions.autoSaveLoadOrUnload && !profileOptions.autoSaveLoad;
  569. autoSaveRepeatDelayInput.value = profileOptions.autoSaveRepeatDelay;
  570. autoSaveRepeatDelayInput.disabled = !profileOptions.autoSaveRepeat;
  571. removeAlternativeFontsInput.checked = profileOptions.removeAlternativeFonts;
  572. removeAlternativeImagesInput.checked = profileOptions.removeAlternativeImages;
  573. groupDuplicateImagesInput.checked = profileOptions.groupDuplicateImages;
  574. removeAlternativeMediasInput.checked = profileOptions.removeAlternativeMedias;
  575. infobarTemplateInput.value = profileOptions.infobarTemplate;
  576. confirmInfobarInput.checked = profileOptions.confirmInfobarContent;
  577. removeFramesInput.disabled = saveRawPageInput.checked;
  578. removeFramesInput.checked = removeFramesInput.checked || saveRawPageInput.checked;
  579. loadDeferredImagesInput.disabled = saveRawPageInput.checked;
  580. if (saveRawPageInput.checked) {
  581. loadDeferredImagesInput.checked = false;
  582. }
  583. }
  584. function getProfileText(profileName) {
  585. return profileName == DEFAULT_PROFILE_NAME ? browser.i18n.getMessage("profileDefaultSettings") : profileName == DISABLED_PROFILE_NAME ? browser.i18n.getMessage("profileDisabled") : profileName;
  586. }
  587. async function update() {
  588. await pendingSave;
  589. pendingSave = browser.runtime.sendMessage({
  590. method: "config.updateProfile",
  591. profileName: profileNamesInput.value,
  592. profile: {
  593. removeHiddenElements: removeHiddenElementsInput.checked,
  594. removeUnusedStyles: removeUnusedStylesInput.checked,
  595. removeUnusedFonts: removeUnusedFontsInput.checked,
  596. removeFrames: removeFramesInput.checked,
  597. removeImports: removeImportsInput.checked,
  598. removeScripts: removeScriptsInput.checked,
  599. saveRawPage: saveRawPageInput.checked,
  600. saveToClipboard: saveToClipboardInput.checked,
  601. compressHTML: compressHTMLInput.checked,
  602. compressCSS: compressCSSInput.checked,
  603. loadDeferredImages: loadDeferredImagesInput.checked,
  604. loadDeferredImagesMaxIdleTime: Math.max(loadDeferredImagesMaxIdleTimeInput.value, 0),
  605. contextMenuEnabled: contextMenuEnabledInput.checked,
  606. filenameTemplate: filenameTemplateInput.value,
  607. shadowEnabled: shadowEnabledInput.checked,
  608. maxResourceSizeEnabled: maxResourceSizeEnabledInput.checked,
  609. maxResourceSize: Math.max(maxResourceSizeInput.value, 0),
  610. confirmFilename: confirmFilenameInput.checked,
  611. filenameConflictAction: filenameConflictActionInput.value,
  612. removeAudioSrc: removeAudioSrcInput.checked,
  613. removeVideoSrc: removeVideoSrcInput.checked,
  614. displayInfobar: displayInfobarInput.checked,
  615. displayStats: displayStatsInput.checked,
  616. backgroundSave: backgroundSaveInput.checked,
  617. autoSaveDelay: Math.max(autoSaveDelayInput.value, 0),
  618. autoSaveLoad: autoSaveLoadInput.checked,
  619. autoSaveUnload: autoSaveUnloadInput.checked,
  620. autoSaveLoadOrUnload: autoSaveLoadOrUnloadInput.checked,
  621. autoSaveRepeat: autoSaveRepeatInput.checked,
  622. autoSaveRepeatDelay: Math.max(autoSaveRepeatDelayInput.value, 1),
  623. removeAlternativeFonts: removeAlternativeFontsInput.checked,
  624. removeAlternativeImages: removeAlternativeImagesInput.checked,
  625. removeAlternativeMedias: removeAlternativeMediasInput.checked,
  626. groupDuplicateImages: groupDuplicateImagesInput.checked,
  627. infobarTemplate: infobarTemplateInput.value,
  628. confirmInfobarContent: confirmInfobarInput.checked
  629. }
  630. });
  631. await pendingSave;
  632. }
  633. async function refreshExternalComponents() {
  634. try {
  635. await browser.runtime.sendMessage({ method: "ui.refreshMenu" });
  636. if (sidePanelDisplay) {
  637. await browser.runtime.sendMessage({ method: "options.refresh", profileName: profileNamesInput.value });
  638. } else {
  639. await browser.runtime.sendMessage({ method: "options.refreshPanel", profileName: profileNamesInput.value });
  640. }
  641. } catch (error) {
  642. // ignored
  643. }
  644. }
  645. async function confirm(message) {
  646. document.getElementById("confirmLabel").textContent = message;
  647. document.getElementById("formConfirmContainer").hidden = false;
  648. confirmButton.focus();
  649. document.body.style.setProperty("overflow-y", "hidden");
  650. return new Promise(resolve => {
  651. confirmButton.onclick = event => hideAndResolve(event, true);
  652. cancelButton.onclick = event => hideAndResolve(event);
  653. window.onkeyup = event => {
  654. if (event.key == "Escape") {
  655. hideAndResolve(event);
  656. }
  657. };
  658. function hideAndResolve(event, value) {
  659. event.preventDefault();
  660. document.getElementById("formConfirmContainer").hidden = true;
  661. document.body.style.setProperty("overflow-y", "");
  662. resolve(value);
  663. }
  664. });
  665. }
  666. async function reset() {
  667. document.getElementById("formResetContainer").hidden = false;
  668. resetCancelButton.focus();
  669. document.body.style.setProperty("overflow-y", "hidden");
  670. return new Promise(resolve => {
  671. resetAllButton.onclick = event => hideAndResolve(event, "all");
  672. resetCurrentButton.onclick = event => hideAndResolve(event, "current");
  673. resetCancelButton.onclick = event => hideAndResolve(event);
  674. window.onkeyup = event => {
  675. if (event.key == "Escape") {
  676. hideAndResolve(event);
  677. }
  678. };
  679. function hideAndResolve(event, value) {
  680. event.preventDefault();
  681. document.getElementById("formResetContainer").hidden = true;
  682. document.body.style.setProperty("overflow-y", "");
  683. resolve(value);
  684. }
  685. });
  686. }
  687. async function prompt(message, defaultValue = "") {
  688. document.getElementById("promptLabel").textContent = message;
  689. document.getElementById("formPromptContainer").hidden = false;
  690. promptInput.value = defaultValue;
  691. promptInput.focus();
  692. document.body.style.setProperty("overflow-y", "hidden");
  693. return new Promise(resolve => {
  694. promptConfirmButton.onclick = event => hideAndResolve(event, promptInput.value);
  695. promptCancelButton.onclick = event => hideAndResolve(event);
  696. window.onkeyup = event => {
  697. if (event.key == "Escape") {
  698. hideAndResolve(event);
  699. }
  700. };
  701. function hideAndResolve(event, value) {
  702. event.preventDefault();
  703. document.getElementById("formPromptContainer").hidden = true;
  704. document.body.style.setProperty("overflow-y", "");
  705. resolve(value);
  706. }
  707. });
  708. }
  709. async function getHelpContents() {
  710. const helpPage = await fetch(browser.runtime.getURL(HELP_PAGE_PATH));
  711. const content = new TextDecoder().decode(await helpPage.arrayBuffer());
  712. const doc = (new DOMParser()).parseFromString(content, "text/html");
  713. const items = doc.querySelectorAll("[data-options-label]");
  714. items.forEach(itemElement => {
  715. const optionLabel = document.getElementById(itemElement.dataset.optionsLabel);
  716. const helpIcon = document.createElement("img");
  717. helpIcon.className = "help-icon";
  718. helpIcon.src = HELP_ICON_URL;
  719. helpIcon.onclick = () => {
  720. helpContent.hidden = !helpContent.hidden;
  721. return false;
  722. };
  723. helpIcon.tabIndex = 0;
  724. helpIcon.onkeyup = event => {
  725. if (event.code == "Enter") {
  726. helpContent.hidden = !helpContent.hidden;
  727. return false;
  728. }
  729. };
  730. optionLabel.appendChild(helpIcon);
  731. const helpContent = document.createElement("div");
  732. helpContent.hidden = true;
  733. helpContent.className = "help-content";
  734. itemElement.childNodes.forEach(node => {
  735. if (node instanceof HTMLElement && node.className != "option") {
  736. helpContent.appendChild(document.importNode(node, true));
  737. }
  738. });
  739. helpContent.querySelectorAll("a[href]").forEach(linkElement => {
  740. const hrefValue = linkElement.getAttribute("href");
  741. if (hrefValue.startsWith("#")) {
  742. linkElement.href = browser.runtime.getURL(HELP_PAGE_PATH + linkElement.getAttribute("href"));
  743. linkElement.target = "_blank";
  744. }
  745. });
  746. optionLabel.parentElement.insertAdjacentElement("afterEnd", helpContent);
  747. });
  748. }
  749. function getLocalStorageItem(key) {
  750. try {
  751. return localStorage.getItem(key);
  752. } catch (error) {
  753. // ignored
  754. }
  755. }
  756. function setLocalStorageItem(key, value) {
  757. try {
  758. return localStorage.setItem(key, value);
  759. } catch (error) {
  760. // ignored
  761. }
  762. }
  763. function removeLocalStorageItem(key) {
  764. try {
  765. return localStorage.removeItem(key);
  766. } catch (error) {
  767. // ignored
  768. }
  769. }
  770. })();