mirror of https://github.com/mue/mue.git
chore: update quicklink and autocomplete apis
This commit is contained in:
parent
271af64d07
commit
2684277a76
|
@ -17,10 +17,6 @@
|
|||
"48": "icons/48x48.png",
|
||||
"128": "icons/128x128.png"
|
||||
},
|
||||
"content_security_policy": {
|
||||
"extension_pages": "script-src 'self'; object-src 'self'",
|
||||
"sandbox": "script-src 'self' https://api.bing.com https://www.google.com; object-src 'self'"
|
||||
},
|
||||
"background": {
|
||||
"service_worker": "background-chrome.js"
|
||||
}
|
||||
|
|
|
@ -17,9 +17,5 @@
|
|||
},
|
||||
"chrome_settings_overrides": {
|
||||
"homepage": "index.html"
|
||||
},
|
||||
"content_security_policy": {
|
||||
"extension_pages": "script-src 'self'; object-src 'self'",
|
||||
"sandbox": "script-src 'self' https://api.bing.com https://www.google.com; object-src 'self'"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ export default class QuickLinks extends PureComponent {
|
|||
showAddModal: false,
|
||||
urlError: '',
|
||||
edit: false,
|
||||
editData: ''
|
||||
editData: '',
|
||||
};
|
||||
this.quicklinksContainer = createRef();
|
||||
}
|
||||
|
@ -75,23 +75,23 @@ export default class QuickLinks extends PureComponent {
|
|||
this.setState({
|
||||
items: data,
|
||||
showAddModal: false,
|
||||
urlError: ''
|
||||
urlError: '',
|
||||
});
|
||||
|
||||
variables.stats.postEvent('feature', 'Quicklink add');
|
||||
};
|
||||
}
|
||||
|
||||
startEditLink(data) {
|
||||
this.setState({
|
||||
edit: true,
|
||||
editData: data,
|
||||
showAddModal: true
|
||||
showAddModal: true,
|
||||
});
|
||||
}
|
||||
|
||||
editLink(og, name, url, icon) {
|
||||
const data = JSON.parse(localStorage.getItem('quicklinks'));
|
||||
const dataobj = data.find(i => i.key === og.key);
|
||||
const dataobj = data.find((i) => i.key === og.key);
|
||||
dataobj.name = name || url;
|
||||
dataobj.url = url;
|
||||
dataobj.icon = icon || '';
|
||||
|
@ -101,7 +101,7 @@ export default class QuickLinks extends PureComponent {
|
|||
this.setState({
|
||||
items: data,
|
||||
showAddModal: false,
|
||||
edit: false
|
||||
edit: false,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,6 @@ export default class QuickLinks extends PureComponent {
|
|||
rel = 'noopener noreferrer';
|
||||
}
|
||||
|
||||
const useProxy = localStorage.getItem('quicklinksddgProxy') !== 'false';
|
||||
const useText = localStorage.getItem('quicklinksText') === 'true';
|
||||
|
||||
const quickLink = (item) => {
|
||||
|
@ -153,17 +152,19 @@ export default class QuickLinks extends PureComponent {
|
|||
);
|
||||
}
|
||||
|
||||
const url = useProxy
|
||||
? 'https://icons.duckduckgo.com/ip2/'
|
||||
: 'https://www.google.com/s2/favicons?sz=32&domain=';
|
||||
const img =
|
||||
item.icon ||
|
||||
url + item.url.replace('https://', '').replace('http://', '') + (useProxy ? '.ico' : '');
|
||||
'https://icon.horse/icon/ ' + item.url.replace('https://', '').replace('http://', '');
|
||||
|
||||
const link = (
|
||||
<div className="messageMap" key={item.key}>
|
||||
<div className="icon">
|
||||
<img src={img} alt={item.name} draggable={false} style={{ height: '30px', width: '30px'}} />
|
||||
<img
|
||||
src={img}
|
||||
alt={item.name}
|
||||
draggable={false}
|
||||
style={{ height: '30px', width: '30px' }}
|
||||
/>
|
||||
</div>
|
||||
<div className="messageText">
|
||||
<div className="title">{item.name}</div>
|
||||
|
@ -172,7 +173,7 @@ export default class QuickLinks extends PureComponent {
|
|||
<div>
|
||||
<div className="messageAction">
|
||||
<button className="deleteButton" onClick={() => this.startEditLink(item)}>
|
||||
{variables.getMessage('modals.main.settings.sections.quicklinks.edit')}
|
||||
{variables.getMessage('modals.main.settings.sections.quicklinks.edit')}
|
||||
<MdEdit />
|
||||
</button>
|
||||
<button className="deleteButton" onClick={(e) => this.deleteLink(item.key, e)}>
|
||||
|
@ -183,7 +184,7 @@ export default class QuickLinks extends PureComponent {
|
|||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
return link;
|
||||
};
|
||||
|
||||
|
@ -201,11 +202,6 @@ export default class QuickLinks extends PureComponent {
|
|||
title={variables.getMessage('modals.main.settings.additional_settings')}
|
||||
subtitle={variables.getMessage('modals.main.settings.sections.quicklinks.additional')}
|
||||
>
|
||||
<Checkbox
|
||||
name="quicklinksddgProxy"
|
||||
text={variables.getMessage('modals.main.settings.sections.background.ddg_image_proxy')}
|
||||
category="quicklinks"
|
||||
/>
|
||||
<Checkbox
|
||||
name="quicklinksnewtab"
|
||||
text={variables.getMessage('modals.main.settings.sections.quicklinks.open_new')}
|
||||
|
@ -219,15 +215,22 @@ export default class QuickLinks extends PureComponent {
|
|||
</SettingsItem>
|
||||
<SettingsItem title="Quick Links Styling" description="Customise Quick Links Appearance.">
|
||||
<Dropdown label="Style" name="quickLinksStyle" category="other">
|
||||
<option value="icon">{variables.getMessage('modals.main.settings.sections.quicklinks.options.icon')}</option>
|
||||
<option value="text">{variables.getMessage('modals.main.settings.sections.quicklinks.options.text_only')}</option>
|
||||
<option value="metro">{variables.getMessage('modals.main.settings.sections.quicklinks.options.metro')}</option>
|
||||
<option value="icon">
|
||||
{variables.getMessage('modals.main.settings.sections.quicklinks.options.icon')}
|
||||
</option>
|
||||
<option value="text">
|
||||
{variables.getMessage('modals.main.settings.sections.quicklinks.options.text_only')}
|
||||
</option>
|
||||
<option value="metro">
|
||||
{variables.getMessage('modals.main.settings.sections.quicklinks.options.metro')}
|
||||
</option>
|
||||
</Dropdown>
|
||||
</SettingsItem>
|
||||
|
||||
<SettingsItem title="Quick Links" subtitle="" final={true}>
|
||||
<button onClick={() => this.setState({ showAddModal: true })}>
|
||||
{variables.getMessage('modals.main.settings.sections.quicklinks.add_link')} <MdAddLink />
|
||||
{variables.getMessage('modals.main.settings.sections.quicklinks.add_link')}{' '}
|
||||
<MdAddLink />
|
||||
</button>
|
||||
</SettingsItem>
|
||||
|
||||
|
@ -235,12 +238,14 @@ export default class QuickLinks extends PureComponent {
|
|||
<div className="photosEmpty">
|
||||
<div className="emptyNewMessage">
|
||||
<MdLinkOff />
|
||||
<span className="title">{variables.getMessage('modals.main.settings.sections.quicklinks.no_quicklinks')}</span>
|
||||
<span className="title">
|
||||
{variables.getMessage('modals.main.settings.sections.quicklinks.no_quicklinks')}
|
||||
</span>
|
||||
<span className="subtitle">
|
||||
{variables.getMessage('modals.main.settings.sections.message.add_some')}
|
||||
</span>
|
||||
<button onClick={() => this.setState({ showAddModal: true })}>
|
||||
{variables.getMessage('modals.main.settings.sections.quicklinks.add_link')}
|
||||
{variables.getMessage('modals.main.settings.sections.quicklinks.add_link')}
|
||||
<MdAddLink />
|
||||
</button>
|
||||
</div>
|
||||
|
|
|
@ -6,13 +6,11 @@ import { MenuItem, TextField } from '@mui/material';
|
|||
import Header from '../Header';
|
||||
import Dropdown from '../Dropdown';
|
||||
import Checkbox from '../Checkbox';
|
||||
import Radio from '../Radio';
|
||||
import SettingsItem from '../SettingsItem';
|
||||
|
||||
import EventBus from 'modules/helpers/eventbus';
|
||||
|
||||
import searchEngines from 'components/widgets/search/search_engines.json';
|
||||
import autocompleteProviders from 'components/widgets/search/autocomplete_providers.json';
|
||||
|
||||
export default class SearchSettings extends PureComponent {
|
||||
constructor() {
|
||||
|
@ -145,15 +143,6 @@ export default class SearchSettings extends PureComponent {
|
|||
</p>
|
||||
</SettingsItem>
|
||||
</div>
|
||||
<SettingsItem
|
||||
title={variables.getMessage('modals.main.settings.sections.search.autocomplete_provider')}
|
||||
subtitle={variables.getMessage(
|
||||
'modals.main.settings.sections.search.autocomplete_provider_subtitle',
|
||||
)}
|
||||
final={true}
|
||||
>
|
||||
<Radio options={autocompleteProviders} name="autocompleteProvider" category="search" />
|
||||
</SettingsItem>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -329,15 +329,6 @@ export default class WelcomeSections extends PureComponent {
|
|||
<span className="subtitle">
|
||||
{variables.getMessage('modals.welcome.sections.privacy.offline_mode_description')}
|
||||
</span>
|
||||
<Checkbox
|
||||
name="quicklinksddgProxy"
|
||||
text={
|
||||
variables.getMessage('modals.main.settings.sections.background.ddg_image_proxy') +
|
||||
' (' +
|
||||
variables.getMessage('modals.main.settings.sections.quicklinks.title') +
|
||||
')'
|
||||
}
|
||||
/>
|
||||
<Checkbox
|
||||
name="ddgProxy"
|
||||
text={
|
||||
|
|
|
@ -59,7 +59,6 @@ export default class QuickLinks extends PureComponent {
|
|||
}
|
||||
|
||||
const tooltipEnabled = localStorage.getItem('quicklinkstooltip');
|
||||
const useProxy = localStorage.getItem('quicklinksddgProxy') !== 'false';
|
||||
|
||||
const quickLink = (item) => {
|
||||
if (localStorage.getItem('quickLinksStyle') === 'text') {
|
||||
|
@ -77,12 +76,9 @@ export default class QuickLinks extends PureComponent {
|
|||
);
|
||||
}
|
||||
|
||||
const url = useProxy
|
||||
? 'https://icons.duckduckgo.com/ip2/'
|
||||
: 'https://www.google.com/s2/favicons?sz=32&domain=';
|
||||
const img =
|
||||
item.icon ||
|
||||
url + item.url.replace('https://', '').replace('http://', '') + (useProxy ? '.ico' : '');
|
||||
'https://icon.horse/icon/ ' + item.url.replace('https://', '').replace('http://', '');
|
||||
|
||||
if (localStorage.getItem('quickLinksStyle') === 'metro') {
|
||||
return (
|
||||
|
|
|
@ -10,7 +10,6 @@ import EventBus from 'modules/helpers/eventbus';
|
|||
import './search.scss';
|
||||
|
||||
import searchEngines from 'components/widgets/search/search_engines.json';
|
||||
import autocompleteProviders from 'components/widgets/search/autocomplete_providers.json';
|
||||
|
||||
export default class Search extends PureComponent {
|
||||
constructor() {
|
||||
|
@ -18,9 +17,6 @@ export default class Search extends PureComponent {
|
|||
this.state = {
|
||||
url: '',
|
||||
query: '',
|
||||
autocompleteURL: '',
|
||||
autocompleteQuery: '',
|
||||
autocompleteCallback: '',
|
||||
microphone: null,
|
||||
suggestions: [],
|
||||
searchDropdown: true,
|
||||
|
@ -67,21 +63,15 @@ export default class Search extends PureComponent {
|
|||
window.searchResults = results;
|
||||
};
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.src = `${this.state.autocompleteURL + this.state.autocompleteQuery + input}&${
|
||||
this.state.autocompleteCallback
|
||||
}=window.setResults`;
|
||||
document.head.appendChild(script);
|
||||
const results = await (await fetch(`https://ac.ecosia.org/?q=${input}`)).json();
|
||||
|
||||
try {
|
||||
this.setState({
|
||||
suggestions: window.searchResults[1].splice(0, 3),
|
||||
suggestions: results.suggestions.splice(0, 3),
|
||||
});
|
||||
} catch (e) {
|
||||
// ignore error if empty
|
||||
}
|
||||
|
||||
document.head.removeChild(script);
|
||||
}
|
||||
|
||||
init() {
|
||||
|
@ -110,23 +100,9 @@ export default class Search extends PureComponent {
|
|||
);
|
||||
}
|
||||
|
||||
let autocompleteURL, autocompleteQuery, autocompleteCallback;
|
||||
|
||||
if (localStorage.getItem('autocomplete') === 'true') {
|
||||
const info = autocompleteProviders.find(
|
||||
(i) => i.value === localStorage.getItem('autocompleteProvider'),
|
||||
);
|
||||
autocompleteURL = info.url;
|
||||
autocompleteQuery = info.query;
|
||||
autocompleteCallback = info.callback;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
url,
|
||||
query,
|
||||
autocompleteURL,
|
||||
autocompleteQuery,
|
||||
autocompleteCallback,
|
||||
microphone,
|
||||
currentSearch: info ? info.name : 'Custom',
|
||||
});
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
[
|
||||
{
|
||||
"name": "Google",
|
||||
"value": "google",
|
||||
"url": "https://www.google.com/complete/search?client=chrome",
|
||||
"callback": "callback",
|
||||
"query": "&q="
|
||||
},
|
||||
{
|
||||
"name": "Bing",
|
||||
"value": "bing",
|
||||
"url": "https://api.bing.com/osjson.aspx?JsonType=callback",
|
||||
"callback": "JsonCallback",
|
||||
"query": "&query="
|
||||
}
|
||||
]
|
|
@ -1,4 +1,4 @@
|
|||
import { render } from 'react-dom';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import * as Sentry from '@sentry/react';
|
||||
|
||||
import App from './App';
|
||||
|
@ -57,4 +57,5 @@ Sentry.init({
|
|||
autoSessionTracking: false,
|
||||
});
|
||||
|
||||
render(<App />, document.getElementById('root'));
|
||||
const root = createRoot(document.getElementById('root'));
|
||||
root.render(<App />);
|
||||
|
|
Loading…
Reference in New Issue