Skip to content

Commit 22c674a

Browse files
committed
feat: search on Ghostarchive
Closes #41.
1 parent df7c7ce commit 22c674a

File tree

7 files changed

+79
-5
lines changed

7 files changed

+79
-5
lines changed
7.14 KB
Loading

src/assets/locales/en/messages.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969
"description": "Name of the search engine."
7070
},
7171

72+
"engineName_ghostarchive": {
73+
"message": "Ghostarchive",
74+
"description": "Name of the search engine."
75+
},
76+
7277
"engineName_allEngines": {
7378
"message": "All search engines",
7479
"description": "Name of the search engine."
@@ -150,6 +155,11 @@
150155
"description": "Title of the menu item."
151156
},
152157

158+
"menuItemTitle_ghostarchive": {
159+
"message": "Ghostarchive",
160+
"description": "Title of the menu item."
161+
},
162+
153163
"menuItemTitle_allEngines": {
154164
"message": "All search engines",
155165
"description": "Title of the menu item."
@@ -246,6 +256,11 @@
246256
"description": "Title of the option."
247257
},
248258

259+
"optionTitle_ghostarchive": {
260+
"message": "Ghostarchive",
261+
"description": "Title of the option."
262+
},
263+
249264
"optionTitle_searchMode": {
250265
"message": "Search mode",
251266
"description": "Title of the option."

src/engines/ghostarchive.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {validateUrl} from 'utils/app';
2+
import {findNode} from 'utils/common';
3+
import {initSearch, sendReceipt} from 'utils/engines';
4+
5+
const engine = 'ghostarchive';
6+
7+
async function search({session, search, doc, storageIds}) {
8+
const link = await findNode('#bodyContent table td a', {
9+
throwError: false,
10+
timeout: 10000
11+
});
12+
13+
await sendReceipt(storageIds);
14+
15+
if (link) {
16+
const tabUrl = link.href;
17+
18+
if (validateUrl(tabUrl)) {
19+
window.location.href = tabUrl;
20+
}
21+
}
22+
}
23+
24+
function init() {
25+
initSearch(search, engine, taskId);
26+
}
27+
28+
init();

src/storage/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"20230201232239_remove_search_engines",
1414
"20230703074609_remove_gigablast",
1515
"20230704125533_remove_opencurrentdocaction",
16-
"20230713165504_add_perma.cc"
16+
"20230713165504_add_perma.cc",
17+
"20230715152710_add_ghostarchive"
1718
],
1819
"sync": []
1920
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const message = 'Add Ghostarchive';
2+
3+
const revision = '20230715152710_add_ghostarchive';
4+
5+
async function upgrade() {
6+
const changes = {};
7+
const {engines, disabledEngines} = await browser.storage.local.get([
8+
'engines',
9+
'disabledEngines'
10+
]);
11+
12+
const newEngines = ['ghostarchive'];
13+
14+
changes.engines = engines.concat(newEngines);
15+
changes.disabledEngines = disabledEngines.concat(newEngines);
16+
17+
changes.storageVersion = revision;
18+
return browser.storage.local.set(changes);
19+
}
20+
21+
export {message, revision, upgrade};

src/tools/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ function main() {
4949
docUrl = document.querySelector('#yandex-cache-hdr > span > a')?.href;
5050
} else if (engine === 'permacc') {
5151
docUrl = document.querySelector('._livepage a')?.href;
52+
} else if (engine === 'ghostarchive') {
53+
docUrl = document.querySelector('#searchInput')?.value;
5254
}
5355

5456
break;

src/utils/data.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ const engines = {
6161
permacc: {
6262
target: searchUrl,
6363
isTaskId: true
64+
},
65+
ghostarchive: {
66+
target: 'https://ghostarchive.org/search?term={url}',
67+
isExec: true
6468
}
6569
};
6670

@@ -76,7 +80,7 @@ const engineIconVariants = {
7680
yahoo: ['dark']
7781
};
7882

79-
const rasterEngineIcons = [];
83+
const rasterEngineIcons = ['ghostarchive'];
8084

8185
// prettier-ignore
8286
const errorCodes = [
@@ -123,7 +127,8 @@ const pageArchiveHosts = {
123127
google: ['webcache.googleusercontent.com'],
124128
bing: ['cc.bingj.com'],
125129
yandex: ['yandexwebcache.net'],
126-
permacc: ['perma.cc', 'rejouer.perma.cc']
130+
permacc: ['perma.cc', 'rejouer.perma.cc'],
131+
ghostarchive: ['ghostarchive.org']
127132
};
128133

129134
const linkArchiveHosts = {
@@ -139,7 +144,8 @@ const linkArchiveHosts = {
139144
'archiveiya74codqgiixo33q62qlrqtkgmcitqx5u2oeqnmn5bpcbiyd.onion'
140145
],
141146
google: ['webcache.googleusercontent.com'],
142-
permacc: ['rejouer.perma.cc']
147+
permacc: ['rejouer.perma.cc'],
148+
ghostarchive: ['ghostarchive.org']
143149
};
144150

145151
const linkArchiveUrlRx = {
@@ -148,7 +154,8 @@ const linkArchiveUrlRx = {
148154
/^https?:\/\/(?:archive\.(?:is|today|ph|vn|fo|li|md)|archiveiya74codqgiixo33q62qlrqtkgmcitqx5u2oeqnmn5bpcbiyd.onion)\/o\/.*?\/(.*)/i,
149155
google:
150156
/^https?:\/\/webcache\.googleusercontent\.com\/search.*[?&]q=cache:.*$/i,
151-
permacc: /^https:\/\/rejouer\.perma\.cc\/(?:.*)\/mp_\/(.*)/i
157+
permacc: /^https:\/\/rejouer\.perma\.cc\/(?:.*)\/mp_\/(.*)/i,
158+
ghostarchive: /^https:\/\/ghostarchive\.org\/(?:.*)\/mp_\/(.*)/i
152159
};
153160

154161
const chromeDesktopUA =

0 commit comments

Comments
 (0)