Skip to content

Commit a1c1796

Browse files
authored
Add files via upload
1 parent 29a0e42 commit a1c1796

File tree

4 files changed

+248
-0
lines changed

4 files changed

+248
-0
lines changed

icon.png

3.74 KB
Loading

info.plist

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>bundleid</key>
6+
<string>zarifpour.etherscan</string>
7+
<key>category</key>
8+
<string>Internet</string>
9+
<key>connections</key>
10+
<dict>
11+
<key>B2496DEF-C902-4D76-BD7C-DC86D9DB4C04</key>
12+
<array>
13+
<dict>
14+
<key>destinationuid</key>
15+
<string>882A5947-06A0-49ED-8443-D55F88AEF74A</string>
16+
<key>modifiers</key>
17+
<integer>0</integer>
18+
<key>modifiersubtext</key>
19+
<string></string>
20+
<key>vitoclose</key>
21+
<false/>
22+
</dict>
23+
</array>
24+
</dict>
25+
<key>createdby</key>
26+
<string>Daniel Zarifpour</string>
27+
<key>description</key>
28+
<string>Get in-line Etherscan search suggestions</string>
29+
<key>disabled</key>
30+
<false/>
31+
<key>name</key>
32+
<string>Etherscan Suggest</string>
33+
<key>objects</key>
34+
<array>
35+
<dict>
36+
<key>config</key>
37+
<dict>
38+
<key>browser</key>
39+
<string></string>
40+
<key>skipqueryencode</key>
41+
<false/>
42+
<key>skipvarencode</key>
43+
<false/>
44+
<key>spaces</key>
45+
<string></string>
46+
<key>url</key>
47+
<string>https://etherscan.io/token/{query}</string>
48+
</dict>
49+
<key>type</key>
50+
<string>alfred.workflow.action.openurl</string>
51+
<key>uid</key>
52+
<string>882A5947-06A0-49ED-8443-D55F88AEF74A</string>
53+
<key>version</key>
54+
<integer>1</integer>
55+
</dict>
56+
<dict>
57+
<key>config</key>
58+
<dict>
59+
<key>alfredfiltersresults</key>
60+
<false/>
61+
<key>alfredfiltersresultsmatchmode</key>
62+
<integer>0</integer>
63+
<key>argumenttreatemptyqueryasnil</key>
64+
<true/>
65+
<key>argumenttrimmode</key>
66+
<integer>0</integer>
67+
<key>argumenttype</key>
68+
<integer>1</integer>
69+
<key>escaping</key>
70+
<integer>102</integer>
71+
<key>keyword</key>
72+
<string>{var:search_keyword}</string>
73+
<key>queuedelaycustom</key>
74+
<integer>3</integer>
75+
<key>queuedelayimmediatelyinitially</key>
76+
<true/>
77+
<key>queuedelaymode</key>
78+
<integer>0</integer>
79+
<key>queuemode</key>
80+
<integer>1</integer>
81+
<key>runningsubtext</key>
82+
<string>Getting suggestions…</string>
83+
<key>script</key>
84+
<string>// Define a function to check if a string is a valid Ethereum address
85+
function isValidEthereumAddress(address) {
86+
return /^0x[a-fA-F0-9]{40}$/.test(address);
87+
}
88+
89+
// Define a function to create Alfred items from an array of suggestion objects
90+
function makeItems(suggestions) {
91+
return suggestions.map((suggestion) =&gt; {
92+
const title = suggestion.title;
93+
const address = suggestion.address || title; // Default to title if no address is provided
94+
return {
95+
uid: title,
96+
title: title,
97+
subtitle: "Open “" + title + "” on Etherscan",
98+
arg: address,
99+
};
100+
});
101+
}
102+
103+
// Retrieve the previous search term and suggestions from Alfred's environment variables
104+
const oldArg = $.NSProcessInfo.processInfo.environment.objectForKey("oldArg").js;
105+
const oldResults = $.NSProcessInfo.processInfo.environment.objectForKey("oldResults").js;
106+
107+
// Define the main function that generates the list of suggestions for Alfred
108+
function run(argv) {
109+
// If the user did not type anything, return an empty list of suggestions
110+
if (!argv[0]) {
111+
return JSON.stringify({ items: [] });
112+
}
113+
114+
// If the user is currently typing, return the previous suggestions as well as the new ones from the current search
115+
if (argv[0] !== oldArg) {
116+
const previousTitles = oldResults ? oldResults.split("\n").map(title =&gt; ({ title })) : [];
117+
return JSON.stringify({
118+
rerun: 0.1,
119+
skipknowledge: true,
120+
variables: { oldResults: oldResults, oldArg: argv[0] },
121+
items: makeItems(
122+
[{ title: argv[0] }].concat(previousTitles)
123+
),
124+
});
125+
}
126+
127+
// If the user is not currently typing, make a request to the Etherscan autocomplete API to retrieve new suggestions
128+
const encodedQuery = encodeURIComponent(argv[0]);
129+
const queryURL = $.NSURL.URLWithString(`https://etherscan.io/searchHandler?term=${encodedQuery}&amp;filterby=0`);
130+
const requestData = $.NSData.dataWithContentsOfURL(queryURL);
131+
const requestString = $.NSString.alloc.initWithDataEncoding(
132+
requestData,
133+
$.NSUTF8StringEncoding
134+
).js;
135+
const newResults = JSON.parse(requestString).filter((result) =&gt; result.title !== argv[0]);
136+
137+
// If input is a valid Ethereum address and no results, add the address as a suggestion
138+
if (isValidEthereumAddress(argv[0]) &amp;&amp; newResults.length === 0) {
139+
newResults.push({ title: argv[0], address: argv[0] });
140+
}
141+
142+
// Return the new suggestions as Alfred items, and store them along with the current search term in the environment variables for later use
143+
return JSON.stringify({
144+
skipknowledge: true,
145+
variables: { oldResults: newResults.map(result =&gt; result.title).join("\n"), oldArg: argv[0] }, // Store only the titles
146+
items: makeItems(newResults),
147+
});
148+
}</string>
149+
<key>scriptargtype</key>
150+
<integer>1</integer>
151+
<key>scriptfile</key>
152+
<string></string>
153+
<key>subtext</key>
154+
<string>Search Etherscan with suggestions</string>
155+
<key>title</key>
156+
<string>Search Etherscan</string>
157+
<key>type</key>
158+
<integer>7</integer>
159+
<key>withspace</key>
160+
<true/>
161+
</dict>
162+
<key>type</key>
163+
<string>alfred.workflow.input.scriptfilter</string>
164+
<key>uid</key>
165+
<string>B2496DEF-C902-4D76-BD7C-DC86D9DB4C04</string>
166+
<key>version</key>
167+
<integer>3</integer>
168+
</dict>
169+
</array>
170+
<key>readme</key>
171+
<string># Etherscan Suggest
172+
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.
174+
175+
![etherscan-workflow.png](/resources/etherscan-workflow.png)
176+
177+
## Updating the Search Keyword
178+
179+
1. Go to **Alfred Preferences**.
180+
2. Open the **Workflows** tab.
181+
3. Select **Etherscan Suggest**.
182+
4. Click **Configure Workflow...** to set the Search Keyword.
183+
184+
## Credits
185+
186+
This workflow is inspired by the [Google Suggest](https://alfred.app/workflows/alfredapp/google-suggest/) workflow created by Vítor Galvão.
187+
188+
"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."
189+
190+
If you liked this workflow, try out my other one: [You.com Suggest](https://github.com/zarifpour/alfred-you-suggest/tree/main).
191+
192+
---
193+
194+
Adapted with ❤️ by [Daniel Zarifpour](https://links.dev/z).</string>
195+
<key>uidata</key>
196+
<dict>
197+
<key>882A5947-06A0-49ED-8443-D55F88AEF74A</key>
198+
<dict>
199+
<key>xpos</key>
200+
<real>315</real>
201+
<key>ypos</key>
202+
<real>230</real>
203+
</dict>
204+
<key>B2496DEF-C902-4D76-BD7C-DC86D9DB4C04</key>
205+
<dict>
206+
<key>xpos</key>
207+
<real>125</real>
208+
<key>ypos</key>
209+
<real>230</real>
210+
</dict>
211+
</dict>
212+
<key>userconfigurationconfig</key>
213+
<array>
214+
<dict>
215+
<key>config</key>
216+
<dict>
217+
<key>default</key>
218+
<string>eth</string>
219+
<key>placeholder</key>
220+
<string></string>
221+
<key>required</key>
222+
<false/>
223+
<key>trim</key>
224+
<true/>
225+
</dict>
226+
<key>description</key>
227+
<string>Key to start Etherscan suggestions</string>
228+
<key>label</key>
229+
<string>Search Keyword</string>
230+
<key>type</key>
231+
<string>textfield</string>
232+
<key>variable</key>
233+
<string>search_keyword</string>
234+
</dict>
235+
</array>
236+
<key>variablesdontexport</key>
237+
<array/>
238+
<key>version</key>
239+
<string>1.0.0</string>
240+
<key>webaddress</key>
241+
<string>https://links.dev/z</string>
242+
</dict>
243+
</plist>

prefs.plist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict/>
5+
</plist>

resources/etherscan-workflow.png

301 KB
Loading

0 commit comments

Comments
 (0)