Add jsdoc types for some functions
For VSCode completion
This commit is contained in:
parent
62d10a2d0c
commit
57c978b648
@ -1,6 +1,9 @@
|
|||||||
window.browser = window.browser || window.chrome
|
window.browser = window.browser || window.chrome
|
||||||
|
|
||||||
function localisePage() {
|
function localisePage() {
|
||||||
|
/**
|
||||||
|
* @param {string} tag
|
||||||
|
*/
|
||||||
function getMessage(tag) {
|
function getMessage(tag) {
|
||||||
return tag.replace(/__MSG_(\w+)__/g, (_match, v1) => {
|
return tag.replace(/__MSG_(\w+)__/g, (_match, v1) => {
|
||||||
return v1 ? browser.i18n.getMessage(v1) : null
|
return v1 ? browser.i18n.getMessage(v1) : null
|
||||||
|
@ -30,6 +30,12 @@ function all(service, frontend, options, config) {
|
|||||||
return instances
|
return instances
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} service
|
||||||
|
* @param {URL} url
|
||||||
|
* @param {{}} config
|
||||||
|
* @param {string} frontend
|
||||||
|
*/
|
||||||
function regexArray(service, url, config, frontend) {
|
function regexArray(service, url, config, frontend) {
|
||||||
let targetList = config.services[service].targets
|
let targetList = config.services[service].targets
|
||||||
if (frontend && 'excludeTargets' in config.services[service].frontends[frontend]) {
|
if (frontend && 'excludeTargets' in config.services[service].frontends[frontend]) {
|
||||||
@ -44,11 +50,24 @@ function regexArray(service, url, config, frontend) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {URL} url
|
||||||
|
* @param {string} type
|
||||||
|
* @param {URL} initiator
|
||||||
|
* @param {boolean} forceRedirection
|
||||||
|
*/
|
||||||
async function redirectAsync(url, type, initiator, forceRedirection) {
|
async function redirectAsync(url, type, initiator, forceRedirection) {
|
||||||
await init()
|
await init()
|
||||||
return redirect(url, type, initiator, forceRedirection)
|
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) {
|
function redirect(url, type, initiator, forceRedirection) {
|
||||||
if (type != "main_frame" && type != "sub_frame" && type != "image") return
|
if (type != "main_frame" && type != "sub_frame" && type != "image") return
|
||||||
let randomInstance
|
let randomInstance
|
||||||
@ -545,6 +564,10 @@ function redirect(url, type, initiator, forceRedirection) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {URL} url
|
||||||
|
* @param {*} returnFrontend
|
||||||
|
*/
|
||||||
function computeService(url, returnFrontend) {
|
function computeService(url, returnFrontend) {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
const config = await utils.getConfig()
|
const config = await utils.getConfig()
|
||||||
@ -569,6 +592,10 @@ function computeService(url, returnFrontend) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {URL} url
|
||||||
|
* @param {string} customService
|
||||||
|
*/
|
||||||
function switchInstance(url, customService) {
|
function switchInstance(url, customService) {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
let options = await utils.getOptions()
|
let options = await utils.getOptions()
|
||||||
@ -599,6 +626,9 @@ function switchInstance(url, customService) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {URL} url
|
||||||
|
*/
|
||||||
async function reverse(url) {
|
async function reverse(url) {
|
||||||
let options = await utils.getOptions()
|
let options = await utils.getOptions()
|
||||||
let config = await utils.getConfig()
|
let config = await utils.getConfig()
|
||||||
@ -774,6 +804,10 @@ function processUpdate() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {URL} url
|
||||||
|
* @param {boolean} test
|
||||||
|
*/
|
||||||
async function copyRaw(url, test) {
|
async function copyRaw(url, test) {
|
||||||
const newUrl = await reverse(url)
|
const newUrl = await reverse(url)
|
||||||
if (newUrl) {
|
if (newUrl) {
|
||||||
@ -794,6 +828,9 @@ async function copyRaw(url, test) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {URL} url
|
||||||
|
*/
|
||||||
function isException(url) {
|
function isException(url) {
|
||||||
if (!options.exceptions) return false
|
if (!options.exceptions) return false
|
||||||
let exceptions = options.exceptions
|
let exceptions = options.exceptions
|
||||||
|
@ -1,18 +1,49 @@
|
|||||||
window.browser = window.browser || window.chrome
|
window.browser = window.browser || window.chrome
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Array.<T>} instances
|
||||||
|
* @returns {T}
|
||||||
|
*/
|
||||||
function getRandomInstance(instances) {
|
function getRandomInstance(instances) {
|
||||||
return instances[~~(instances.length * Math.random())]
|
return instances[~~(instances.length * Math.random())]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} str
|
||||||
|
*/
|
||||||
function camelCase(str) {
|
function camelCase(str) {
|
||||||
return str.charAt(0).toUpperCase() + str.slice(1)
|
return str.charAt(0).toUpperCase() + str.slice(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {URL} url
|
||||||
|
*/
|
||||||
function protocolHost(url) {
|
function protocolHost(url) {
|
||||||
if (url.username && url.password) return `${url.protocol}//${url.username}:${url.password}@${url.host}`
|
if (url.username && url.password) return `${url.protocol}//${url.username}:${url.password}@${url.host}`
|
||||||
return `${url.protocol}//${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() {
|
function getConfig() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
fetch("/config.json")
|
fetch("/config.json")
|
||||||
@ -24,6 +55,14 @@ function getConfig() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} Option
|
||||||
|
* @prop {string} frontend
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Promise<Object.<string, Option | string[]>>}
|
||||||
|
*/
|
||||||
function getOptions() {
|
function getOptions() {
|
||||||
return new Promise(resolve =>
|
return new Promise(resolve =>
|
||||||
browser.storage.local.get("options", r => {
|
browser.storage.local.get("options", r => {
|
||||||
@ -106,6 +145,9 @@ function getList(options) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} href
|
||||||
|
*/
|
||||||
function pingOnce(href) {
|
function pingOnce(href) {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
let started
|
let started
|
||||||
@ -130,6 +172,9 @@ function pingOnce(href) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} href
|
||||||
|
*/
|
||||||
function ping(href) {
|
function ping(href) {
|
||||||
return new Promise(async resolve => {
|
return new Promise(async resolve => {
|
||||||
let average = 0
|
let average = 0
|
||||||
|
@ -17,6 +17,9 @@ for (const a of document.getElementById("links").getElementsByTagName("a")) {
|
|||||||
config = await utils.getConfig()
|
config = await utils.getConfig()
|
||||||
options = await utils.getOptions()
|
options = await utils.getOptions()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} service
|
||||||
|
*/
|
||||||
async function changeFrontendsSettings(service) {
|
async function changeFrontendsSettings(service) {
|
||||||
options = await utils.getOptions()
|
options = await utils.getOptions()
|
||||||
const opacityDiv = document.getElementById(`${service}-opacity`)
|
const opacityDiv = document.getElementById(`${service}-opacity`)
|
||||||
@ -95,6 +98,9 @@ async function changeFrontendsSettings(service) {
|
|||||||
frontend_name_element.href = config.services[service].frontends[divs[service].frontend.value].url
|
frontend_name_element.href = config.services[service].frontends[divs[service].frontend.value].url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} path
|
||||||
|
*/
|
||||||
async function loadPage(path) {
|
async function loadPage(path) {
|
||||||
options = await utils.getOptions()
|
options = await utils.getOptions()
|
||||||
for (const section of document.getElementById("pages").getElementsByTagName("section")) section.style.display = "none"
|
for (const section of document.getElementById("pages").getElementsByTagName("section")) section.style.display = "none"
|
||||||
@ -251,6 +257,13 @@ async function processCustomInstances(frontend, document) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} frontend
|
||||||
|
* @param {*} networks
|
||||||
|
* @param {*} document
|
||||||
|
* @param {*} redirects
|
||||||
|
* @param {*} blacklist
|
||||||
|
*/
|
||||||
async function createList(frontend, networks, document, redirects, blacklist) {
|
async function createList(frontend, networks, document, redirects, blacklist) {
|
||||||
const pingCache = await utils.getPingCache()
|
const pingCache = await utils.getPingCache()
|
||||||
const options = await utils.getOptions()
|
const options = await utils.getOptions()
|
||||||
@ -331,6 +344,9 @@ const r = window.location.href.match(/#(.*)/)
|
|||||||
if (r) loadPage(r[1])
|
if (r) loadPage(r[1])
|
||||||
else loadPage("general")
|
else loadPage("general")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} frontend
|
||||||
|
*/
|
||||||
async function ping(frontend) {
|
async function ping(frontend) {
|
||||||
const instanceElements = [
|
const instanceElements = [
|
||||||
...document.getElementById(frontend).getElementsByClassName("custom-checklist")[0].getElementsByTagName('x'),
|
...document.getElementById(frontend).getElementsByClassName("custom-checklist")[0].getElementsByTagName('x'),
|
||||||
@ -357,6 +373,9 @@ async function ping(frontend) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} time
|
||||||
|
*/
|
||||||
function processTime(time) {
|
function processTime(time) {
|
||||||
let text
|
let text
|
||||||
let color
|
let color
|
||||||
|
Loading…
x
Reference in New Issue
Block a user