Skip to content

Commit

Permalink
new build scripts divided by browser (manifest v2 for firefox, v3 for…
Browse files Browse the repository at this point in the history
… chrome), firefox works now!, exchangeratestore now periodically fetches prices in the background if dogmoneymode is enabled
  • Loading branch information
UsaRandom committed Oct 15, 2023
1 parent 8df66b8 commit c2a41ce
Show file tree
Hide file tree
Showing 17 changed files with 1,223 additions and 38 deletions.
28 changes: 15 additions & 13 deletions build/manifest.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
{
"manifest_version": 3,
"manifest_version": 2,
"name": "DogMoneyMode",
"version": "2.0",
"description": "Browser extension that makes fiat prices display in Dogecoin. Works with USD, EUR, GRB, ",
"version": "2.1",
"description": "Browser extension that makes fiat prices display in Dogecoin. Works with USD, EUR, GBP, etc.",
"permissions": ["storage"],
"action": {
"browser_action": {
"default_popup": "popup.html"
},
"icons": {
"16": "images/icon-16.png",
"32": "images/icon-32.png",
"48": "images/icon-48.png",
"128": "images/icon-128.png"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"css": ["styles/comic.css"],
"js": ["scripts/content.js"],
"matches": [
"<all_urls>"
],
"all_frames": true
}
],
"background": {
"scripts": ["scripts/background.js"],
"persistent": true
},
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "109.0"
"gecko": {
"id": "[email protected]",
"strict_min_version": "109.0"
}
}
}
}
}

2 changes: 1 addition & 1 deletion build/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,6 @@ <h3 style="margin-bottom: 0px;">Comic Sans Mode:</h3>
</label>
<a id="tips" href="#"><em>Tips:</em> D6hbn1AugHq3WVtTVSv1fZAg6atPAMtwuV</a>-->
<script src="scripts\popup.js"></script>
<script src="scripts/popup.js"></script>
</body>
</html>
112 changes: 112 additions & 0 deletions build/scripts/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/******/ (() => { // webpackBootstrap
/******/ "use strict";
var __webpack_exports__ = {};

;// CONCATENATED MODULE: ./src/ExchangeRateStore.js
class ExchangeRateStore {
constructor() {
this.localStorageKey = 'dmm-exchange-rates';
this.timeToLive = 120000; // 2 minutes in milliseconds
}

async _fetchRates() {
const response = await fetch('https://api.coingecko.com/api/v3/simple/price?ids=dogecoin&vs_currencies=USD,EUR,CNY,JPY,GBP,INR,RUB');
const data = await response.json();
const rates = data.dogecoin;
const updatedOn = Date.now();

const storageObject = {
updatedOn,
rates,
};

return new Promise((resolve, reject) => {
chrome.storage.local.set({ [this.localStorageKey]: storageObject }, () => {
if (chrome.runtime.lastError) {
return reject(chrome.runtime.lastError);
}
resolve(storageObject);
});
});
}

async getRates(isContentScript = true) {
return new Promise((resolve, reject) => {
chrome.storage.local.get(this.localStorageKey, async (result) => {
let storedData = result[this.localStorageKey];
if (!isContentScript && (!storedData || Date.now() - storedData.updatedOn > this.timeToLive)) {
try {
storedData = await this._fetchRates();
} catch (error) {
return reject(error);
}
}
resolve(storedData.rates);
});
});
}
}



;// CONCATENATED MODULE: ./src/AppStateStore.js
class AppStateStore {
constructor() {
this.localStorageKey = 'dmm-app-state';
}

async setAppState(stateObj) {
const obj = {};
obj[this.localStorageKey] = stateObj;
return new Promise((resolve, reject) => {
chrome.storage.local.set(obj, () => {
if (chrome.runtime.lastError) {
return reject(chrome.runtime.lastError);
}
resolve();
});
});
}

async getAppState() {
return new Promise((resolve, reject) => {
chrome.storage.local.get(this.localStorageKey, (result) => {
if (chrome.runtime.lastError) {
return reject(chrome.runtime.lastError);
}
resolve(result[this.localStorageKey] || {"dogMoneyModeEnabled": false, "comicSansModeEnabled": false});
});
});
}
}



;// CONCATENATED MODULE: ./src/background.js



const appStateStore = new AppStateStore();
const exchangeRateStore = new ExchangeRateStore();
const refreshTimeMs = 45000;

(async () => {
let state = await appStateStore.getAppState();
let exchangeRates = await exchangeRateStore.getRates(false);

setInterval(async () => {
try {
state = await appStateStore.getAppState();

if (state.dogMoneyModeEnabled) {
const rates = await exchangeRateStore.getRates(false);
console.log('Rates fetched:', rates);
}
} catch (error) {
console.error('Error fetching rates:', error);
}
}, refreshTimeMs);
})();

/******/ })()
;
Loading

0 comments on commit c2a41ce

Please sign in to comment.