about summary refs log tree commit diff stats
path: root/src/assets/javascripts
diff options
context:
space:
mode:
authorManeraKai <manerakai@protonmail.com>2023-11-15 15:19:01 +0300
committerGitHub <noreply@github.com>2023-11-15 15:19:01 +0300
commitcac79c6959be5abeb77ffbce06205c4b74b8716d (patch)
treec3ad5f58f5b8fb4443077dbfd7ea1cdabfd6a5c1 /src/assets/javascripts
parentFixed AnonymousOverflow redirection bug https://codeberg.org/LibRedirect/brow... (diff)
parentAdd jsdoc types for some functions (diff)
downloadlibredirect-cac79c6959be5abeb77ffbce06205c4b74b8716d.zip
Merge pull request #852 from Davilarek/patch-2
Add jsdoc types for some functions
Diffstat (limited to 'src/assets/javascripts')
-rw-r--r--src/assets/javascripts/localise.js3
-rw-r--r--src/assets/javascripts/services.js37
-rw-r--r--src/assets/javascripts/utils.js45
3 files changed, 85 insertions, 0 deletions
diff --git a/src/assets/javascripts/localise.js b/src/assets/javascripts/localise.js
index 34ccd66b..c0936873 100644
--- a/src/assets/javascripts/localise.js
+++ b/src/assets/javascripts/localise.js
@@ -1,6 +1,9 @@
 window.browser = window.browser || window.chrome
 
 function localisePage() {
+	/**
+	 * @param {string} tag
+	 */
 	function getMessage(tag) {
 		return tag.replace(/__MSG_(\w+)__/g, (_match, v1) => {
 			return v1 ? browser.i18n.getMessage(v1) : null
diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js
index 1a1afa14..7f00b7cf 100644
--- a/src/assets/javascripts/services.js
+++ b/src/assets/javascripts/services.js
@@ -30,6 +30,12 @@ function all(service, frontend, options, config) {
 	return instances
 }
 
+/**
+ * @param {string} service
+ * @param {URL} url
+ * @param {{}} config
+ * @param {string} frontend
+ */
 function regexArray(service, url, config, frontend) {
 	let targetList = config.services[service].targets
 	if (frontend && 'excludeTargets' in config.services[service].frontends[frontend]) {
@@ -44,11 +50,24 @@ function regexArray(service, url, config, frontend) {
 	return false
 }
 
+/**
+ * @param {URL} url
+ * @param {string} type
+ * @param {URL} initiator
+ * @param {boolean} forceRedirection
+ */
 async function redirectAsync(url, type, initiator, forceRedirection) {
 	await init()
 	return redirect(url, type, initiator, forceRedirection)
 }
 
+/**
+ * @param {URL} url
+ * @param {string} type
+ * @param {URL} initiator
+ * @param {boolean} forceRedirection
+ * @returns {string | undefined}
+ */
 function redirect(url, type, initiator, forceRedirection) {
 	if (type != "main_frame" && type != "sub_frame" && type != "image") return
 	let randomInstance
@@ -545,6 +564,10 @@ function redirect(url, type, initiator, forceRedirection) {
 	}
 }
 
+/**
+ * @param {URL} url
+ * @param {*} returnFrontend
+ */
 function computeService(url, returnFrontend) {
 	return new Promise(async resolve => {
 		const config = await utils.getConfig()
@@ -569,6 +592,10 @@ function computeService(url, returnFrontend) {
 	})
 }
 
+/**
+ * @param {URL} url
+ * @param {string} customService
+ */
 function switchInstance(url, customService) {
 	return new Promise(async resolve => {
 		let options = await utils.getOptions()
@@ -599,6 +626,9 @@ function switchInstance(url, customService) {
 	})
 }
 
+/**
+ * @param {URL} url
+ */
 async function reverse(url) {
 	let options = await utils.getOptions()
 	let config = await utils.getConfig()
@@ -774,6 +804,10 @@ function processUpdate() {
 	})
 }
 
+/**
+ * @param {URL} url
+ * @param {boolean} test
+ */
 async function copyRaw(url, test) {
 	const newUrl = await reverse(url)
 	if (newUrl) {
@@ -794,6 +828,9 @@ async function copyRaw(url, test) {
 	}
 }
 
+/**
+ * @param {URL} url
+ */
 function isException(url) {
 	if (!options.exceptions) return false
 	let exceptions = options.exceptions
diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js
index e85b1115..f7b9fd73 100644
--- a/src/assets/javascripts/utils.js
+++ b/src/assets/javascripts/utils.js
@@ -1,18 +1,49 @@
 window.browser = window.browser || window.chrome
 
+/**
+ * @param {Array.<T>} instances 
+ * @returns {T}
+ */
 function getRandomInstance(instances) {
 	return instances[~~(instances.length * Math.random())]
 }
 
+/**
+ * @param {string} str
+ */
 function camelCase(str) {
 	return str.charAt(0).toUpperCase() + str.slice(1)
 }
 
+/**
+ * @param {URL} url
+ */
 function protocolHost(url) {
 	if (url.username && url.password) return `${url.protocol}//${url.username}:${url.password}@${url.host}`
 	return `${url.protocol}//${url.host}`
 }
 
+/**
+ * @typedef FrontendInfo
+ * @prop {boolean} instanceList
+ * @prop {string} name
+ * @prop {string} url
+ */
+
+/**
+ * @typedef {Object} Service
+ * @prop {Object.<string, FrontendInfo>} frontends
+ * @prop {Object} options
+ */
+
+/**
+ * @typedef {Object} Config
+ * @prop {Object.<string, Service>} services
+ */
+
+/**
+ * @returns {Promise<Config>}
+ */
 function getConfig() {
 	return new Promise(resolve => {
 		fetch("/config.json")
@@ -24,6 +55,14 @@ function getConfig() {
 	})
 }
 
+/**
+ * @typedef {Object} Option
+ * @prop {string} frontend
+ */
+
+/**
+ * @returns {Promise<Object.<string, Option | string[]>>}
+ */
 function getOptions() {
 	return new Promise(resolve =>
 		browser.storage.local.get("options", r => {
@@ -106,6 +145,9 @@ function getList(options) {
 	})
 }
 
+/**
+ * @param {string} href
+ */
 function pingOnce(href) {
 	return new Promise(async resolve => {
 		let started
@@ -130,6 +172,9 @@ function pingOnce(href) {
 	})
 }
 
+/**
+ * @param {string} href
+ */
 function ping(href) {
 	return new Promise(async resolve => {
 		let average = 0