mirror of
https://github.com/mue/mue.git
synced 2026-06-06 07:55:48 +02:00
add support for custom quote apis in quote packs
This commit is contained in:
@@ -83,6 +83,7 @@ export default class Marketplace extends React.PureComponent {
|
||||
icon: info.data.screenshot_url
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('marketplace').style.display = 'none';
|
||||
document.getElementById('seemore').style.display = 'none';
|
||||
document.getElementById('item').style.display = 'block';
|
||||
@@ -142,6 +143,7 @@ export default class Marketplace extends React.PureComponent {
|
||||
installStuff();
|
||||
break;
|
||||
case 'quote_packs':
|
||||
if (this.state.current_data.content.data.quoteapi) localStorage.setItem('quote_api', JSON.stringify(this.state.current_data.content.data.quoteapi));
|
||||
localStorage.setItem('quote_packs', JSON.stringify(this.state.current_data.content.data.quotes));
|
||||
installStuff();
|
||||
break;
|
||||
|
||||
@@ -21,7 +21,7 @@ export default class Quote extends React.PureComponent {
|
||||
}); // Set the quote
|
||||
}
|
||||
|
||||
async getQuote() {
|
||||
getQuotePack() {
|
||||
const quotePack = JSON.parse(localStorage.getItem('quote_packs'));
|
||||
if (quotePack) {
|
||||
const data = quotePack[Math.floor(Math.random() * quotePack.length)];
|
||||
@@ -29,6 +29,23 @@ export default class Quote extends React.PureComponent {
|
||||
quote: '"' + data.quote + '"',
|
||||
author: data.author
|
||||
});
|
||||
} else this.doOffline();
|
||||
}
|
||||
|
||||
async getQuote() {
|
||||
const quotePackAPI = JSON.parse(localStorage.getItem('quote_api'));
|
||||
if (quotePackAPI) {
|
||||
try {
|
||||
const data = await (await fetch(quotePackAPI.url)).json();
|
||||
let author = data[quotePackAPI.author];
|
||||
if (quotePackAPI.authorOverride) author = quotePackAPI.authorOverride;
|
||||
return this.setState({
|
||||
quote: '"' + data[quotePackAPI.quote] + '"',
|
||||
author: author
|
||||
});
|
||||
} catch (e) {
|
||||
return this.getQuotePack();
|
||||
}
|
||||
}
|
||||
|
||||
if (localStorage.getItem('offlineMode') === 'true') return this.doOffline();
|
||||
|
||||
@@ -26,6 +26,10 @@ export default class MarketplaceFunctions {
|
||||
oldSettings.forEach(item => localStorage.setItem(item.name, item.value));
|
||||
uninstallStuff();
|
||||
break;
|
||||
case 'quote_pack':
|
||||
localStorage.removeItem('quote_packs');
|
||||
localStorage.removeItem('quote_api');
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
localStorage.removeItem(type);
|
||||
|
||||
Reference in New Issue
Block a user