about summary refs log tree commit diff stats
path: root/src/pages/options/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/options/widgets')
-rw-r--r--src/pages/options/widgets/general.js276
1 files changed, 138 insertions, 138 deletions
diff --git a/src/pages/options/widgets/general.js b/src/pages/options/widgets/general.js
index 30a8a0c8..b9ddfd08 100644
--- a/src/pages/options/widgets/general.js
+++ b/src/pages/options/widgets/general.js
@@ -7,29 +7,29 @@ import servicesHelper from "../../../assets/javascripts/services.js"
 const isChrome = browser.runtime.getBrowserInfo === undefined
 
 async function setOption(option, type, event) {
-	let options = await utils.getOptions()
-	switch (type) {
-		case "select":
-			options[option] = event.target.options[event.target.options.selectedIndex].value
-			break;
-		case "checkbox":
-			options[option] = event.target.checked
-			break;
-		case "range":
-			options[option] = event.target.value
-			break;
-	}
-	browser.storage.local.set({ options })
+  let options = await utils.getOptions()
+  switch (type) {
+    case "select":
+      options[option] = event.target.options[event.target.options.selectedIndex].value
+      break
+    case "checkbox":
+      options[option] = event.target.checked
+      break
+    case "range":
+      options[option] = event.target.value
+      break
+  }
+  browser.storage.local.set({ options })
 }
 
 const exportSettingsElement = document.getElementById("export-settings")
 async function exportSettings() {
-	const options = await utils.getOptions()
-	options.version = browser.runtime.getManifest().version
-	let resultString = JSON.stringify(options, null, "  ")
-	exportSettingsElement.href = "data:application/json;base64," + btoa(resultString)
-	exportSettingsElement.download = `libredirect-settings-v${options.version}.json`
-	return
+  const options = await utils.getOptions()
+  options.version = browser.runtime.getManifest().version
+  let resultString = JSON.stringify(options, null, "  ")
+  exportSettingsElement.href = "data:application/json;base64," + btoa(resultString)
+  exportSettingsElement.download = `libredirect-settings-v${options.version}.json`
+  return
 }
 exportSettings()
 document.getElementById("general_page").onclick = exportSettings
@@ -37,35 +37,32 @@ document.getElementById("general_page").onclick = exportSettings
 const importSettingsElement = document.getElementById("import-settings")
 const importSettingsElementText = document.getElementById("import_settings_text")
 importSettingsElement.addEventListener("change", () => {
-	function importError() {
-		const oldHTML = importSettingsElementText.innerHTML
-		importSettingsElementText.innerHTML = '<span style="color:red;">Error!</span>'
-		setTimeout(() => (importSettingsElementText.innerHTML = oldHTML), 1000)
-	}
-	importSettingsElementText.innerHTML = "..."
-	let file = importSettingsElement.files[0]
-	const reader = new FileReader()
-	reader.readAsText(file)
-	reader.onload = async () => {
-		const data = JSON.parse(reader.result)
-		if (
-			"theme" in data
-			&& data.version == browser.runtime.getManifest().version
-		) {
-			browser.storage.local.clear(async () => {
-				browser.storage.local.set({ options: data }, () => {
-					location.reload()
-				})
-			})
-		} else {
-			console.log("incompatible settings")
-			importError()
-		}
-	}
-	reader.onerror = error => {
-		console.log("error", error)
-		importError()
-	}
+  function importError() {
+    const oldHTML = importSettingsElementText.innerHTML
+    importSettingsElementText.innerHTML = '<span style="color:red;">Error!</span>'
+    setTimeout(() => (importSettingsElementText.innerHTML = oldHTML), 1000)
+  }
+  importSettingsElementText.innerHTML = "..."
+  let file = importSettingsElement.files[0]
+  const reader = new FileReader()
+  reader.readAsText(file)
+  reader.onload = async () => {
+    const data = JSON.parse(reader.result)
+    if ("theme" in data && data.version == browser.runtime.getManifest().version) {
+      browser.storage.local.clear(async () => {
+        browser.storage.local.set({ options: data }, () => {
+          location.reload()
+        })
+      })
+    } else {
+      console.log("incompatible settings")
+      importError()
+    }
+  }
+  reader.onerror = error => {
+    console.log("error", error)
+    importError()
+  }
 })
 
 const exportSettingsSync = document.getElementById("export-settings-sync")
@@ -73,58 +70,57 @@ const importSettingsSync = document.getElementById("import-settings-sync")
 const importSettingsSyncText = document.getElementById("import_settings_sync_text")
 
 exportSettingsSync.addEventListener("click", async () => {
-	let options = await utils.getOptions()
-	options.version = browser.runtime.getManifest().version
-	browser.storage.sync.set({ options }, () => location.reload())
+  let options = await utils.getOptions()
+  options.version = browser.runtime.getManifest().version
+  browser.storage.sync.set({ options }, () => location.reload())
 })
 
 importSettingsSync.addEventListener("click", () => {
-	function importError() {
-		importSettingsSyncText.innerHTML = '<span style="color:red;">Error!</span>'
-		setTimeout(() => (importSettingsSyncText.innerHTML = oldHTML), 1000)
-	}
-	const oldHTML = importSettingsSyncText.innerHTML
-	importSettingsSyncText.innerHTML = "..."
-	browser.storage.sync.get({ options }, r => {
-		const options = r.options
-		if (options.version == browser.runtime.getManifest().version) {
-			browser.storage.local.set({ options }, () => location.reload())
-		} else {
-			importError()
-		}
-	})
+  function importError() {
+    importSettingsSyncText.innerHTML = '<span style="color:red;">Error!</span>'
+    setTimeout(() => (importSettingsSyncText.innerHTML = oldHTML), 1000)
+  }
+  const oldHTML = importSettingsSyncText.innerHTML
+  importSettingsSyncText.innerHTML = "..."
+  browser.storage.sync.get({ options }, r => {
+    const options = r.options
+    if (options.version == browser.runtime.getManifest().version) {
+      browser.storage.local.set({ options }, () => location.reload())
+    } else {
+      importError()
+    }
+  })
 })
 
 const resetSettings = document.getElementById("reset-settings")
 resetSettings.addEventListener("click", async () => {
-	resetSettings.innerHTML = "..."
-	await servicesHelper.initDefaults()
-	location.reload()
+  resetSettings.innerHTML = "..."
+  await servicesHelper.initDefaults()
+  location.reload()
 })
 
-const fetchInstancesElement = document.getElementById('fetch-instances')
-fetchInstancesElement.addEventListener('change', event => {
-	setOption('fetchInstances', 'select', event)
-	location.reload()
+const fetchInstancesElement = document.getElementById("fetch-instances")
+fetchInstancesElement.addEventListener("change", event => {
+  setOption("fetchInstances", "select", event)
+  location.reload()
 })
 
-const redirectOnlyInIncognitoElement = document.getElementById('redirectOnlyInIncognito')
-redirectOnlyInIncognitoElement.addEventListener('change', event => {
-	setOption('redirectOnlyInIncognito', 'checkbox', event)
+const redirectOnlyInIncognitoElement = document.getElementById("redirectOnlyInIncognito")
+redirectOnlyInIncognitoElement.addEventListener("change", event => {
+  setOption("redirectOnlyInIncognito", "checkbox", event)
 })
 
-const bookmarksMenuElement = document.getElementById('bookmarksMenu')
-bookmarksMenuElement.addEventListener('change', async event => {
-	if (event.target.checked)
-		browser.permissions.request({ permissions: ["bookmarks"] }, r => bookmarksMenuElement.checked = r)
-	else
-		browser.permissions.remove({ permissions: ["bookmarks"] }, r => bookmarksMenuElement.checked = !r)
+const bookmarksMenuElement = document.getElementById("bookmarksMenu")
+bookmarksMenuElement.addEventListener("change", async event => {
+  if (event.target.checked)
+    browser.permissions.request({ permissions: ["bookmarks"] }, r => (bookmarksMenuElement.checked = r))
+  else browser.permissions.remove({ permissions: ["bookmarks"] }, r => (bookmarksMenuElement.checked = !r))
 })
 
 let themeElement = document.getElementById("theme")
 themeElement.addEventListener("change", event => {
-	setOption("theme", "select", event)
-	location.reload()
+  setOption("theme", "select", event)
+  location.reload()
 })
 
 let nameCustomInstanceInput = document.getElementById("exceptions-custom-instance")
@@ -134,40 +130,44 @@ let instanceType = "url"
 let config = await utils.getConfig()
 
 for (const service in config.services) {
-	document.getElementById(service).addEventListener("change", async event => {
-		let options = await utils.getOptions()
-		if (event.target.checked && !options.popupServices.includes(service)) options.popupServices.push(service)
-		else if (options.popupServices.includes(service)) {
-			var index = options.popupServices.indexOf(service)
-			if (index !== -1) options.popupServices.splice(index, 1)
-		}
-		browser.storage.local.set({ options })
-	})
+  document.getElementById(service).addEventListener("change", async event => {
+    let options = await utils.getOptions()
+    if (event.target.checked && !options.popupServices.includes(service)) options.popupServices.push(service)
+    else if (options.popupServices.includes(service)) {
+      var index = options.popupServices.indexOf(service)
+      if (index !== -1) options.popupServices.splice(index, 1)
+    }
+    browser.storage.local.set({ options })
+  })
 }
 
 let options = await utils.getOptions()
 themeElement.value = options.theme
 fetchInstancesElement.value = options.fetchInstances
 redirectOnlyInIncognitoElement.checked = options.redirectOnlyInIncognito
-browser.permissions.contains({ permissions: ["bookmarks"] }, r => bookmarksMenuElement.checked = r)
-for (const service in config.services) document.getElementById(service).checked = options.popupServices.includes(service)
+browser.permissions.contains({ permissions: ["bookmarks"] }, r => (bookmarksMenuElement.checked = r))
+for (const service in config.services)
+  document.getElementById(service).checked = options.popupServices.includes(service)
 
 instanceTypeElement.addEventListener("change", event => {
-	instanceType = event.target.options[instanceTypeElement.selectedIndex].value
-	if (instanceType == "url") {
-		nameCustomInstanceInput.setAttribute("type", "url")
-		nameCustomInstanceInput.setAttribute("placeholder", "https://www.google.com")
-	} else if (instanceType == "regex") {
-		nameCustomInstanceInput.setAttribute("type", "text")
-		nameCustomInstanceInput.setAttribute("placeholder", "https?://(www.|)youtube.com/")
-	}
+  instanceType = event.target.options[instanceTypeElement.selectedIndex].value
+  if (instanceType == "url") {
+    nameCustomInstanceInput.setAttribute("type", "url")
+    nameCustomInstanceInput.setAttribute("placeholder", "https://www.google.com")
+  } else if (instanceType == "regex") {
+    nameCustomInstanceInput.setAttribute("type", "text")
+    nameCustomInstanceInput.setAttribute("placeholder", "https?://(www.|)youtube.com/")
+  }
 })
 
 let exceptionsCustomInstances = options.exceptions
 function calcExceptionsCustomInstances() {
-	document.getElementById("exceptions-custom-checklist").innerHTML = [...exceptionsCustomInstances.url, ...exceptionsCustomInstances.regex]
-		.map(
-			x => `<div>
+  document.getElementById("exceptions-custom-checklist").innerHTML = [
+    ...exceptionsCustomInstances.url,
+    ...exceptionsCustomInstances.regex,
+  ]
+    .map(
+      x => `<div>
                       ${x}
                       <button class="add" id="clear-${x}">
                         <svg xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
@@ -177,40 +177,40 @@ function calcExceptionsCustomInstances() {
                       </button>
                     </div>
                     <hr>`
-		)
-		.join("\n")
-
-	for (const x of [...exceptionsCustomInstances.url, ...exceptionsCustomInstances.regex]) {
-		document.getElementById(`clear-${x}`).addEventListener("click", async () => {
-			let index
-			index = exceptionsCustomInstances.url.indexOf(x)
-			if (index > -1) exceptionsCustomInstances.url.splice(index, 1)
-			else {
-				index = exceptionsCustomInstances.regex.indexOf(x)
-				if (index > -1) exceptionsCustomInstances.regex.splice(index, 1)
-			}
-			options = await utils.getOptions()
-			options.exceptions = exceptionsCustomInstances
-			browser.storage.local.set({ options })
-			calcExceptionsCustomInstances()
-		})
-	}
+    )
+    .join("\n")
+
+  for (const x of [...exceptionsCustomInstances.url, ...exceptionsCustomInstances.regex]) {
+    document.getElementById(`clear-${x}`).addEventListener("click", async () => {
+      let index
+      index = exceptionsCustomInstances.url.indexOf(x)
+      if (index > -1) exceptionsCustomInstances.url.splice(index, 1)
+      else {
+        index = exceptionsCustomInstances.regex.indexOf(x)
+        if (index > -1) exceptionsCustomInstances.regex.splice(index, 1)
+      }
+      options = await utils.getOptions()
+      options.exceptions = exceptionsCustomInstances
+      browser.storage.local.set({ options })
+      calcExceptionsCustomInstances()
+    })
+  }
 }
 calcExceptionsCustomInstances()
 document.getElementById("custom-exceptions-instance-form").addEventListener("submit", async event => {
-	event.preventDefault()
-	let val
-	if (instanceType == "url" && nameCustomInstanceInput.validity.valid) {
-		val = nameCustomInstanceInput.value
-		if (!exceptionsCustomInstances.url.includes(val)) exceptionsCustomInstances.url.push(val)
-	} else if (instanceType == "regex") {
-		val = nameCustomInstanceInput.value
-		if (val.trim() != "" && !exceptionsCustomInstances.regex.includes(val)) exceptionsCustomInstances.regex.push(val)
-	}
-	if (val) {
-		options = await utils.getOptions()
-		options.exceptions = exceptionsCustomInstances
-		browser.storage.local.set({ options }, () => nameCustomInstanceInput.value = "")
-	}
-	calcExceptionsCustomInstances()
+  event.preventDefault()
+  let val
+  if (instanceType == "url" && nameCustomInstanceInput.validity.valid) {
+    val = nameCustomInstanceInput.value
+    if (!exceptionsCustomInstances.url.includes(val)) exceptionsCustomInstances.url.push(val)
+  } else if (instanceType == "regex") {
+    val = nameCustomInstanceInput.value
+    if (val.trim() != "" && !exceptionsCustomInstances.regex.includes(val)) exceptionsCustomInstances.regex.push(val)
+  }
+  if (val) {
+    options = await utils.getOptions()
+    options.exceptions = exceptionsCustomInstances
+    browser.storage.local.set({ options }, () => (nameCustomInstanceInput.value = ""))
+  }
+  calcExceptionsCustomInstances()
 })