Skip to content

Commit

Permalink
**FoE-Helfer**
Browse files Browse the repository at this point in the history
- Alle relevanten Änderungen und Bugfixes bis einschließlich FoE Helfer 3.0.0.1 migriert
  • Loading branch information
sdn-br committed Dec 21, 2022
1 parent 8299eaa commit 3370f48
Show file tree
Hide file tree
Showing 49 changed files with 958 additions and 541 deletions.
83 changes: 41 additions & 42 deletions js/background.js → background.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* **************************************************************************************
* *************************************************************************************
*
* Copyright (C) 2022 FoE-Helper team - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the AGPL license.
Expand All @@ -8,9 +9,15 @@
* https://github.com/mainIine/foe-helfer-extension/blob/master/LICENSE.md
* for full license details.
*
* **************************************************************************************
* *************************************************************************************
*/

'use strict';

importScripts(
'vendor/browser-polyfill/browser-polyfill.min.js','vendor/dexie/dexie.min.js'
);

// @ts-ignore
let alertsDB = new Dexie("Alerts");
// Define Database Schema
Expand Down Expand Up @@ -215,6 +222,22 @@ alertsDB.version(1).stores({
// make sure the alarm got cleared before finishing
await alarmClearP;
}

/**
* deletes all Alerts marked for deletion which don't have a notification displayed.
*/
async function cleanupAlerts() {
const alerts = await getAllAlerts();
// don't actually delete an alarm with notification since the user can still interact with the notification
const notifications = await browser.notifications.getAll();
alerts.forEach(alert => {
const tagId = prefix + alert.id;
if (!notifications[tagId]) {
db.alerts.delete(alert.id);
}
});
}

/**
* triggers the notification for the given alert
* @param {FoEAlert} alert
Expand All @@ -240,7 +263,7 @@ alertsDB.version(1).stores({
browser.alarms.onAlarm.addListener(async (alarm) => {
if (!alarm.name.startsWith(prefix)) return;

const alertId = Number.parseInt(alarm.name.substr(prefix.length));
const alertId = Number.parseInt(alarm.name.substring(prefix.length));
if (!Number.isInteger(alertId) || alertId > Number.MAX_SAFE_INTEGER || alertId < 0) return;

const alertData = await db.transaction('rw', db.alerts, async () => {
Expand All @@ -260,7 +283,7 @@ alertsDB.version(1).stores({
browser.notifications.onClicked.addListener(async (notificationId) => {
if (!notificationId.startsWith(prefix)) return;

const alertId = Number.parseInt(notificationId.substr(prefix.length));
const alertId = Number.parseInt(notificationId.substring(prefix.length));
if (!Number.isInteger(alertId) || alertId > Number.MAX_SAFE_INTEGER || alertId < 0) return;

const alertData = await db.transaction('rw', db.alerts, async () => {
Expand All @@ -287,7 +310,7 @@ alertsDB.version(1).stores({
browser.notifications.onClosed.addListener(async (notificationId) => {
if (!notificationId.startsWith(prefix)) return;

const alertId = Number.parseInt(notificationId.substr(prefix.length));
const alertId = Number.parseInt(notificationId.substring(prefix.length));
const alert = await getAlert(alertId);
if (alert) {
if (alert.delete) {
Expand All @@ -298,7 +321,8 @@ alertsDB.version(1).stores({
}
});


// upon start cleanup alerts which didn't get removed properly.
cleanupAlerts();

return {
getValidData: getValidateAlertData,
Expand Down Expand Up @@ -329,8 +353,6 @@ alertsDB.version(1).stores({
})();




browser.runtime.onInstalled.addListener(() => {
"use strict";
const version = browser.runtime.getManifest().version;
Expand Down Expand Up @@ -401,6 +423,7 @@ alertsDB.version(1).stores({
return {ok: true, data: data};
}


/**
* creates the return value for an error
* @param {string} message the error message
Expand All @@ -410,6 +433,7 @@ alertsDB.version(1).stores({
return {ok: false, error: message};
}


/**
* handles internal and external extension communication
* @param {any} request
Expand Down Expand Up @@ -616,38 +640,13 @@ alertsDB.version(1).stores({
}

case 'send2Api': { // type
let xhr = new XMLHttpRequest();

xhr.open('POST', request.url);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(request.data);

return APIsuccess(true);
}

case 'setInnoCDN': { // type
localStorage.setItem('InnoCDN', request.url);
return APIsuccess(true);
}

case 'getInnoCDN': { // type
let cdnUrl = localStorage.getItem('InnoCDN');
return APIsuccess([cdnUrl || defaultInnoCDN, cdnUrl != null]);
}

case 'setPlayerData': { // type
const data = request.data;

const playerdata = JSON.parse(localStorage.getItem('PlayerIdentities') || '{}');
playerdata[data.world+'-'+data.player_id] = data;
localStorage.setItem('PlayerIdentities', JSON.stringify(playerdata));

return APIsuccess(true);
}

case 'getPlayerData': { // type
const playerdata = JSON.parse(localStorage.getItem('PlayerIdentities') || '{}');
return APIsuccess(playerdata[request.world+'-'+request.player_id]);
fetch(request.url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: request.data
});
}

case 'showNotification': { // type
Expand All @@ -666,8 +665,7 @@ alertsDB.version(1).stores({
});
}
catch( error ){
console.error('NotificationManager.notify:');
console.error( error );
console.error('NotificationManager.notify: ', error );
return APIsuccess(false);
}
return APIsuccess(true);
Expand Down Expand Up @@ -704,6 +702,7 @@ alertsDB.version(1).stores({
return APIerror(`unknown request type: ${type}`);
}


browser.runtime.onMessage.addListener(handleWebpageRequests);
browser.runtime.onMessageExternal.addListener(handleWebpageRequests);

Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog - Extension

##### 1.22.0.0
**FoE-Helfer**
- Alle relevanten Änderungen und Bugfixes bis einschließlich FoE Helfer 3.0.0.1 migriert

##### 1.21.1.0
**Bugfix**
- Kostenrechner
Expand Down
52 changes: 32 additions & 20 deletions content/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,38 @@
<link href="../css/popup.css" rel="stylesheet">
</head>
<body>
<h5 data-translate="title">FoE Toolbox</h5>

<p data-translate="desc">
Viele Dank für die tolle Arbeit des FoE Helfer Teams. Diese Erweiterung besteht fast ausschließlich aus einer inoffiziellen 1:1 Kopie des FoE Helfers und wir nur durch einige kleinere Optimierungen ergänzt, die nicht in den Helfer Einzug finden werden.<br><br>
Dir gefällt diese kleine kostenlose Extension und du möchtest sie supporten damit das weiterhin so bleibt?<br> Dann ist jede kleine Spende für den Support des original FoE Helfer Teams immer gern gesehen.
</p>

<p class="text-center">
<span class="paypal-link">
<img class="img-fluid" src="../css/images/paypal-donate.jpg" alt="PayPal Donation">
</span>
</p>

<p data-translate="thanks">
Vielen Dank! <a href="alerts.html" class="text-right">Alerts</a>
</p>

<p class="text-right mt-3 mb-0">
<small class="text-muted">&copy; 2021 - <span class="foe-link">foe-helper.com</span></small>
</p>
<section>
<h3 data-translate="title">FoE Toolbox</h3>
<p data-translate="intro">Eine inoffizielle Browser-Erweiterung für Forge of Empires.</p>
</section>
<section id="links">
<ul class="helplist">
<li><a href="https://discord.gg/z97KZq4" target="_blank"><span class="discord">&nbsp;</span>Discord des FoE Helfer Teams</a></li>
<li><a href="https://github.com/mainIine/foe-helfer-extension/issues" target="_blank"><span class="github">&nbsp;</span>GitHub des FoE Helfers</a></li>
<li><a href="https://foe-helper.com" target="_blank"><span class="website">&nbsp;</span>FoE Helfer Website</a></li>
<li><a href="https://github.com/sdn-br/foe-toolbox/issues" target="_blank"><span class="github">&nbsp;</span>Github der FoE Toolbox</a></li>
</ul>
</section>
<section id="donate">
<h3 data-translate="donate">Spenden</h3>
<p>
<span data-translate="desc">Viele Dank für die tolle Arbeit des FoE Helfer Teams. Diese Erweiterung besteht fast ausschließlich aus einer inoffiziellen 1:1 Kopie des FoE Helfers und wir nur durch einige kleinere Optimierungen ergänzt, die nicht in den Helfer Einzug finden werden.<br><br>Wenn dir diese kleine kostenlose Extension gefällt und du sie supporten möchtest, damit das weiterhin so bleibt, dann spende gerne für das FoE Helfer Team.</span>
<span data-translate="thanks">
Vielen Dank!
</span>
</p>
<p>
<span class="paypal-link">
<img src="../css/images/paypal-donate.png" alt="PayPal Donation">
</span>
</p>
<p>
<br><span ><a href="alerts.html" class="text-right">Alerts</a></span>
</p>
</section>
<footer class="text-right">
<small class="text-muted">&copy; 2022 - <span class="foe-link">foe-helper.com</span></small>
</footer>

<script src="/vendor/jQuery/jquery.min.js"></script>
<script src="../js/popup.js"></script>
Expand Down
Binary file modified css/images/menu/discord.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added css/images/menu/negotation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed css/images/menu/negotiation.png
Binary file not shown.
Binary file modified css/images/menu/recurringQuests.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed css/images/paypal-donate.jpg
Binary file not shown.
Binary file added css/images/paypal-donate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 97 additions & 3 deletions css/popup.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* **************************************************************************************
* Copyright (C) 2021 FoE-Helper team - All Rights Reserved
* Copyright (C) 2022 FoE-Helper team - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the AGPL license.
*
Expand All @@ -12,8 +12,33 @@
*/

body {
min-width: 350px;
padding: 25px;
min-width: 300px;
background-color: #fff;
margin: 0;
font-size: 1em;
}

body > section, body > footer {
padding: 15px;
}

p {
margin: 0.25rem 0 0.5rem;
}

p:last-child {
margin-bottom: 0;
}

section {
border-bottom: 1px solid #ccc;
}

h3 {
color: #1573d4;
font-weight: bold;
margin: 0;
font-size: 1.1em;
}

.foe-link {
Expand All @@ -22,5 +47,74 @@ body {
}

.paypal-link {
text-align: center;
display: block;
}

.paypal-link img {
cursor: pointer;
width: 160px;
}

footer {
background-color: #eee;
font-size: 90%;
text-align: right;
}

#links {
background-color: #333;
font-size: 85%;
padding: 5px 0 2px;
}

#donate {
font-size: 90%;
}

.helplist {
margin: 0;
list-style: none;
padding: 0;
text-align: center;
}

.helplist li {
display: inline-block;
margin: 0;
}

.helplist a {
text-decoration: none;
display: block;
overflow: hidden;
padding: 5px;
color: var(--text-normal);
line-height: 26px;
color: #eee;
}

.helplist li span {
display: inline-block;
background-color: #000;
width: 30px;
height: 32px;
margin-right: 3px;
background: url('../js/web/settings/images/help.png') 0 0 no-repeat;
text-decoration: none;
}

.helplist .discord {
background-position: -33px 0;
}

.helplist .forums {
background-position: -63px 0;
width: 34px;
margin-right: 4px;
}

.helplist .website {
background-position: -97px 0;
width: 32px;
}
Loading

0 comments on commit 3370f48

Please sign in to comment.