Skip to content

Commit

Permalink
feat: search with Reddit Repost Sleuth
Browse files Browse the repository at this point in the history
Closes #132.
  • Loading branch information
dessant committed Jul 18, 2021
1 parent d1aeec4 commit 872ef2d
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@
"description": "Name of the search engine."
},

"engineName_repostSleuth": {
"message": "Reddit Repost Sleuth",
"description": "Name of the search engine."
},

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

"menuItemTitle_repostSleuth": {
"message": "Reddit Repost Sleuth",
"description": "Title of the menu item."
},

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

"optionTitle_repostSleuth": {
"message": "Reddit Repost Sleuth",
"description": "Title of the option."
},

"optionTitle_searchMode": {
"message": "Search mode",
"description": "Title of the option."
Expand Down
6 changes: 5 additions & 1 deletion src/action/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ export default {
getEngineIcon: function (engine) {
let ext = 'svg';
if (['iqdb', 'karmaDecay', 'tineye', 'whatanime'].includes(engine)) {
if (
['iqdb', 'karmaDecay', 'tineye', 'whatanime', 'repostSleuth'].includes(
engine
)
) {
ext = 'png';
} else if (['branddb', 'madridMonitor'].includes(engine)) {
engine = 'wipo';
Expand Down
6 changes: 5 additions & 1 deletion src/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ function setContentRequestHeaders(token, url, {referrer = ''} = {}) {
}

function getEngineMenuIcons(engine) {
if (['iqdb', 'karmaDecay', 'tineye', 'whatanime'].includes(engine)) {
if (
['iqdb', 'karmaDecay', 'tineye', 'whatanime', 'repostSleuth'].includes(
engine
)
) {
return {
16: `src/icons/engines/${engine}-16.png`,
32: `src/icons/engines/${engine}-32.png`
Expand Down
33 changes: 33 additions & 0 deletions src/engines/repostSleuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {findNode} from 'utils/common';
import {setFileInputData, initSearch, sendReceipt} from 'utils/engines';

const engine = 'repostSleuth';

async function search({task, search, image, storageKeys}) {
if (search.method === 'upload') {
const inputSelector = 'input[type=file]';
const input = await findNode(inputSelector);

await setFileInputData(inputSelector, input, image);

await sendReceipt(storageKeys);

input.dispatchEvent(new Event('change'));
} else {
const input = await findNode('input[placeholder="https://redd.it/xyz"]');

input.value = image.imageUrl;

await sendReceipt(storageKeys);

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

(await findNode('main button.primary')).click();
}

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

init();
Binary file added src/icons/engines/repostSleuth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions src/storage/versions/local/K9Esw2jiQ3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import browser from 'webextension-polyfill';

const message = 'Add Reddit Repost Sleuth';

const revision = 'K9Esw2jiQ3';
const downRevision = 'IMMjiccGj';

const storage = browser.storage.local;

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

changes.engines = engines.concat('repostSleuth');
changes.disabledEngines = disabledEngines.concat('repostSleuth');

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

async function downgrade() {
const changes = {};
const {engines, disabledEngines} = await storage.get([
'engines',
'disabledEngines'
]);

changes.engines = engines.filter(function (item) {
return item !== 'repostSleuth';
});
changes.disabledEngines = disabledEngines.filter(function (item) {
return item !== 'repostSleuth';
});

changes.storageVersion = downRevision;
return storage.set(changes);
}

export {message, revision, upgrade, downgrade};
3 changes: 2 additions & 1 deletion src/storage/versions/local/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"UhWEtK9gMh",
"TshBYj8anA",
"ggrr9C9pgV",
"IMMjiccGj"
"IMMjiccGj",
"K9Esw2jiQ3"
]
}
42 changes: 42 additions & 0 deletions src/storage/versions/sync/K9Esw2jiQ3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import browser from 'webextension-polyfill';

const message = 'Add Reddit Repost Sleuth';

const revision = 'K9Esw2jiQ3';
const downRevision = 'IMMjiccGj';

const storage = browser.storage.sync;

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

changes.engines = engines.concat('repostSleuth');
changes.disabledEngines = disabledEngines.concat('repostSleuth');

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

async function downgrade() {
const changes = {};
const {engines, disabledEngines} = await storage.get([
'engines',
'disabledEngines'
]);

changes.engines = engines.filter(function (item) {
return item !== 'repostSleuth';
});
changes.disabledEngines = disabledEngines.filter(function (item) {
return item !== 'repostSleuth';
});

changes.storageVersion = downRevision;
return storage.set(changes);
}

export {message, revision, upgrade, downgrade};
3 changes: 2 additions & 1 deletion src/storage/versions/sync/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"UhWEtK9gMh",
"TshBYj8anA",
"ggrr9C9pgV",
"IMMjiccGj"
"IMMjiccGj",
"K9Esw2jiQ3"
]
}
12 changes: 12 additions & 0 deletions src/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,18 @@ const engines = {
target: 'https://www.ikea.com/',
isExec: true
}
},
repostSleuth: {
url: {
target:
'https://repostsleuth.com/search?targetImageMatch=60&filterSameAuthor=false',
isExec: true
},
upload: {
target:
'https://repostsleuth.com/search?targetImageMatch=60&filterSameAuthor=false',
isExec: true
}
}
};

Expand Down

0 comments on commit 872ef2d

Please sign in to comment.