diff options
| author | stonedDiscord <Tukz@gmx.de> | 2023-09-20 12:57:45 +0200 |
|---|---|---|
| committer | stonedDiscord <Tukz@gmx.de> | 2023-09-20 12:57:45 +0200 |
| commit | 59028dd4046ad0715d80be8d1ed0031f20f05b7a (patch) | |
| tree | c66c470ad4fb959b8959f1895e410762c557437b /webAO/utils | |
| parent | ef28c355ef69fee7511956751bbdb5dcd1a931b1 (diff) | |
mostly whitespaces, please don't break
Diffstat (limited to 'webAO/utils')
| -rw-r--r-- | webAO/utils/aoml.ts | 4 | ||||
| -rw-r--r-- | webAO/utils/calculatorHandler.js | 6 | ||||
| -rw-r--r-- | webAO/utils/fileExists.js | 28 | ||||
| -rw-r--r-- | webAO/utils/getAnimLength.js | 20 | ||||
| -rw-r--r-- | webAO/utils/getCookie.ts | 36 | ||||
| -rw-r--r-- | webAO/utils/getResources.js | 72 | ||||
| -rw-r--r-- | webAO/utils/queryParser.ts | 31 | ||||
| -rw-r--r-- | webAO/utils/setCookie.ts | 8 |
8 files changed, 105 insertions, 100 deletions
diff --git a/webAO/utils/aoml.ts b/webAO/utils/aoml.ts index 5b5da5f..1f2f482 100644 --- a/webAO/utils/aoml.ts +++ b/webAO/utils/aoml.ts @@ -10,7 +10,7 @@ interface Aoml { color: string; } const aomlParser = (text: string) => { - let parsed: {[key: string]: Aoml}= {} + const parsed: {[key: string]: Aoml}= {} let currentHeader = '' for (const line of text.split(/\r?\n/)) { if (line === '') { @@ -35,7 +35,7 @@ const aomlParser = (text: string) => { const mlConfig = (AO_HOST: string) => { const defaultUrl = `${AO_HOST}themes/default/chat_config.ini` - let aomlParsed: Promise<{ [key: string]: Aoml }> = request(defaultUrl).then((data) => aomlParser(data)); + const aomlParsed: Promise<{ [key: string]: Aoml }> = request(defaultUrl).then((data) => aomlParser(data)); diff --git a/webAO/utils/calculatorHandler.js b/webAO/utils/calculatorHandler.js index 9072195..890b53c 100644 --- a/webAO/utils/calculatorHandler.js +++ b/webAO/utils/calculatorHandler.js @@ -3,7 +3,7 @@ import calculateWebpLength from './calculateWebpLength'; import calculateApngLength from './calculateApngLength'; export default { - '.gif': calculateGifLength, - '.webp': calculateWebpLength, - '.apng': calculateApngLength, + '.gif': calculateGifLength, + '.webp': calculateWebpLength, + '.apng': calculateApngLength, }; diff --git a/webAO/utils/fileExists.js b/webAO/utils/fileExists.js index a4b3b80..5b60976 100644 --- a/webAO/utils/fileExists.js +++ b/webAO/utils/fileExists.js @@ -1,18 +1,18 @@ const fileExists = async (url) => new Promise((resolve) => { - const xhr = new XMLHttpRequest(); - xhr.open('HEAD', url); - xhr.onload = function checkLoad() { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - resolve(true); - } else { + const xhr = new XMLHttpRequest(); + xhr.open('HEAD', url); + xhr.onload = function checkLoad() { + if (xhr.readyState === 4) { + if (xhr.status === 200) { + resolve(true); + } else { + resolve(false); + } + } + }; + xhr.onerror = function checkError() { resolve(false); - } - } - }; - xhr.onerror = function checkError() { - resolve(false); - }; - xhr.send(null); + }; + xhr.send(null); }); export default fileExists; diff --git a/webAO/utils/getAnimLength.js b/webAO/utils/getAnimLength.js index b33757a..2d83844 100644 --- a/webAO/utils/getAnimLength.js +++ b/webAO/utils/getAnimLength.js @@ -12,16 +12,16 @@ import { requestBuffer } from '../services/request'; */ const getAnimLength = async (url) => { - const extensions = ['.gif', '.webp', '.apng']; - for (const extension of extensions) { - const urlWithExtension = url + extension; - const exists = await fileExists(urlWithExtension); - if (exists) { - const fileBuffer = await requestBuffer(urlWithExtension); - const length = calculatorHandler[extension](fileBuffer); - return length; + const extensions = ['.gif', '.webp', '.apng']; + for (const extension of extensions) { + const urlWithExtension = url + extension; + const exists = await fileExists(urlWithExtension); + if (exists) { + const fileBuffer = await requestBuffer(urlWithExtension); + const length = calculatorHandler[extension](fileBuffer); + return length; + } } - } - return 0; + return 0; }; export default getAnimLength; diff --git a/webAO/utils/getCookie.ts b/webAO/utils/getCookie.ts index f5b9679..638dcb7 100644 --- a/webAO/utils/getCookie.ts +++ b/webAO/utils/getCookie.ts @@ -2,25 +2,25 @@ * read a cookie from storage * got this from w3schools * https://www.w3schools.com/js/js_cookies.asp - * @param {String} cname The name of the cookie to return + * @param {string} cname The name of the cookie to return */ -const getCookie = (cname: String) => { - try { - const name = `${cname}=`; - const decodedCookie = decodeURIComponent(document.cookie); - const ca = decodedCookie.split(';'); - for (let i = 0; i < ca.length; i++) { - let c = ca[i]; - while (c.charAt(0) === ' ') { - c = c.substring(1); - } - if (c.indexOf(name) === 0) { - return c.substring(name.length, c.length); - } +const getCookie = (cname: string) => { + try { + const name = `${cname}=`; + const decodedCookie = decodeURIComponent(document.cookie); + const ca = decodedCookie.split(';'); + for (let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) === ' ') { + c = c.substring(1); + } + if (c.indexOf(name) === 0) { + return c.substring(name.length, c.length); + } + } + return ''; + } catch (error) { + return ''; } - return ''; - } catch (error) { - return ''; - } }; export default getCookie; diff --git a/webAO/utils/getResources.js b/webAO/utils/getResources.js index 859e63b..a711452 100644 --- a/webAO/utils/getResources.js +++ b/webAO/utils/getResources.js @@ -1,39 +1,39 @@ const getResources = (AO_HOST, THEME) => ({ - holdit: { - src: `${AO_HOST}misc/default/holdit_bubble.png`, - duration: 720, - }, - objection: { - src: `${AO_HOST}misc/default/objection_bubble.png`, - duration: 720, - }, - takethat: { - src: `${AO_HOST}misc/default/takethat_bubble.png`, - duration: 840, - }, - custom: { - src: '', - duration: 840, - }, - witnesstestimony: { - src: `${AO_HOST}themes/${THEME}/witnesstestimony_bubble.gif`, - duration: 1560, - sfx: `${AO_HOST}sounds/general/sfx-testimony.opus`, - }, - crossexamination: { - src: `${AO_HOST}themes/${THEME}/crossexamination_bubble.gif`, - duration: 1600, - sfx: `${AO_HOST}sounds/general/sfx-testimony2.opus`, - }, - guilty: { - src: `${AO_HOST}themes/${THEME}/guilty_bubble.gif`, - duration: 2870, - sfx: `${AO_HOST}sounds/general/sfx-guilty.opus`, - }, - notguilty: { - src: `${AO_HOST}themes/${THEME}/notguilty_bubble.gif`, - duration: 2440, - sfx: `${AO_HOST}sounds/general/sfx-notguilty.opus`, - }, + holdit: { + src: `${AO_HOST}misc/default/holdit_bubble.png`, + duration: 720, + }, + objection: { + src: `${AO_HOST}misc/default/objection_bubble.png`, + duration: 720, + }, + takethat: { + src: `${AO_HOST}misc/default/takethat_bubble.png`, + duration: 840, + }, + custom: { + src: '', + duration: 840, + }, + witnesstestimony: { + src: `${AO_HOST}themes/${THEME}/witnesstestimony_bubble.gif`, + duration: 1560, + sfx: `${AO_HOST}sounds/general/sfx-testimony.opus`, + }, + crossexamination: { + src: `${AO_HOST}themes/${THEME}/crossexamination_bubble.gif`, + duration: 1600, + sfx: `${AO_HOST}sounds/general/sfx-testimony2.opus`, + }, + guilty: { + src: `${AO_HOST}themes/${THEME}/guilty_bubble.gif`, + duration: 2870, + sfx: `${AO_HOST}sounds/general/sfx-guilty.opus`, + }, + notguilty: { + src: `${AO_HOST}themes/${THEME}/notguilty_bubble.gif`, + duration: 2440, + sfx: `${AO_HOST}sounds/general/sfx-notguilty.opus`, + }, }); export default getResources; diff --git a/webAO/utils/queryParser.ts b/webAO/utils/queryParser.ts index 3110c14..20863ca 100644 --- a/webAO/utils/queryParser.ts +++ b/webAO/utils/queryParser.ts @@ -1,22 +1,25 @@ +/* eslint @typescript-eslint/no-explicit-any: "warn" */ + interface QueryParams { - ip: string; - serverIP: string; - mode: string; - asset: string; - theme: string; + ip: string; + serverIP: string; + mode: string; + asset: string; + theme: string; } + interface StringMap { - [key: string]: any; + [key: string]: any; } const queryParser = (): QueryParams => { - const queryDict: StringMap = {}; - location.search - .substr(1) - .split("&") - .forEach((item) => { - queryDict[item.split("=")[0]] = item.split("=")[1]; - }); - return queryDict as QueryParams; + const queryDict: StringMap = {}; + location.search + .substr(1) + .split("&") + .forEach((item) => { + queryDict[item.split("=")[0]] = item.split("=")[1]; + }); + return queryDict as QueryParams; }; export default queryParser; diff --git a/webAO/utils/setCookie.ts b/webAO/utils/setCookie.ts index f9ac5d2..a4e554e 100644 --- a/webAO/utils/setCookie.ts +++ b/webAO/utils/setCookie.ts @@ -1,10 +1,12 @@ +/* eslint @typescript-eslint/no-explicit-any: "off" */ + /** * set a cookie * the version from w3schools expects these to expire - * @param {String} cname The name of the cookie to return + * @param {string} cname The name of the cookie to return * @param {any} value The value of that cookie option */ -const setCookie = (cname: String, value: any) => { - document.cookie = `${cname}=${value};SameSite=Strict`; +const setCookie = (cname: string, value: any) => { + document.cookie = `${cname}=${value};SameSite=Strict`; }; export default setCookie; |
