Commit d67b09d0 authored by Vildravn's avatar Vildravn
Browse files

Add a check for widget configuration

parent ceb92605
......@@ -20,8 +20,8 @@
REGION - The region you want to show data of; Accepts 'EU' or 'US'
FACTION - What faction's data you want to show; Accepts 'alliance' or 'horde'
*/
const REGION = 'EU';
const FACTION = 'horde';
const REGION = '';
const FACTION = '';
/*
Colors
......@@ -100,39 +100,45 @@ async function createWidget(size) {
widget.backgroundColor = colors.bg;
if (size == 'medium') {
widget.url = REGION == 'EU' ? 'https://www.wowhead.com/world-quests/sl/eu' : 'https://www.wowhead.com/world-quests/sl/na';
let whData = await fetchData("https://www.wowhead.com", "loadString");
$ = cheerio.load(whData);
let data = undefined;
whData = undefined;
delete(whData);
const wrapperStack = widget.addStack();
wrapperStack.layoutHorizontally();
widget.addSpacer();
const leftColumn = wrapperStack.addStack();
leftColumn.layoutVertically();
data = await parseTextGroup(`#${REGION}-group-calling-quests`, `.tiw-region[data-region="${REGION}"]`);
await buildTextDisplay(leftColumn, "calling quests", data, 'https://www.wowhead.com/guides/covenant-callings-shadowlands');
leftColumn.addSpacer(20);
data = await parseTextGroup(`#${REGION}-group-torghast-wings`, `.tiw-region[data-region="${REGION}"]`);
await buildTextDisplay(leftColumn, "torghast wings", data, 'https://www.wowhead.com/guides/torghast-tower-of-the-damned-overview');
wrapperStack.addSpacer();
const rightColumn = wrapperStack.addStack();
rightColumn.layoutVertically();
data = await parseImageGroup(`#${REGION}-group-mythicaffix`, `.tiw-region[data-region="${REGION}"]`);
await buildAffixDisplay(rightColumn, data);
rightColumn.addSpacer(20);
data = await parseTextGroup(`#${REGION}-group-epiceliteworldsl`, `.tiw-region[data-region="${REGION}"]`);
await buildTextDisplay(rightColumn, "world boss", data, slBosses[data[0]]);
$ = undefined;
delete($);
if (REGION && FACTION) {
widget.url = REGION == 'EU' ? 'https://www.wowhead.com/world-quests/sl/eu' : 'https://www.wowhead.com/world-quests/sl/na';
let whData = await fetchData("https://www.wowhead.com", "loadString");
$ = cheerio.load(whData);
let data = undefined;
whData = undefined;
delete (whData);
const wrapperStack = widget.addStack();
wrapperStack.layoutHorizontally();
widget.addSpacer();
const leftColumn = wrapperStack.addStack();
leftColumn.layoutVertically();
data = await parseTextGroup(`#${REGION}-group-calling-quests`, `.tiw-region[data-region="${REGION}"]`);
await buildTextDisplay(leftColumn, "calling quests", data, 'https://www.wowhead.com/guides/covenant-callings-shadowlands');
leftColumn.addSpacer(20);
data = await parseTextGroup(`#${REGION}-group-torghast-wings`, `.tiw-region[data-region="${REGION}"]`);
await buildTextDisplay(leftColumn, "torghast wings", data, 'https://www.wowhead.com/guides/torghast-tower-of-the-damned-overview');
wrapperStack.addSpacer();
const rightColumn = wrapperStack.addStack();
rightColumn.layoutVertically();
data = await parseImageGroup(`#${REGION}-group-mythicaffix`, `.tiw-region[data-region="${REGION}"]`);
await buildAffixDisplay(rightColumn, data);
rightColumn.addSpacer(20);
data = await parseTextGroup(`#${REGION}-group-epiceliteworldsl`, `.tiw-region[data-region="${REGION}"]`);
await buildTextDisplay(rightColumn, "world boss", data, slBosses[data[0]]);
$ = undefined;
delete ($);
} else {
const text = widget.addText('The widget is not configured correctly.');
text.textColor = textStyles.header.color;
text.font = textStyles.header.font;
}
} else {
const text = widget.addText(`${size} widget is currently not supported.`);
text.textColor = textStyles.header.color;
......@@ -149,7 +155,7 @@ async function buildAffixDisplay(parent, affixes) {
affix.text = levels[i];
}
await buildImageDisplay(parent, "mythic+ affixes", affixes);
}
......@@ -157,7 +163,7 @@ async function buildTextDisplay(parent, heading, data, url) {
const contentStack = parent.addStack();
contentStack.layoutVertically();
contentStack.url = url;
const header = contentStack.addText(heading.toUpperCase());
header.textColor = textStyles.header.color;
header.font = textStyles.header.font;
......@@ -172,11 +178,11 @@ async function buildTextDisplay(parent, heading, data, url) {
async function buildImageDisplay(parent, heading, data) {
const contentStack = parent.addStack();
contentStack.layoutVertically();
const header = contentStack.addText(heading.toUpperCase());
header.textColor = textStyles.header.color;
header.font = textStyles.header.font;
const horizontalStack = contentStack.addStack();
horizontalStack.layoutHorizontally();
......@@ -198,7 +204,7 @@ function buildImageItem(parent, image, item) {
icon.cornerRadius = 4;
icon.imageSize = new Size(34, 34);
icon.borderColor = colors.faction[item.side || "both"];
if (item.urlFragment) {
icon.url = `https://wowhead.com${item.urlFragment}`;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment