Skip to content

Commit

Permalink
feat: search on Lenso.ai
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Jan 7, 2025
1 parent 1cbaf95 commit 2efa8d1
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/assets/icons/engines/lenso-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/assets/icons/engines/lenso.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/assets/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@
"description": "Name of the search engine."
},

"engineName_lenso": {
"message": "Lenso.ai",
"description": "Name of the search engine."
},

"engineName_allEngines": {
"message": "all search engines",
"description": "Name of the search engine."
Expand Down Expand Up @@ -480,6 +485,11 @@
"description": "Title of the menu item."
},

"menuItemTitle_lenso": {
"message": "Lenso.ai",
"description": "Title of the menu item."
},

"menuItemTitle_allEngines": {
"message": "All search engines",
"description": "Title of the menu item."
Expand Down Expand Up @@ -746,6 +756,11 @@
"description": "Title of the option."
},

"optionTitle_lenso": {
"message": "Lenso.ai",
"description": "Title of the option."
},

"optionTitle_searchMode": {
"message": "Search mode",
"description": "Title of the option."
Expand Down
52 changes: 52 additions & 0 deletions src/engines/lenso.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {findNode, runOnce} from 'utils/common';
import {setFileInputData, initSearch, sendReceipt} from 'utils/engines';

const engine = 'lenso';

async function search({session, search, image, storageIds}) {
if (search.assetType === 'image') {
const inputSelector = 'input[type=file]';
const input = await findNode(inputSelector);

await setFileInputData(inputSelector, input, image);

await sendReceipt(storageIds);

input.dispatchEvent(new Event('change'));

const modal = await findNode('.manage-consents-modal', {
timeout: 10000,
throwError: false
});

if (modal) {
(
await findNode('label[for="privacy-policy"]', {rootNode: modal})
).click();

(
await findNode('button.perfom-search-btn:not([disabled])', {
rootNode: modal,
observerOptions: {attributes: true}
})
).click();
}
} else {
await sendReceipt(storageIds);

(
await findNode('.search-by-url .cta-btn', {
timeout: 10000,
throwError: false
})
).click();
}
}

function init() {
initSearch(search, engine, taskId);
}

if (runOnce('search')) {
init();
}
3 changes: 2 additions & 1 deletion src/storage/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"20240514170322_add_appversion",
"20240529183556_update_search_engines",
"20240619180111_add_menuchangeevent",
"20240624161944_remove_search_engines"
"20240624161944_remove_search_engines",
"20250102095603_add_lenso.ai"
],
"session": [
"20240514122825_initial_version"
Expand Down
30 changes: 30 additions & 0 deletions src/storage/revisions/local/20250102095603_add_lenso.ai.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const message = 'Add Lenso.ai';

const revision = '20250102095603_add_lenso.ai';

async function upgrade() {
const changes = {};
const {engines, disabledEngines} = await browser.storage.local.get([
'engines',
'disabledEngines'
]);
const newEngine = 'lenso';

const enabledEngineCount = engines.length - disabledEngines.length;

engines.splice(1, 0, newEngine);
changes.engines = engines;

if (enabledEngineCount <= 1) {
disabledEngines.push(newEngine);
}
if (enabledEngineCount === 8 && !disabledEngines.includes('alamy')) {
disabledEngines.push('alamy');
}
changes.disabledEngines = disabledEngines;

changes.storageVersion = revision;
return browser.storage.local.set(changes);
}

export {message, revision, upgrade};
19 changes: 16 additions & 3 deletions src/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@ const engines = {
target: 'https://icons8.com/',
isExec: true
}
},
lenso: {
url: {
target: 'https://lenso.ai/en/search-by-url?url={imgUrl}&utm_source=sbi',
isExec: true
},
image: {
target: 'https://lenso.ai/en?utm_source=sbi',
isExec: true
}
}
};

Expand All @@ -365,7 +375,8 @@ const engineIconVariants = {
ascii2d: ['dark'],
tmview: ['dark'],
pixta: ['dark'],
freepik: ['dark']
freepik: ['dark'],
lenso: ['dark']
};

const rasterEngineIcons = [
Expand Down Expand Up @@ -590,7 +601,8 @@ const webpEngineSupport = [
'lykdat',
'googleLens',
'lexica',
'icons8'
'icons8',
'lenso'
];

// Search engines only support the image format in compatible browsers.
Expand Down Expand Up @@ -651,7 +663,8 @@ const maxImageUploadSize = {
lexica: {ui: 30 * 1024 * 1024},
kagi: {ui: 1 * 1024 * 1024},
freepik: {ui: 60 * 1024 * 1024},
icons8: {ui: 5 * 1024 * 1024}
icons8: {ui: 5 * 1024 * 1024},
lenso: {ui: 10 * 1024 * 1024}
};

const chromeDesktopUA =
Expand Down

0 comments on commit 2efa8d1

Please sign in to comment.