11const bangs = [
22 {
3- "t" : "al" ,
4- "u" : "https://kiwix.tristanhavelick.com/search?content=archlinux_en_all_nopic_2022-05&pattern={{{s}}}"
3+ t : "al" ,
4+ u : "https://kiwix.tristanhavelick.com/search?content=archlinux_en_all_nopic_2022-05&pattern={{{s}}}" ,
55 } ,
66 {
7- "t" : "cl" ,
8- "u" : "https://denver.craigslist.org/search/?query={{{s}}}"
7+ t : "cl" ,
8+ u : "https://denver.craigslist.org/search/?query={{{s}}}" ,
99 } ,
1010 {
11- "t" : "d" ,
12- "u" : "https://lite.duckduckgo.com/lite?q={{{s}}}&kl=us-en"
11+ t : "d" ,
12+ u : "https://lite.duckduckgo.com/lite?q={{{s}}}&kl=us-en" ,
1313 } ,
1414 {
15- "t" : "e" ,
16- "u" : "https://www.ebay.com/sch/i.html?_nkw={{{s}}}&rt=nc&LH_ItemCondition=4"
15+ t : "e" ,
16+ u : "https://www.ebay.com/sch/i.html?_nkw={{{s}}}&rt=nc&LH_ItemCondition=4" ,
1717 } ,
1818 {
19- "t" : "jw" ,
20- "u" : "https://www.justwatch.com/us/search?q={{{s}}}"
19+ t : "jw" ,
20+ u : "https://www.justwatch.com/us/search?q={{{s}}}" ,
2121 } ,
2222 {
23- "t" : "k" ,
24- "u" : "https://kiwix.tristanhavelick.com/search?pattern={{{s}}}"
23+ t : "k" ,
24+ u : "https://kiwix.tristanhavelick.com/search?pattern={{{s}}}" ,
2525 } ,
2626 {
27- "t" : "lg" ,
28- "u" : "http://libgen.is/search.php?req={{{s}}}"
27+ t : "lg" ,
28+ u : "http://libgen.is/search.php?req={{{s}}}" ,
2929 } ,
3030 {
31- "t" : "lgf" ,
32- "u" : "http://libgen.is/fiction/?q={{{s}}}"
31+ t : "lgf" ,
32+ u : "http://libgen.is/fiction/?q={{{s}}}" ,
3333 } ,
3434 {
35- "t" : "m" ,
36- "u" : "https://search.marginalia.nu/search?query={{{s}}}"
35+ t : "m" ,
36+ u : "https://search.marginalia.nu/search?query={{{s}}}" ,
3737 } ,
3838 {
39- "t" : "py" ,
40- "u" : "https://kiwix.tristanhavelick.com/search?content=python-3.10.2&pattern={{{s}}}"
39+ t : "py" ,
40+ u : "https://kiwix.tristanhavelick.com/search?content=python-3.10.2&pattern={{{s}}}" ,
4141 } ,
4242 {
43- "t" : "sg" ,
44- "u" : "https://app.thestorygraph.com/browse?search_term={{{s}}}"
43+ t : "sg" ,
44+ u : "https://app.thestorygraph.com/browse?search_term={{{s}}}" ,
4545 } ,
4646 {
47- "t" : "ytt" ,
48- "u" : "https://youtranscript.tristanhavelick.com/search?search_term={{{s}}}"
47+ t : "ytt" ,
48+ u : "https://youtranscript.tristanhavelick.com/search?search_term={{{s}}}" ,
4949 } ,
5050 {
51- "t" : "x" ,
52- "u" : "https://searxng.tristanhavelick.com/search?q={{{s}}}"
51+ t : "x" ,
52+ u : "https://searxng.tristanhavelick.com/search?q={{{s}}}" ,
5353 } ,
5454 {
55- "t" : "gh" ,
56- "u" : "https://github.com/search?q={{{s}}}"
55+ t : "gh" ,
56+ u : "https://github.com/search?q={{{s}}}" ,
5757 } ,
5858 {
59- "t" : "g" ,
60- "u" : "https://www.google.com/search?q={{{s}}}"
59+ t : "g" ,
60+ u : "https://www.google.com/search?q={{{s}}}" ,
6161 } ,
6262 {
63- "t" : "ddg" ,
64- "u" : "https://duckduckgo.com/?q={{{s}}}"
63+ t : "ddg" ,
64+ u : "https://duckduckgo.com/?q={{{s}}}" ,
6565 } ,
6666 {
67- "t" : "a" ,
68- "u" : "https://www.amazon.com/s?k={{{s}}}"
67+ t : "a" ,
68+ u : "https://www.amazon.com/s?k={{{s}}}" ,
6969 } ,
7070 {
71- "t" : "pypi" ,
72- "u" : "https://pypi.org/search/?q={{{s}}}"
71+ t : "pypi" ,
72+ u : "https://pypi.org/search/?q={{{s}}}" ,
7373 } ,
7474 {
75- "t" : "w" ,
76- "u" : "https://en.wikipedia.org/wiki/Special:Search?search={{{s}}}"
77- }
75+ t : "w" ,
76+ u : "https://en.wikipedia.org/wiki/Special:Search?search={{{s}}}" ,
77+ } ,
7878] ;
7979
8080function processBang ( query ) {
8181 const trimmed = query . trim ( ) ;
82-
83- if ( trimmed . startsWith ( '!' ) ) {
84- const spaceIndex = trimmed . indexOf ( ' ' ) ;
82+
83+ if ( trimmed . startsWith ( "!" ) ) {
84+ const spaceIndex = trimmed . indexOf ( " " ) ;
8585 if ( spaceIndex === - 1 ) {
8686 return null ;
8787 }
88-
88+
8989 const bangTag = trimmed . substring ( 1 , spaceIndex ) ;
9090 const searchTerm = trimmed . substring ( spaceIndex + 1 ) . trim ( ) ;
91-
92- const bang = bangs . find ( b => b . t === bangTag ) ;
91+
92+ const bang = bangs . find ( ( b ) => b . t === bangTag ) ;
9393 if ( bang ) {
9494 return bang . u . replace ( / { { { s } } } / g, encodeURIComponent ( searchTerm ) ) ;
9595 }
@@ -98,8 +98,8 @@ function processBang(query) {
9898 if ( bangMatch ) {
9999 const searchTerm = bangMatch [ 1 ] . trim ( ) ;
100100 const bangTag = bangMatch [ 2 ] ;
101-
102- const bang = bangs . find ( b => b . t === bangTag ) ;
101+
102+ const bang = bangs . find ( ( b ) => b . t === bangTag ) ;
103103 if ( bang ) {
104104 return bang . u . replace ( / { { { s } } } / g, encodeURIComponent ( searchTerm ) ) ;
105105 }
@@ -117,45 +117,47 @@ function redirect(url) {
117117}
118118
119119function setupUI ( ) {
120- const searchInput = document . getElementById ( ' searchInput' ) ;
121-
120+ const searchInput = document . getElementById ( " searchInput" ) ;
121+
122122 function performSearch ( ) {
123123 const query = searchInput . value ;
124124 const url = processBang ( query ) ;
125125 if ( url ) {
126- window . location . hash = ' #q=' + encodeURIComponent ( query ) ;
126+ window . location . hash = " #q=" + encodeURIComponent ( query ) ;
127127 redirect ( url ) ;
128128 }
129129 }
130130
131- document . getElementById ( 'searchButton' ) . addEventListener ( 'click' , performSearch ) ;
131+ document
132+ . getElementById ( "searchButton" )
133+ . addEventListener ( "click" , performSearch ) ;
132134
133- searchInput . addEventListener ( ' keypress' , function ( e ) {
134- if ( e . key === ' Enter' ) {
135+ searchInput . addEventListener ( " keypress" , function ( e ) {
136+ if ( e . key === " Enter" ) {
135137 e . preventDefault ( ) ;
136138 performSearch ( ) ;
137139 }
138140 } ) ;
139141
140142 if ( window . location . hash ) {
141143 const hashParams = new URLSearchParams ( window . location . hash . substring ( 1 ) ) ;
142- const hashQuery = hashParams . get ( 'q' ) ;
144+ const hashQuery = hashParams . get ( "q" ) ;
143145 if ( hashQuery ) {
144146 searchInput . value = decodeURIComponent ( hashQuery ) ;
145147 }
146148 }
147149}
148150
149151function initialize ( ) {
150- const queryParam = getQueryParam ( 'q' ) ;
152+ const queryParam = getQueryParam ( "q" ) ;
151153 if ( queryParam ) {
152154 const url = processBang ( queryParam ) ;
153155 if ( url ) {
154156 redirect ( url ) ;
155157 }
156158 } else {
157- document . addEventListener ( ' DOMContentLoaded' , setupUI ) ;
159+ document . addEventListener ( " DOMContentLoaded" , setupUI ) ;
158160 }
159161}
160162
161- initialize ( ) ;
163+ initialize ( ) ;
0 commit comments