From f6253b890808f22d779e05587c93049ae7375641 Mon Sep 17 00:00:00 2001 From: dessant Date: Thu, 2 Nov 2023 19:15:56 +0200 Subject: [PATCH] feat: search on Icons8 --- src/assets/icons/engines/icons8.svg | 4 ++++ src/assets/locales/en/messages.json | 15 ++++++++++++ src/engines/icons8.js | 23 +++++++++++++++++++ src/storage/config.json | 3 ++- .../local/20231102164602_add_icons8.js | 20 ++++++++++++++++ src/utils/data.js | 12 ++++++++-- 6 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 src/assets/icons/engines/icons8.svg create mode 100644 src/engines/icons8.js create mode 100644 src/storage/revisions/local/20231102164602_add_icons8.js diff --git a/src/assets/icons/engines/icons8.svg b/src/assets/icons/engines/icons8.svg new file mode 100644 index 0000000..86e3b9b --- /dev/null +++ b/src/assets/icons/engines/icons8.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/assets/locales/en/messages.json b/src/assets/locales/en/messages.json index 2b7366e..d7d4a90 100644 --- a/src/assets/locales/en/messages.json +++ b/src/assets/locales/en/messages.json @@ -249,6 +249,11 @@ "description": "Name of the search engine." }, + "engineName_icons8": { + "message": "Icons8", + "description": "Name of the search engine." + }, + "engineName_allEngines": { "message": "all search engines", "description": "Name of the search engine." @@ -510,6 +515,11 @@ "description": "Title of the menu item." }, + "menuItemTitle_icons8": { + "message": "Icons8", + "description": "Title of the menu item." + }, + "menuItemTitle_allEngines": { "message": "All search engines", "description": "Title of the menu item." @@ -791,6 +801,11 @@ "description": "Title of the option." }, + "optionTitle_icons8": { + "message": "Icons8", + "description": "Title of the option." + }, + "optionTitle_searchMode": { "message": "Search mode", "description": "Title of the option." diff --git a/src/engines/icons8.js b/src/engines/icons8.js new file mode 100644 index 0000000..2ab2032 --- /dev/null +++ b/src/engines/icons8.js @@ -0,0 +1,23 @@ +import {findNode} from 'utils/common'; +import {setFileInputData, initSearch, sendReceipt} from 'utils/engines'; + +const engine = 'icons8'; + +async function search({session, search, image, storageIds}) { + (await findNode('button.search-autocomplete__img-trigger')).click(); + + const inputSelector = 'input#file-input'; + const input = await findNode(inputSelector); + + await setFileInputData(inputSelector, input, image); + + await sendReceipt(storageIds); + + input.dispatchEvent(new Event('input')); +} + +function init() { + initSearch(search, engine, taskId); +} + +init(); diff --git a/src/storage/config.json b/src/storage/config.json index f9ac288..69e110b 100755 --- a/src/storage/config.json +++ b/src/storage/config.json @@ -49,7 +49,8 @@ "20230601115626_add_kagi", "20230624145626_add_search_engines", "20230716121432_add_freepik", - "20231009185955_remove_unsplash" + "20231009185955_remove_unsplash", + "20231102164602_add_icons8" ], "sync": [] } diff --git a/src/storage/revisions/local/20231102164602_add_icons8.js b/src/storage/revisions/local/20231102164602_add_icons8.js new file mode 100644 index 0000000..61af684 --- /dev/null +++ b/src/storage/revisions/local/20231102164602_add_icons8.js @@ -0,0 +1,20 @@ +const message = 'Add Icons8'; + +const revision = '20231102164602_add_icons8'; + +async function upgrade() { + const changes = {}; + const {engines, disabledEngines} = await browser.storage.local.get([ + 'engines', + 'disabledEngines' + ]); + const newEngines = ['icons8']; + + changes.engines = engines.concat(newEngines); + changes.disabledEngines = disabledEngines.concat(newEngines); + + changes.storageVersion = revision; + return browser.storage.local.set(changes); +} + +export {message, revision, upgrade}; diff --git a/src/utils/data.js b/src/utils/data.js index 8ceb8d8..a4b6c24 100755 --- a/src/utils/data.js +++ b/src/utils/data.js @@ -360,6 +360,12 @@ const engines = { target: 'https://www.freepik.com/search', isExec: true } + }, + icons8: { + image: { + target: 'https://icons8.com/', + isExec: true + } } }; @@ -614,7 +620,8 @@ const webpEngineSupport = [ 'haveibeentrained', 'enterpix', 'immerse', - 'clipretrieval' + 'clipretrieval', + 'icons8' ]; // Search engines only support the image format in compatible browsers. @@ -679,7 +686,8 @@ const maxImageUploadSize = { enterpix: {ui: 5 * 1024 * 1024}, immerse: {ui: 10 * 1024 * 1024}, clipretrieval: {ui: 15 * 1024 * 1024}, - freepik: {ui: 60 * 1024 * 1024} + freepik: {ui: 60 * 1024 * 1024}, + icons8: {ui: 5 * 1024 * 1024} }; const chromeDesktopUA =