optimise and fix quote api support for addons

This commit is contained in:
David Ralph
2020-12-05 13:48:14 +00:00
parent 7147dbef30
commit 408f8c4502
5 changed files with 96 additions and 16 deletions

View File

@@ -15,14 +15,15 @@ export default class SearchSettings extends React.PureComponent {
}
componentDidMount() {
if (localStorage.getItem('searchEngine') === 'custom') {
const searchEngine = localStorage.getItem('searchEngine');
if (searchEngine === 'custom') {
const input = document.getElementById('searchEngineInput');
input.style.display = 'block';
input.enabled = 'true';
document.getElementById('customSearchEngine').value = localStorage.getItem('customSearchEngine');
} else localStorage.removeItem('customSearchEngine');
document.getElementById('searchEngine').value = localStorage.getItem('searchEngine');
document.getElementById('searchEngine').value = searchEngine;
}
render() {

View File

@@ -1,5 +1,4 @@
import React from 'react';
import Quotes from '@muetab/quotes';
import FileCopy from '@material-ui/icons/FilterNone';
import { toast } from 'react-toastify';
import * as Constants from '../../../modules/constants';
@@ -9,6 +8,8 @@ import StarIcon2 from '@material-ui/icons/StarBorder';
import './quote.scss';
const quotes = require('./offline_quotes.json');
export default class Quote extends React.PureComponent {
constructor(...args) {
super(...args);
@@ -20,7 +21,7 @@ export default class Quote extends React.PureComponent {
}
doOffline() {
const quote = Quotes.random(); // Get a random quote from our local package
const quote = quotes[Math.floor(Math.random() * quotes.length)]; // Get a random quote from our local package
this.setState({
quote: '"' + quote.quote + '"',
author: quote.author
@@ -42,14 +43,13 @@ export default class Quote extends React.PureComponent {
}
async getQuote() {
const quotePackAPI = JSON.parse(localStorage.getItem('quote_api'));
const quotePackAPI = JSON.parse(localStorage.getItem('quoteAPI'));
if (quotePackAPI) {
try {
const data = await (await fetch(quotePackAPI.url)).json();
const author = quotePackAPI.authorOverride || data[quotePackAPI.author];
return this.setState({
quote: '"' + data[quotePackAPI.quote] + '"',
author: author
quote: '"' + data.quote + '"',
author: quotePackAPI.author || data.author
});
} catch (e) {
return this.getQuotePack();

View File

@@ -0,0 +1,80 @@
[
{
"author": "Robert De Niro",
"quote": "Time goes on. So whatever youre going to do, do it. Do it now. Dont wait."
},
{
"author": "Walt Disney",
"quote": "All our dreams can come true, if we have the courage to pursue them."
},
{
"author": "Confucius",
"quote": "It does not matter how slowly you go as long as you do not stop."
}, {
"author": "Roy T. Bennett",
"quote": "Believe in yourself. You are braver than you think, more talented than you know, and capable of more than you imagine."
}, {
"author": "Wayne Dyer",
"quote": "If you believe it will work out, youll see opportunities. If you believe it wont, you will see obstacles."
}, {
"author": "George Addair",
"quote": "Everything youve ever wanted is on the other side of fear."
}, {
"author": "Winston Churchill",
"quote": "Success is not final, failure is not fatal: it is the courage to continue that counts."
}, {
"author": "Paulo Coelho",
"quote": "There is only one thing that makes a dream impossible to achieve: the fear of failure"
}, {
"author": "Brian Tracy",
"quote": "Your true success in life begins only when you make the commitment to become excellent at what you do."
}, {
"author": "Chantal Sutherland",
"quote": "Believe in yourself, take on your challenges, dig deep within yourself to conquer fears. Never let anyone bring you down. You got to keep going."
}, {
"author": "Les Brown",
"quote": "Too many of us are not living our dreams because we are living our fears."
}, {
"author": "Bob Riley",
"quote": "Hard times dont create heroes. It is during the hard times when the hero within us is revealed."
}, {
"author": "Jack Canfield",
"quote": "If you can tune into your purpose and really align with it, setting goals so that your vision is an expression of that purpose, then life flows much more easily."
}, {
"author": "Napolean Hill",
"quote": "Whatever the mind can conceive and believe, it can achieve."
}, {
"author": "Jim Rohn",
"quote": "Dont wish it were easier. Wish you were better."
}, {
"author": "Serena Williams",
"quote": "A champion is defined not by their wins but by how they can recover when they fall."
}, {
"author": "Sheryl Sandberg",
"quote": "Motivation comes from working on things we care about."
}, {
"author": "Reese Witherspoon",
"quote": "With the right kind of coaching and determination you can accomplish anything."
}, {
"author": "Hazrat Inayat Khan",
"quote": "Some people look for a beautiful place. Others make a place beautiful."
}, {
"author": "Albert Einstein",
"quote": "Life is like riding a bicycle. To keep your balance, you must keep moving."
}, {
"author": "Walt Disney",
"quote": "The way to get started is to quit talking and begin doing."
}, {
"author": "Winston Churchill",
"quote": "A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty."
}, {
"author": "Will Rogers",
"quote": "Don't let yesterday take up too much of today."
}, {
"author": "Vince Lombardi",
"quote": "It's not whether you get knocked down, it's whether you get up."
}, {
"author": "Steve Jobs",
"quote": "If you are working on something that you really care about, you dont have to be pushed. The vision pulls you."
}
]