Skip to content

Commit d6ffcbd

Browse files
committed
feat: support deathcode
1 parent 5acc095 commit d6ffcbd

8 files changed

+206
-21
lines changed
8.46 KB
Loading

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
<img src="icon.png" alt="etherscan logo" width="96" height="96"/>
1+
<img src="icon.png" alt="dethcode logo" width="120" />
22

3-
# Etherscan Suggest
3+
# Etherscan Suggest (with DethCode)
44

5-
Get in-line suggestions from [Etherscan](https://etherscan.io) search results via the **Search Keyword** (default: `eth`). Press <kbd>↩</kbd> to open the contract's page with your default web browser — both the contract's name and its address are valid inputs.
5+
Get in-line suggestions from [Etherscan](https://etherscan.io) via the **Keywords** `eth` (to open in Etherscan) and `deth` (to open the contract's source code on [DethCode](https://etherscan.deth.net)). Press <kbd>↩</kbd> to proceed — both the contract's name and its address are valid inputs.
66

7-
![etherscan-workflow.png](/resources/etherscan-workflow.png)
7+
<p float="left">
8+
<img src="/resources/etherscan-workflow.png" width="48%" />
9+
<img src="/resources/dethcode-workflow.png" width="48%" />
10+
</p>
811

912
## Installation
1013

@@ -13,22 +16,22 @@ Get in-line suggestions from [Etherscan](https://etherscan.io) search results vi
1316
3. Double-click the file to install it in Alfred.
1417
4. Alfred will prompt you to add the workflow to your collection.
1518

16-
That's it! Once the workflow is installed, you can use it by typing in the **Search Keyword** (default: `eth`) followed by a project's name or its address in Alfred.
19+
Once installed, use `eth` to open results in Etherscan and `deth` to view a contract's source code on DethCode. Type in a project's name or its address after the keyword in Alfred.
1720

18-
## Updating the Search Keyword
21+
## Updating the Search Keywords
1922

2023
1. Go to **Alfred Preferences**.
2124
2. Open the **Workflows** tab.
22-
3. Select **Etherscan Suggest**.
23-
4. Click **Configure Workflow...** to set the Search Keyword.
25+
3. Select **Etherscan Suggest (with DethCode)**.
26+
4. Click **Configure Workflow...** to set or modify the **Keywords**.
2427

2528
## Credits
2629

2730
This workflow is inspired by the [Google Suggest](https://alfred.app/workflows/alfredapp/google-suggest/) workflow created by Vítor Galvão.
2831

2932
"This workflow was adapted with the help of ChatGPT, a large language model trained by OpenAI. ChatGPT provided guidance and support during the development process."
3033

31-
If you liked this workflow, try out my other one: [You.com Suggest](https://github.com/zarifpour/alfred-you-suggest/tree/main).
34+
If you enjoyed this workflow, explore my other one: [You.com Suggest](https://github.com/zarifpour/alfred-you-suggest/).
3235

3336
---
3437

icon.png

7.01 KB
Loading

info.plist

Lines changed: 194 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,28 @@
2121
<false/>
2222
</dict>
2323
</array>
24+
<key>BBFB364B-0164-4127-823F-FB71BB608C05</key>
25+
<array>
26+
<dict>
27+
<key>destinationuid</key>
28+
<string>51C6A401-41A1-461F-9C42-C904FA75DC36</string>
29+
<key>modifiers</key>
30+
<integer>0</integer>
31+
<key>modifiersubtext</key>
32+
<string></string>
33+
<key>vitoclose</key>
34+
<false/>
35+
</dict>
36+
</array>
2437
</dict>
2538
<key>createdby</key>
2639
<string>Daniel Zarifpour</string>
2740
<key>description</key>
28-
<string>Get in-line Etherscan search suggestions</string>
41+
<string>Get in-line Etherscan suggestions and view source on DethCode.</string>
2942
<key>disabled</key>
3043
<false/>
3144
<key>name</key>
32-
<string>Etherscan Suggest</string>
45+
<string>Etherscan Suggest (with DethCode)</string>
3346
<key>objects</key>
3447
<array>
3548
<dict>
@@ -166,34 +179,177 @@ function run(argv) {
166179
<key>version</key>
167180
<integer>3</integer>
168181
</dict>
182+
<dict>
183+
<key>config</key>
184+
<dict>
185+
<key>alfredfiltersresults</key>
186+
<false/>
187+
<key>alfredfiltersresultsmatchmode</key>
188+
<integer>0</integer>
189+
<key>argumenttreatemptyqueryasnil</key>
190+
<true/>
191+
<key>argumenttrimmode</key>
192+
<integer>0</integer>
193+
<key>argumenttype</key>
194+
<integer>1</integer>
195+
<key>escaping</key>
196+
<integer>102</integer>
197+
<key>keyword</key>
198+
<string>{var:code_keyword}</string>
199+
<key>queuedelaycustom</key>
200+
<integer>3</integer>
201+
<key>queuedelayimmediatelyinitially</key>
202+
<true/>
203+
<key>queuedelaymode</key>
204+
<integer>0</integer>
205+
<key>queuemode</key>
206+
<integer>1</integer>
207+
<key>runningsubtext</key>
208+
<string>Getting suggestions…</string>
209+
<key>script</key>
210+
<string>// Define a function to check if a string is a valid Ethereum address
211+
function isValidEthereumAddress(address) {
212+
return /^0x[a-fA-F0-9]{40}$/.test(address);
213+
}
214+
215+
// Define a function to create Alfred items from an array of suggestion objects
216+
function makeItems(suggestions) {
217+
return suggestions.map((suggestion) =&gt; {
218+
const title = suggestion.title;
219+
const address = suggestion.address || title; // Default to title if no address is provided
220+
return {
221+
uid: title,
222+
title: title,
223+
subtitle: "Open “" + title + "” on DethCode",
224+
arg: address,
225+
};
226+
});
227+
}
228+
229+
// Retrieve the previous search term and suggestions from Alfred's environment variables
230+
const oldArg = $.NSProcessInfo.processInfo.environment.objectForKey("oldArg").js;
231+
const oldResults = $.NSProcessInfo.processInfo.environment.objectForKey("oldResults").js;
232+
233+
// Define the main function that generates the list of suggestions for Alfred
234+
function run(argv) {
235+
// If the user did not type anything, return an empty list of suggestions
236+
if (!argv[0]) {
237+
return JSON.stringify({ items: [] });
238+
}
239+
240+
// If the user is currently typing, return the previous suggestions as well as the new ones from the current search
241+
if (argv[0] !== oldArg) {
242+
const previousTitles = oldResults ? oldResults.split("\n").map(title =&gt; ({ title })) : [];
243+
return JSON.stringify({
244+
rerun: 0.1,
245+
skipknowledge: true,
246+
variables: { oldResults: oldResults, oldArg: argv[0] },
247+
items: makeItems(
248+
[{ title: argv[0] }].concat(previousTitles)
249+
),
250+
});
251+
}
252+
253+
// If the user is not currently typing, make a request to the Etherscan autocomplete API to retrieve new suggestions
254+
const encodedQuery = encodeURIComponent(argv[0]);
255+
const queryURL = $.NSURL.URLWithString(`https://etherscan.io/searchHandler?term=${encodedQuery}&amp;filterby=0`);
256+
const requestData = $.NSData.dataWithContentsOfURL(queryURL);
257+
const requestString = $.NSString.alloc.initWithDataEncoding(
258+
requestData,
259+
$.NSUTF8StringEncoding
260+
).js;
261+
const newResults = JSON.parse(requestString).filter((result) =&gt; result.title !== argv[0]);
262+
263+
// If input is a valid Ethereum address and no results, add the address as a suggestion
264+
if (isValidEthereumAddress(argv[0]) &amp;&amp; newResults.length === 0) {
265+
newResults.push({ title: argv[0], address: argv[0] });
266+
}
267+
268+
// Return the new suggestions as Alfred items, and store them along with the current search term in the environment variables for later use
269+
return JSON.stringify({
270+
skipknowledge: true,
271+
variables: { oldResults: newResults.map(result =&gt; result.title).join("\n"), oldArg: argv[0] }, // Store only the titles
272+
items: makeItems(newResults),
273+
});
274+
}</string>
275+
<key>scriptargtype</key>
276+
<integer>1</integer>
277+
<key>scriptfile</key>
278+
<string></string>
279+
<key>subtext</key>
280+
<string>Search Etherscan with suggestions</string>
281+
<key>title</key>
282+
<string>Open in DethCode</string>
283+
<key>type</key>
284+
<integer>7</integer>
285+
<key>withspace</key>
286+
<true/>
287+
</dict>
288+
<key>type</key>
289+
<string>alfred.workflow.input.scriptfilter</string>
290+
<key>uid</key>
291+
<string>BBFB364B-0164-4127-823F-FB71BB608C05</string>
292+
<key>version</key>
293+
<integer>3</integer>
294+
</dict>
295+
<dict>
296+
<key>config</key>
297+
<dict>
298+
<key>browser</key>
299+
<string></string>
300+
<key>skipqueryencode</key>
301+
<false/>
302+
<key>skipvarencode</key>
303+
<false/>
304+
<key>spaces</key>
305+
<string></string>
306+
<key>url</key>
307+
<string>https://etherscan.deth.net/token/{query}</string>
308+
</dict>
309+
<key>type</key>
310+
<string>alfred.workflow.action.openurl</string>
311+
<key>uid</key>
312+
<string>51C6A401-41A1-461F-9C42-C904FA75DC36</string>
313+
<key>version</key>
314+
<integer>1</integer>
315+
</dict>
169316
</array>
170317
<key>readme</key>
171-
<string># Etherscan Suggest
318+
<string># Etherscan Suggest (with DethCode)
172319
173-
Get in-line suggestions from [Etherscan](https://etherscan.io) search results via the **Search Keyword** (default: `eth`). Press &lt;kbd&gt;&lt;/kbd&gt; to open the contract's page with your default web browser — both the contract's name and its address are valid inputs.
320+
Get in-line suggestions from [Etherscan](https://etherscan.io) via the **Keywords** `eth` (to open in Etherscan) and `deth` (to open the contract's source code on [DethCode](https://etherscan.deth.net)). Press &lt;kbd&gt;&lt;/kbd&gt; to proceed — both the contract's name and its address are valid inputs.
174321
175322
![etherscan-workflow.png](/resources/etherscan-workflow.png)
176323
177-
## Updating the Search Keyword
324+
![dethcode-workflow.png](/resources/dethcode-workflow.png)
325+
326+
## Updating the Search Keywords
178327
179328
1. Go to **Alfred Preferences**.
180329
2. Open the **Workflows** tab.
181-
3. Select **Etherscan Suggest**.
182-
4. Click **Configure Workflow...** to set the Search Keyword.
330+
3. Select **Etherscan Suggest (with DethCode)**.
331+
4. Click **Configure Workflow...** to set or modify the **Keywords**.
183332
184333
## Credits
185334
186335
This workflow is inspired by the [Google Suggest](https://alfred.app/workflows/alfredapp/google-suggest/) workflow created by Vítor Galvão.
187336
188337
"This workflow was adapted with the help of ChatGPT, a large language model trained by OpenAI. ChatGPT provided guidance and support during the development process."
189338
190-
If you liked this workflow, try out my other one: [You.com Suggest](https://github.com/zarifpour/alfred-you-suggest/tree/main).
339+
If you enjoyed this workflow, explore my other one: [You.com Suggest](https://github.com/zarifpour/alfred-you-suggest/tree/main).
191340
192341
---
193342
194343
Adapted with ❤️ by [Daniel Zarifpour](https://links.dev/z).</string>
195344
<key>uidata</key>
196345
<dict>
346+
<key>51C6A401-41A1-461F-9C42-C904FA75DC36</key>
347+
<dict>
348+
<key>xpos</key>
349+
<real>310</real>
350+
<key>ypos</key>
351+
<real>375</real>
352+
</dict>
197353
<key>882A5947-06A0-49ED-8443-D55F88AEF74A</key>
198354
<dict>
199355
<key>xpos</key>
@@ -208,6 +364,13 @@ Adapted with ❤️ by [Daniel Zarifpour](https://links.dev/z).</string>
208364
<key>ypos</key>
209365
<real>230</real>
210366
</dict>
367+
<key>BBFB364B-0164-4127-823F-FB71BB608C05</key>
368+
<dict>
369+
<key>xpos</key>
370+
<real>125</real>
371+
<key>ypos</key>
372+
<real>375</real>
373+
</dict>
211374
</dict>
212375
<key>userconfigurationconfig</key>
213376
<array>
@@ -226,17 +389,36 @@ Adapted with ❤️ by [Daniel Zarifpour](https://links.dev/z).</string>
226389
<key>description</key>
227390
<string>Key to start Etherscan suggestions</string>
228391
<key>label</key>
229-
<string>Search Keyword</string>
392+
<string>Search keyword</string>
230393
<key>type</key>
231394
<string>textfield</string>
232395
<key>variable</key>
233396
<string>search_keyword</string>
234397
</dict>
398+
<dict>
399+
<key>config</key>
400+
<dict>
401+
<key>default</key>
402+
<string>deth</string>
403+
<key>placeholder</key>
404+
<string></string>
405+
<key>required</key>
406+
<false/>
407+
<key>trim</key>
408+
<true/>
409+
</dict>
410+
<key>description</key>
411+
<string>Key to open code on DethCode</string>
412+
<key>label</key>
413+
<string>Code keyword</string>
414+
<key>type</key>
415+
<string>textfield</string>
416+
<key>variable</key>
417+
<string>code_keyword</string>
418+
</dict>
235419
</array>
236-
<key>variablesdontexport</key>
237-
<array/>
238420
<key>version</key>
239-
<string>1.0.0</string>
421+
<string>1.1.0</string>
240422
<key>webaddress</key>
241423
<string>https://links.dev/z</string>
242424
</dict>

resources/dethcode-workflow-old.png

297 KB
Loading

resources/dethcode-workflow.png

296 KB
Loading

resources/etherscan-workflow-old.png

301 KB
Loading

resources/etherscan-workflow.png

-2.67 KB
Loading

0 commit comments

Comments
 (0)