-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new build scripts divided by browser (manifest v2 for firefox, v3 for…
… chrome), firefox works now!, exchangeratestore now periodically fetches prices in the background if dogmoneymode is enabled
- Loading branch information
Showing
17 changed files
with
1,223 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); | ||
|
||
/******/ })() | ||
; |
Oops, something went wrong.