notify: escapeHtml for titles

This commit is contained in:
Ralf Vogler 2023-01-25 20:56:35 +01:00
parent f8932af2a1
commit 72a61458fc
4 changed files with 12 additions and 11 deletions

View file

@ -2,7 +2,7 @@ import { firefox } from 'playwright'; // stealth plugin needs no outdated playwr
import { authenticator } from 'otplib';
import path from 'path';
import { existsSync, writeFileSync } from 'fs';
import { dirs, jsonDb, datetime, stealth, filenamify, notify } from './util.js';
import { dirs, jsonDb, datetime, stealth, filenamify, notify, html_game_list } from './util.js';
import { cfg } from './config.js';
import prompts from 'prompts'; // alternatives: enquirer, inquirer
@ -199,8 +199,7 @@ try {
} finally {
await db.write(); // write out json db
if (notify_games.filter(g => g.status != 'existed').length) { // don't notify if all were already claimed; TODO don't notify if killed?
const list = notify_games.map(g => `- <a href="${g.url}">${g.title}</a> (${g.status})`).join('<br>');
notify(`epic-games:<br>${list}`);
notify(`epic-games:<br>${html_game_list(notify_games)}`);
}
}
await writeFileSync(path.resolve(dirs.browser, 'cookies.json'), JSON.stringify(await context.cookies()));

5
gog.js
View file

@ -1,6 +1,6 @@
import { firefox } from 'playwright'; // stealth plugin needs no outdated playwright-extra
import path from 'path';
import { dirs, jsonDb, datetime, filenamify, notify } from './util.js';
import { dirs, jsonDb, datetime, filenamify, notify, html_game_list } from './util.js';
import { cfg } from './config.js';
import prompts from 'prompts'; // alternatives: enquirer, inquirer
@ -127,8 +127,7 @@ try {
} finally {
await db.write(); // write out json db
if (notify_games.filter(g => g.status != 'existed').length) { // don't notify if all were already claimed; TODO don't notify if killed?
const list = notify_games.map(g => `- <a href="${g.url}">${g.title}</a> (${g.status})`).join('<br>');
notify(`gog:<br>${list}`);
notify(`gog:<br>${html_game_list(notify_games)}`);
}
}
await context.close();

View file

@ -1,7 +1,7 @@
import { firefox } from 'playwright'; // stealth plugin needs no outdated playwright-extra
import { authenticator } from 'otplib';
import path from 'path';
import { dirs, jsonDb, datetime, stealth, filenamify, notify } from './util.js';
import { dirs, jsonDb, datetime, stealth, filenamify, notify, html_game_list } from './util.js';
import { cfg } from './config.js';
import prompts from 'prompts'; // alternatives: enquirer, inquirer
@ -182,8 +182,7 @@ try {
} finally {
await db.write(); // write out json db
if (notify_games.length) { // list should only include claimed games
const list = notify_games.map(g => `- <a href="${g.url}">${g.title}</a> (${g.status})`).join('<br>');
notify(`prime-gaming:<br>${list}`);
notify(`prime-gaming:<br>${html_game_list(notify_games)}`);
}
}
await context.close();

View file

@ -95,3 +95,7 @@ export const notify = (html) => {
if (stdout) console.log(`stdout: ${stdout}`);
});
}
export const escapeHtml = (unsafe) => unsafe.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;').replaceAll("'", '&#039;');
export const html_game_list = games => games.map(g => `- <a href="${g.url}">${escapeHtml(g.title)}</a> (${g.status})`).join('<br>');