Skip to content

Commit

Permalink
Release 1.0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
jesuscc1993 committed Mar 23, 2023
1 parent d5f8e64 commit e0f90f0
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 59 deletions.
1 change: 1 addition & 0 deletions assets/i18n/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"normal": "Normal",
"odin": "Odin",
"olivia": "Olivia",
"open_issue": "View / report issues",
"options": "Options",
"osiris": "Osiris",
"outfit": "Outfit",
Expand Down
1 change: 1 addition & 0 deletions assets/i18n/es-es.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"normal": "Normal",
"odin": "Odin",
"olivia": "Olivia",
"open_issue": "Ver / reportar problemas",
"options": "Opciones",
"osiris": "Osiris",
"outfit": "Atuendo",
Expand Down
23 changes: 12 additions & 11 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"author": "MetalTxus (Jesús Miguel Cruz Cana)",
"background": {
"page": "src/modules/background/background.html"
},
"browser_action": {
"action": {
"default_popup": "src/modules/bookmarks/bookmarks.html",
"default_title": "Show bookmarks"
},
"author": "MetalTxus (Jesús Miguel Cruz Cana)",
"background": {
"service_worker": "src/modules/background/background.js",
"type": "module"
},
"commands": {
"_execute_browser_action": {
"_execute_action": {
"suggested_key": {
"chromeos": "Ctrl+Shift+F",
"linux": "Ctrl+Shift+F",
Expand All @@ -19,15 +20,15 @@
"open-arcarum": {
"description": "Open arcarum"
},
"open-fate": {
"description": "Open fate episodes"
},
"open-event": {
"description": "Open event",
"suggested_key": {
"default": "Shift+Alt+E"
}
},
"open-fate-episodes": {
"description": "Open fate episodes"
},
"open-guild-wars": {
"description": "Open Unite and Fight",
"suggested_key": {
Expand Down Expand Up @@ -59,9 +60,9 @@
"48": "assets/images/icons/icon.png",
"128": "assets/images/icons/icon.png"
},
"manifest_version": 2,
"manifest_version": 3,
"name": "GBF Bookmarker",
"options_page": "src/modules/options/options.html",
"permissions": ["activeTab", "browsingData", "contextMenus", "notifications", "storage", "tabs"],
"version": "1.0.21"
"version": "1.0.22"
}
134 changes: 86 additions & 48 deletions src/modules/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,6 @@ import {
import { loadSettings, storeSettings } from '../../storage/settings.storage.js';
import { fetchJson } from '../../shared/file.utils.js';

const targetDomain = 'game.granbluefantasy.jp';

const URL_KEYS = {
EVENT: 'event',
GUILD_WARS: 'guildWars',
LAST_QUEST: 'lastQuest',
};

const URLS = {
ARCARUM: `https://${targetDomain}/#arcarum2`,
FATE: `https://${targetDomain}/#quest/fate`,
PARTY: `https://${targetDomain}/#party/index/0/npc/0`,
QUEST: `https://${targetDomain}/#quest`,
RAIDS: `https://${targetDomain}/#quest/assist`,
WORLD: `https://${targetDomain}/#quest/island`,
};

const initializeBackground = () => {
loadSettings().then((settings) => {
if (!settings) {
Expand All @@ -37,11 +20,11 @@ const initializeBackground = () => {
if (changeInfo.status == 'complete' && url.includes(targetDomain)) {
if (url.includes('/supporter/')) {
// quests
const key = URL_KEYS.LAST_QUEST;
const key = UrlKeys.LastQuest;
storage.sync.set({ [key]: url });
} else if (url.includes('/#event/teamraid')) {
// guild wars
const key = URL_KEYS.GUILD_WARS;
const key = UrlKeys.GuildWars;
storage.sync.get([key], (response) => {
const currentUrl = response[key];
if (!url.includes(currentUrl)) {
Expand All @@ -50,7 +33,7 @@ const initializeBackground = () => {
});
} else if (isAnySubstringIncluded(url, ['/#event', '/#limited'])) {
// events
const key = URL_KEYS.EVENT;
const key = UrlKeys.Event;
storage.sync.get([key], (response) => {
const currentUrl = response[key];
if (!url.includes(currentUrl)) {
Expand All @@ -69,15 +52,15 @@ const initializeBackground = () => {

if (firstmatch) {
const action = {
'open-arcarum': openArcarum,
'open-event': openEvent,
'open-fate': openFate,
'open-guild-wars': openGuildWars,
'open-party': openParty,
'open-quests': openQuests,
'open-raids': openRaids,
'open-world': openWorld,
'repeat-quest': repeatQuest,
[ShortcutAction.Arcarum]: openArcarum,
[ShortcutAction.Event]: openEvent,
[ShortcutAction.FateEpisodes]: openFate,
[ShortcutAction.GuildWars]: openGuildWars,
[ShortcutAction.Party]: openParty,
[ShortcutAction.Quests]: openQuests,
[ShortcutAction.Raids]: openRaids,
[ShortcutAction.RepeatQuest]: repeatQuest,
[ShortcutAction.World]: openWorld,
}[command];
action && action(firstmatch.id);
}
Expand All @@ -88,33 +71,46 @@ const initializeBackground = () => {
initializeTranslations().then(({ language }) => {
setLanguage(language || navigator.language.toLowerCase()).then(() => {
chrome.contextMenus.create({
title: translate('developed_by'),
contexts: ['browser_action'],
onclick: () => {
window.open('https://github.com/jesuscc1993');
},
id: ContextMenuItem.About,
title: translate('about_extension'),
contexts: ['all'],
});
chrome.contextMenus.create({
title: translate('about_extension'),
contexts: ['browser_action'],
onclick: () => {
window.open('https://github.com/jesuscc1993/gbf-bookmarker');
},
id: ContextMenuItem.Issues,
title: translate('open_issue'),
contexts: ['all'],
});
chrome.contextMenus.create({
id: ContextMenuItem.Developer,
title: translate('developed_by'),
contexts: ['all'],
});
chrome.contextMenus.onClicked.addListener((info, tab) => {
const action = {
[ContextMenuItem.About]: openAbout,
[ContextMenuItem.Developer]: openDeveloper,
[ContextMenuItem.Issues]: openIssues,
}[info.menuItemId];
action && action();
});
});
});
};

const openEvent = (tabId) => openStoredUrl(tabId, URL_KEYS.EVENT);
const openGuildWars = (tabId) => openStoredUrl(tabId, URL_KEYS.GUILD_WARS);
const repeatQuest = (tabId) => openStoredUrl(tabId, URL_KEYS.LAST_QUEST);
const openEvent = (tabId) => openStoredUrl(tabId, UrlKeys.Event);
const openGuildWars = (tabId) => openStoredUrl(tabId, UrlKeys.GuildWars);
const repeatQuest = (tabId) => openStoredUrl(tabId, UrlKeys.LastQuest);

const openArcarum = (tabId) => openUrl(tabId, URLS.ARCARUM);
const openFate = (tabId) => openUrl(tabId, URLS.FATE);
const openParty = (tabId) => openUrl(tabId, URLS.PARTY);
const openQuests = (tabId) => openUrl(tabId, URLS.QUEST);
const openRaids = (tabId) => openUrl(tabId, URLS.RAIDS);
const openWorld = (tabId) => openUrl(tabId, URLS.WORLD);
const openArcarum = (tabId) => openUrl(tabId, Urls.Arcarum);
const openFate = (tabId) => openUrl(tabId, Urls.FateEpisodes);
const openParty = (tabId) => openUrl(tabId, Urls.Party);
const openQuests = (tabId) => openUrl(tabId, Urls.Quest);
const openRaids = (tabId) => openUrl(tabId, Urls.Raids);
const openWorld = (tabId) => openUrl(tabId, Urls.World);

const openAbout = () => openTab(Urls.About);
const openDeveloper = () => openTab(Urls.Developer);
const openIssues = () => openTab(Urls.Issues);

const openStoredUrl = (tabId, key) => {
storage.sync.get([key], (response) => {
Expand All @@ -130,6 +126,9 @@ const openStoredUrl = (tabId, key) => {
const openUrl = (tabId, url) => {
tabs.update(tabId, { url });
};
const openTab = (url) => {
tabs.create({ url });
};

const isAnySubstringIncluded = (string, substrings) => {
return (
Expand All @@ -139,4 +138,43 @@ const isAnySubstringIncluded = (string, substrings) => {
);
};

const targetDomain = 'game.granbluefantasy.jp';

const UrlKeys = {
Event: 'event',
GuildWars: 'guildWars',
LastQuest: 'lastQuest',
};

const Urls = {
Arcarum: `https://${targetDomain}/#arcarum2`,
FateEpisodes: `https://${targetDomain}/#quest/fate`,
Party: `https://${targetDomain}/#party/index/0/npc/0`,
Quest: `https://${targetDomain}/#quest`,
Raids: `https://${targetDomain}/#quest/assist`,
World: `https://${targetDomain}/#quest/island`,

About: `https://github.com/jesuscc1993/gbf-bookmarker#gbf-bookmarker`,
Developer: `https://github.com/jesuscc1993`,
Issues: `https://github.com/jesuscc1993/gbf-bookmarker/issues`,
};

const ShortcutAction = {
Arcarum: 'open-arcarum',
Event: 'open-event',
FateEpisodes: 'open-fate-episodes',
GuildWars: 'open-guild-wars',
Party: 'open-party',
Quests: 'open-quests',
Raids: 'open-raids',
RepeatQuest: 'repeat-quest',
World: 'open-world',
};

const ContextMenuItem = {
About: 'gbf-bookmarker-about',
Developer: 'gbf-bookmarker-developer',
Issues: 'gbf-bookmarker-issues',
};

initializeBackground();

0 comments on commit e0f90f0

Please sign in to comment.