From 28a45a2a60e0b22db45e6a45f1cd21c7602fc76e Mon Sep 17 00:00:00 2001 From: LawnCable Date: Sun, 28 Feb 2021 17:39:20 +0100 Subject: apply prettier code formatting --- src/renderer/gameserver/news.ts | 71 +++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 34 deletions(-) (limited to 'src/renderer/gameserver/news.ts') diff --git a/src/renderer/gameserver/news.ts b/src/renderer/gameserver/news.ts index 656238c..34f6995 100644 --- a/src/renderer/gameserver/news.ts +++ b/src/renderer/gameserver/news.ts @@ -1,64 +1,67 @@ export enum NewsType { Markdown, // Without html + yaml - ManaPlus //update news txt + ManaPlus, //update news txt } -export namespace News { // Fetches only the most recent entry - export async function get(url:string,parser:NewsType):Promise{ +export namespace News { + // Fetches only the most recent entry + export async function get(url: string, parser: NewsType): Promise { try { //1. load const unsafe_content = await request(`${url}?${Math.random()}`); //2. sanitize - const content = killHTML( unsafe_content ); + const content = killHTML(unsafe_content); //3. parse - if(parser == NewsType.ManaPlus){ + if (parser == NewsType.ManaPlus) { return manaTextParser(content); - } else if (parser == NewsType.Markdown){ + } else if (parser == NewsType.Markdown) { return "Parsing Failed: Markdown Parser is not implemented yet"; } - } catch (e){ + } catch (e) { console.log(e); return `Failed to get the news, please select the news category on the right to view all news`; } } } -function request(url:string):Promise{ - return new Promise((res, rej)=>{ - var xhr = new XMLHttpRequest(); - xhr.addEventListener("error", (ev)=>{ - rej(ev); - }); - xhr.open('GET', url); - xhr.onload = function() { - if (xhr.status === 200) { - res(xhr.responseText); - } - else { - rej(new Error(`xhr.status: ${xhr.status} != 200`)); - } - }; - xhr.send(); +function request(url: string): Promise { + return new Promise((res, rej) => { + var xhr = new XMLHttpRequest(); + xhr.addEventListener("error", (ev) => { + rej(ev); + }); + xhr.open("GET", url); + xhr.onload = function () { + if (xhr.status === 200) { + res(xhr.responseText); + } else { + rej(new Error(`xhr.status: ${xhr.status} != 200`)); + } + }; + xhr.send(); }); } -function killHTML(raw:string):string{ - return raw.replace(/<|>/,"⚠️"); +function killHTML(raw: string): string { + return raw.replace(/<|>/, "⚠️"); } -function manaTextParser(input:string){ +function manaTextParser(input: string) { const tmwLegacy = "##7Legacy Server##0"; let result = input; - if(result.indexOf(tmwLegacy) !== -1){ + if (result.indexOf(tmwLegacy) !== -1) { const i = result.indexOf(tmwLegacy) + tmwLegacy.length; result = result.slice(0, result.indexOf(tmwLegacy, i)); result = result.replace(/\n \n /, ""); } - result = result.replace(/\[@@(.+?)\|(.+?)@@\]/g,'$2') - .replace(/##B(.+?)##b/g,'$1') - .replace(/##0 Actual Release: ##1 *(.+)/,'

$1

') - .replace(/\n/g,"
"); - if(result.indexOf(tmwLegacy) === -1) - result = result.replace(/br>([^]+?)

$1


<').replace(/
/g,""); - return result.replace(/##\d/g,""); + result = result + .replace(/\[@@(.+?)\|(.+?)@@\]/g, '$2') + .replace(/##B(.+?)##b/g, "$1") + .replace(/##0 Actual Release: ##1 *(.+)/, "

$1

") + .replace(/\n/g, "
"); + if (result.indexOf(tmwLegacy) === -1) + result = result + .replace(/br>([^]+?)

$1


<") + .replace(/
/g, ""); + return result.replace(/##\d/g, ""); } -- cgit v1.2.3-60-g2f50