summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLawnCable <lawncable.tmw2@simonlaux.de>2018-05-24 16:17:50 -0400
committerLawnCable <lawncable.tmw2@simonlaux.de>2018-05-24 16:17:50 -0400
commitd81bc993b8e4acc63af8cf0030d391c4befd77fb (patch)
treee9409a520759f55dd7373481b16df34a44a17505 /src
parente48328aac858537871c29953d9f4f2316e0c39dd (diff)
downloadelectron-d81bc993b8e4acc63af8cf0030d391c4befd77fb.tar.gz
electron-d81bc993b8e4acc63af8cf0030d391c4befd77fb.tar.bz2
electron-d81bc993b8e4acc63af8cf0030d391c4befd77fb.tar.xz
electron-d81bc993b8e4acc63af8cf0030d391c4befd77fb.zip
added basic support to have the latest news entry on the info page
Diffstat (limited to 'src')
-rw-r--r--src/main.ts4
-rw-r--r--src/renderer/gameserver/data.ts4
-rw-r--r--src/renderer/gameserver/news.ts54
-rw-r--r--src/renderer/gameserver/server.ts18
-rw-r--r--src/renderer/serverView.ts2
5 files changed, 79 insertions, 3 deletions
diff --git a/src/main.ts b/src/main.ts
index 7810495..0f60c34 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -17,8 +17,8 @@ if (isSecondInstance) {
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow({
- width: 1300,
- height: 600,
+ width: 780,
+ height: 550,
minHeight: 475,
minWidth: 650,
frame: false
diff --git a/src/renderer/gameserver/data.ts b/src/renderer/gameserver/data.ts
index e3162f6..8140581 100644
--- a/src/renderer/gameserver/data.ts
+++ b/src/renderer/gameserver/data.ts
@@ -2,6 +2,7 @@
import {socialLink} from './server';
import GameServer from './server';
import GameServerProfile from './profile';
+import { NewsType } from './news';
const TMW2 = new GameServer(
@@ -15,6 +16,7 @@ const TMW2 = new GameServer(
"TMW2: Monster Wars",
"What happens if you mix TMW with Evol and add many new Ideas",
"https://tmw2.org/news",
+ {url:"http://updates.tmw2.org/news.txt",type:NewsType.ManaPlus},
[{isVideo:false,file:"tmw2/background1.png"}],
"tmw2/icon.png",
[
@@ -34,6 +36,7 @@ const Evol = new GameServer(
"Evol Online",
"[EvolDescription]",
"https://evolonline.org/",
+ undefined,
[{isVideo:false,file:"evol/background1.png"}],
"evol/icon.png",
[
@@ -51,6 +54,7 @@ const TMW = new GameServer(
"The Mana World",
"The clasic TMW experience. Join adventures with people from all over the world.",
"https://www.themanaworld.org/news-feed.php",
+ undefined,
[{isVideo:false,file:"tmw/background1.png"}],
"tmw/icon.png",
[
diff --git a/src/renderer/gameserver/news.ts b/src/renderer/gameserver/news.ts
new file mode 100644
index 0000000..b8c7b14
--- /dev/null
+++ b/src/renderer/gameserver/news.ts
@@ -0,0 +1,54 @@
+export enum NewsType {
+ Markdown, // Without html + yaml
+ ManaPlus //update news txt
+}
+
+export namespace News { // Fetches only the most recent entry
+ export async function get(url:string,parser:NewsType):Promise<string>{
+ try {
+ //1. load
+ const unsafe_content = await request(url);
+ //2. sanitize
+ const content = killHTML( unsafe_content );
+ //3. parse
+ if(parser == NewsType.ManaPlus){
+ return manaTextParser(content);
+ } else if (parser == NewsType.Markdown){
+ return "Parsing Failed: Markdown Parser is not implemented yet";
+ }
+ } 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<string>{
+ return new Promise((res, rej)=>{
+ var xhr = new XMLHttpRequest();
+ 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 manaTextParser(input:string){
+ return input
+ .replace(/\[@@(.+?)\|(.+?)@@\]/g,'<a href="$1">$2</a>')
+ .replace(/##B(.+?)##b/g,'<b>$1</b>')
+ .replace(/##0 Actual Release: ##1 *(.+)/,'<h2>$1</h2>')
+ .replace(/\n/g,"<br>")
+ .replace(/br>([^]+?)<br></g,'br><p>$1</p><br><').replace(/<br>/g,"")
+ .replace(/##\d/g,"");
+}
diff --git a/src/renderer/gameserver/server.ts b/src/renderer/gameserver/server.ts
index d0b4002..30b40e1 100644
--- a/src/renderer/gameserver/server.ts
+++ b/src/renderer/gameserver/server.ts
@@ -1,6 +1,7 @@
import GameServerProfile from './profile';
import { shell, ipcRenderer } from 'electron';
import { switchPage } from '../CustomEvents';
+import { News, NewsType } from './news';
export default class GameServer {
@@ -10,6 +11,7 @@ export default class GameServer {
public name:string,
public shortDescription:string,// the server in 1-2 sentences
public newsPageUrl:string,
+ public newsLatestPage:{url:string,type:NewsType},
public backgrounds:{isVideo:boolean,file:string}[],
public icon:string,
public socialLinks:socialLink[]
@@ -145,6 +147,22 @@ export default class GameServer {
shrtDsrption.classList.add("shortDescription");
shrtDsrption.innerText = this.shortDescription;
content.appendChild(shrtDsrption);
+ if(this.newsLatestPage && this.newsLatestPage != null){
+ const latestNews = document.createElement('div');
+ latestNews.classList.add("news");
+ content.appendChild(latestNews);
+ News.get(this.newsLatestPage.url,this.newsLatestPage.type).then((result:string)=>{
+ latestNews.innerHTML = result;
+ const aTags = latestNews.getElementsByTagName("a");
+ for (var i = 0; i < aTags.length; i++) {
+ const href = aTags[i].href.toString();
+ aTags[i].addEventListener('click', ()=>{
+ shell.openExternal(href);
+ });
+ aTags[i].href = "#";
+ }
+ });
+ }
return content;
}
diff --git a/src/renderer/serverView.ts b/src/renderer/serverView.ts
index 7f932e7..2250680 100644
--- a/src/renderer/serverView.ts
+++ b/src/renderer/serverView.ts
@@ -95,7 +95,7 @@ function setBackground(){
background1.classList.add('animated');
background1.classList.add('fadeIn');
}
-
+ contentBackground.appendChild(document.createElement('div'))
contentBackground.hidden=false;
contentBackground.classList.remove('hidden');
}