-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugins.html
More file actions
979 lines (954 loc) · 44.4 KB
/
Copy pathplugins.html
File metadata and controls
979 lines (954 loc) · 44.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
<!doctype html>
<html lang="en" data-theme="light">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Plugins - Degoog docs</title>
<script>
(function () {
try {
var t = localStorage.getItem("ade:theme");
if (t !== "light" && t !== "dark") {
t = window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light";
}
document.documentElement.setAttribute("data-theme", t);
} catch (e) {}
})();
</script>
<link
rel="icon"
href="https://github.com/fccview/degoog/raw/main/src/public/images/degoog-logo.png"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css"
/>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"
/>
<link rel="stylesheet" href="style.css?cache=burstthefucker" />
</head>
<body>
<div class="degoog-docs-layout">
<header class="degoog-docs-mobile-header">
<button id="degoog-docs-burger" type="button" class="degoog-docs-btn degoog-docs-btn-burger">
<i class="fa-solid fa-bars"></i>
</button>
<span class="degoog-docs-mobile-title">Degoog Docs</span>
</header>
<div class="degoog-docs-content">
<aside class="degoog-docs-sidebar">
<div class="degoog-docs-sidebar-brand">
<img
src="https://github.com/fccview/degoog/raw/main/src/public/images/degoog-logo.png"
alt="degoog logo"
class="degoog-docs-brand-img"
onerror="this.style.display = 'none'"
/>
<a href="index.html" class="degoog-docs-brand-name">Degoog Docs</a>
</div>
<div class="degoog-docs-sidebar-search">
<div class="doc-search-wrap">
<input
type="search"
id="doc-search-input"
class="degoog-docs-input doc-search"
placeholder="Search docs..."
autocomplete="off"
/>
<button
type="button"
class="doc-search-clear degoog-docs-btn"
aria-label="Clear search"
style="display: none"
>
Clear
</button>
<span class="doc-search-count"></span>
</div>
</div>
<nav class="degoog-docs-nav" aria-label="Documentation">
<a href="index.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-book-open fa-lg"></i></i
><span class="degoog-docs-nav-item-name">Overview</span></a
>
<a href="plugins.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-puzzle-piece fa-lg"></i
><span class="degoog-docs-nav-item-name"> Plugins</span></a
>
<a href="shortcuts.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-arrow-down-a-z fa-lg"></i></i
><span class="degoog-docs-nav-item-name"> Shortcuts</span></a
>
<a href="themes.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-palette fa-lg"></i
><span class="degoog-docs-nav-item-name"> Themes</span></a
>
<a href="engines.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-bolt fa-lg"></i
><span class="degoog-docs-nav-item-name"> Search engines</span></a
>
<a href="autocomplete.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-keyboard fa-lg"></i
><span class="degoog-docs-nav-item-name"> Autocomplete</span></a
>
<a href="transports.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-network-wired fa-lg"></i
><span class="degoog-docs-nav-item-name"> Transports</span></a
>
<a href="store.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-store fa-lg"></i
><span class="degoog-docs-nav-item-name"> Store</span></a
>
<a href="aliases.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-link fa-lg"></i
><span class="degoog-docs-nav-item-name"> Aliases</span></a
>
<a href="env.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-lock fa-lg"></i></i
><span class="degoog-docs-nav-item-name">ENV Variables</span></a
>
<a href="styling.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-swatchbook fa-lg"></i></i
><span class="degoog-docs-nav-item-name"> Styling</span></a
>
<a href="translations.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-language fa-lg"></i
><span class="degoog-docs-nav-item-name"> Translations</span></a
>
<a href="api.html" class="degoog-docs-nav-item"
><i class="fa-solid fa-code fa-lg"></i
><span class="degoog-docs-nav-item-name"> API</span></a
>
</nav>
<div class="degoog-docs-sidebar-actions">
<button
id="doc-theme-toggle"
type="button"
class="degoog-docs-btn"
aria-label="Toggle theme"
>
<i class="fa-solid fa-circle-half-stroke"></i>
</button>
</div>
</aside>
<main class="degoog-docs-main">
<div class="doc-page-header">
<h1><a href="index.html">Degoog</a> Plugins</h1>
<p class="doc-page-desc">
Create custom bang commands, slots, search result tabs, search bar
actions, routes, and middleware.
</p>
</div>
<div class="doc-cli-banner">
<i class="fa-solid fa-terminal"></i>
<p>
<strong>degoog-cli is now available.</strong>
Scaffold plugin boilerplate directly from your terminal - no copy-pasting, no guessing the folder structure.
Install with <code>curl -fsSL https://raw.githubusercontent.com/degoog-org/cli/main/install.sh | sh</code>
or grab it from <a href="https://github.com/degoog-org/cli" target="_blank" rel="noopener">github.com/degoog-org/cli</a>.
</p>
</div>
<h2>What plugins are</h2>
<p>
Your plugins belong in the <code>data/plugins/</code> directory, or
whatever you set <code>DEGOOG_PLUGINS_DIR</code> to. A plugin is
simply a <strong>folder</strong> containing an entry file. You can
use a single plugin to handle multiple tasks like a bang command, a
slot, search bar actions, HTTP routes, or request middleware.
</p>
<h2>Folder structure</h2>
<pre><code>data/plugins/
my-plugin/
index.js
template.html
style.css
script.js
card.html
author.json </code></pre>
<p>
Your entry file needs to be <code>index.js</code>,
<code>index.ts</code>, <code>index.mjs</code>, or
<code>index.cjs</code>.
</p>
<h3>Asset files</h3>
<ul>
<li>
<strong>template.html</strong>: This is the HTML fragment for your
plugin output. You can use <code>{{placeholders}}</code> and
replace them inside <code>execute()</code>. This gets injected
directly into the search results rather than rendering a full
page.
</li>
<li>
<strong>style.css</strong>: This loads automatically when your
plugin is active. Make sure to use class names scoped to your
specific plugin to avoid styling conflicts. You can check the
<a href="styling.html">Styling</a> page for available CSS
variables.
</li>
<li>
<strong>script.js</strong>: Your client side JavaScript that loads
automatically.
</li>
</ul>
<p>
You can add other files and read them while the app runs using
<code>ctx.readFile("filename")</code> inside your
<code>init(ctx)</code> function.
</p>
<h3>Plugin context and init()</h3>
<p>
The system calls your optional <code>init(ctx)</code> function once
during startup before running <code>configure()</code>. The context
provides the following:
</p>
<pre><code>init(ctx) {
// ctx.template contains your template.html
// ctx.dir is the absolute path to your plugin folder
// ctx.pluginId (alias ctx.id) is your real installed plugin folder ID
// ctx.apiBase is /api/plugin/<ctx.pluginId>
// ctx.routeUrl("path") builds /api/plugin/<ctx.pluginId>/path
// ctx.readFile is an async function to read any file from your plugin folder
// ctx.signProxyUrl(url) returns a signed /api/proxy/image URL for any external image
// ctx.fetch(url, init?) is a proxy-aware fetch, respects your outgoing proxy settings
// ctx.useCache(namespace, defaultTtlMs) returns an async TTL cache { get, set, delete, clear }
}</code></pre>
<p>
When your <strong>backend</strong> code generates a URL that points at
one of your own plugin routes (for example an image cache that returns a
link to a <code>/thumb</code> route), never hardcode the folder name or
derive it from <code>ctx.dir</code>. Store-installed plugins run under a
generated folder ID such as
<code><author>-<repo>-<plugin-name></code>, so the only
correct base is <code>ctx.apiBase</code> (or
<code>ctx.routeUrl("thumb")</code>). The frontend equivalent is the
injected <code>__PLUGIN_ID__</code> constant.
</p>
<h3>TTL cache (<code>useCache</code>)</h3>
<p>
Both <code>init(ctx)</code> and slot <code>execute(query, context)</code>
receive <strong><code>useCache</code></strong>: a factory that returns an
<strong>async</strong> namespaced cache. Call
<code>ctx.useCache<T>(namespace, defaultTtlMs)</code> (or
<code>context.useCache<T>(namespace, defaultTtlMs)</code> in slots) to
get an object with <code>await get(key)</code>,
<code>await set(key, value, ttlMs?)</code>, <code>await delete(key)</code>,
and <code>await clear()</code>. Keys are strings; values are typed by your
generic <code>T</code>. Entries expire automatically after the TTL
(milliseconds).
</p>
<p>
The <code>namespace</code> is a per-cache discriminator (for example,
<code>"ext:my-plugin:articles"</code>). It is combined with the instance's
ID internally, so different plugins never collide. When the optional Valkey
sidecar is configured (<code>DEGOOG_VALKEY_URL</code>), <code>useCache</code>
transparently becomes a shared cache across all replicas of the instance;
otherwise it falls back to a per-process in-memory store. The API is
identical either way.
</p>
<p>
Typical usage: call <code>useCache</code> once in <code>init</code>, keep
the returned cache on a module-level variable, and use
<code>await get</code> / <code>await set</code> from <code>execute</code>
(for example, for fetched page excerpts). Always prefer
<code>ctx.useCache</code> / <code>context.useCache</code> over importing
cache helpers from server internals so plugins behave the same in every
environment.
</p>
<p>
Store <code>ctx.fetch</code> during <code>init</code> if your plugin
makes outgoing HTTP requests outside of <code>execute()</code>, for
example inside custom plugin routes. Using it keeps your requests
consistent with the proxy settings configured in Settings.
</p>
<p>
For example, you might build a plugin that uses both a command
template and a separate card template. The
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/rss"
class="external"
target="_blank"
rel="noopener"
>RSS</a
>
plugin does exactly this by reading <code>card.html</code> through
<code>ctx.readFile("card.html")</code>.
</p>
<h2 id="bang-commands">Bang commands</h2>
<p>
Bang commands run whenever you type
<code>!trigger something</code> or <code>something !trigger</code> into the search bar. You need to
export a single object using <code>export default</code> or
<code>export const command</code> containing these properties:
</p>
<ul>
<li>
<strong>name</strong> and <strong>description</strong>: These
appear in Settings and the <code>!help</code> menu.
</li>
<li>
<strong>trigger</strong>: The word you type right after the
<code>!</code> symbol. For example, typing
<code>weather</code> becomes <code>!weather</code>.
</li>
<li>
<strong>execute(args, context)</strong> (async): The
<code>args</code> parameter contains whatever text follows or precedes
your trigger. You must return an object containing a
<code>title</code> string and an <code>html</code> string. You can
also include an optional <code>totalPages</code> number.
</li>
</ul>
<p>
The second argument passed to <code>execute</code> is
<code>context</code>, which might contain your
<code>clientIp</code>, <code>page</code>, and
<code>signProxyUrl(url)</code>. Call
<code>context.signProxyUrl</code> to get a signed
<code>/api/proxy/image</code> URL for any external image you want to
serve through the built-in image proxy.
</p>
<p>
You can also include optional properties like
<code>aliases</code> for extra triggers, or
<code>naturalLanguagePhrases</code> which are phrases that trigger
the command without needing the <code>!</code> symbol when natural
language is enabled in Settings. You can also use
<code>settingsSchema</code>, <code>configure(settings)</code>,
<code>init(ctx)</code>, and <code>isConfigured()</code>. If
<code>isConfigured()</code> is async and returns false, your command
stays hidden from the <code>!help</code> menu until the user
configures it.
</p>
<p>
For your <code>settingsSchema</code>, each field requires a
<code>key</code>, <code>label</code>, and <code>type</code>. The
type can be <code>text</code>, <code>password</code>,
<code>url</code>, <code>toggle</code>, <code>textarea</code>,
<code>select</code>, <code>urllist</code>, <code>list</code>, or
<code>info</code>. You can also add optional flags like
<code>required</code>, <code>placeholder</code>,
<code>description</code>, or <code>secret</code>. Secret fields are
never sent back to the browser. If you use the
<code>select</code> type, you will need to add an
<code>options</code> array containing your string choices.
</p>
<p>
The <code>list</code> type lets users manage a repeatable list of
structured rows. Add an <code>itemSchema</code> array describing one
row (each entry is itself a field with a <code>key</code>,
<code>label</code> and <code>type</code> such as <code>text</code> or
<code>toggle</code>), and an optional <code>addLabel</code> for the
add button. The value is stored and passed to
<code>configure(settings)</code> as a JSON array of objects, so parse
it with <code>JSON.parse</code>.
</p>
<pre><code>settingsSchema: [
{
key: "bangs",
label: "Custom bangs",
type: "list",
addLabel: "+ Add bang",
itemSchema: [
{ key: "name", label: "Name", type: "text" },
{ key: "shortcut", label: "Shortcut", type: "text" },
{ key: "url", label: "URL template", type: "text" },
{ key: "openBase", label: "Open base path", type: "toggle" }
]
}
]</code></pre>
<h3>How settings work</h3>
<ol>
<li>
Declare your <code>settingsSchema</code> so a Configure button
appears in Settings then Plugins.
</li>
<li>
When you save, the values are stored in
<code>data/plugin-settings.json</code> under
<code><folderName>-command</code>.
</li>
<li>
The <code>configure(settings)</code> function runs right after
saving and every time the server restarts if settings are present.
</li>
<li>
Use <code>isConfigured()</code> to return false when required
settings are missing. This hides the command from the
<code>!help</code> menu.
</li>
<li>
You can disable any plugin using the toggle in Settings then
Plugins. Disabled plugins disappear from <code>!help</code> and
return an error if you try to invoke them.
</li>
</ol>
<p><strong>Examples from the official store:</strong></p>
<ul>
<li>
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/custom-bangs"
class="external"
target="_blank"
rel="noopener"
>Custom Bangs</a
>
lets users define their own bang shortcuts that redirect to any
site. It uses a <code>list</code> setting for the bangs and a small
client script that rewrites the query. Type
<code>!<shortcut> terms</code> (leading or trailing); the
<code>{{{s}}}</code> or <code>%s</code> placeholder in the URL
template is replaced with the query, and a bare bang can open the
base path or snap domain.
</li>
<li>
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/weather"
class="external"
target="_blank"
rel="noopener"
>Weather</a
>
is a bang command complete with a template, styles, settings for
things like default city or Fahrenheit, aliases, and natural
language phrases.
</li>
<li>
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/define"
class="external"
target="_blank"
rel="noopener"
>Define</a
>,
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/qr"
class="external"
target="_blank"
rel="noopener"
>QR</a
>,
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/time"
class="external"
target="_blank"
rel="noopener"
>Time</a
>, and
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/password"
class="external"
target="_blank"
rel="noopener"
>Password</a
>
are examples of simple command only plugins.
</li>
<li>
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/jellyfin"
class="external"
target="_blank"
rel="noopener"
>Jellyfin</a
>
and
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/meilisearch"
class="external"
target="_blank"
rel="noopener"
>Meilisearch</a
>
let you search your own personal backend through a bang command.
</li>
</ul>
<h2>Slot plugins</h2>
<p>
Slots let you inject custom panels directly into the search results
page when a query matches. Just export <code>slot</code> or
<code>slotPlugin</code>. A single module can actually export both a
slot and a bang command.
</p>
<ul>
<li>
<strong>id</strong> and <strong>name</strong>: Your unique
identifier and display name.
</li>
<li>
<strong>position</strong>: Choose between
<code>above-results</code>, <code>below-results</code>,
<code>above-sidebar</code>, <code>below-sidebar</code>,
<code>knowledge-panel</code>, or <code>at-a-glance</code>. Please
use the specific sidebar positions instead of the old deprecated
sidebar option.
</li>
<li>
<strong>trigger(query)</strong>: This needs to return true, or a
Promise that resolves to true, whenever the slot should appear for
a specific query.
</li>
<li>
<strong>execute(query, context)</strong> (async): Return an object
with an optional <code>title</code> string and an
<code>html</code> string. If you return an empty string for the
html, nothing will show up. The <code>context</code> includes
<code>clientIp</code>; <code>results</code> (only when
<code>waitForResults: true</code>); proxy-aware
<code>fetch(url, init?)</code>; <code>signProxyUrl(url)</code> for
external images; and <code>useCache(namespace, defaultTtlMs)</code> for the
same async TTL cache factory as in <code>init(ctx)</code>. Note that the
results
array is only populated if you set <code>waitForResults: true</code> on
your plugin.
</li>
</ul>
<p>
You can add an optional <strong>settingsId</strong> to specify the
key where your settings are stored. This defaults to
<code><id>-slot</code>. You can also include
<code>settingsSchema</code>, <code>configure(settings)</code>, and
<code>init(ctx)</code>. If multiple slots match the exact same
query, they will all display together.
</p>
<p>
Another optional flag is <strong>waitForResults</strong>. Set this
to true if you need to receive <code>context.results</code> inside
your <code>execute()</code> function. While results are always
available when execution happens since slots run after the search
finishes, they are only passed to your plugin if you explicitly
enable this flag. It defaults to false so plugins that do not need
results can stay completely independent.
</p>
<p>
You can also provide an optional
<strong>slotPositions</strong> array. This lets you list multiple
position values like
<code>["knowledge-panel", "above-sidebar", "below-sidebar"]</code>.
If you include this, the application adds a Position dropdown in
your plugin settings so you can choose exactly where the slot
appears. If you leave it empty or omit it, the slot simply uses your
fixed <code>position</code> value.
</p>
<h3>Sidebar positions</h3>
<p>
Using <code>above-sidebar</code> renders right at the top of the
sidebar before any main content. Using
<code>below-sidebar</code> renders at the very bottom of the sidebar
below the engine timings and related searches.
</p>
<h3>Knowledge panel slot</h3>
<p>
Setting your position to <code>knowledge-panel</code> replaces only
the very first block in the sidebar, which is usually the Wikipedia
or knowledge panel. Your engine performance and related searches
blocks stay exactly where they are. When your plugin returns content
for this position, it shows up instead of the default knowledge
panel.
</p>
<h3 id="at-a-glance-slot">At a glance slot</h3>
<p>
Slots using the <code>at-a-glance</code> position will fill the
block directly above the search results. This does not delay your
search response. The client shows your results immediately and
fetches the panel content in a separate background request using
<code>POST /api/slots/glance</code>
with the query and results. Your
<code>execute(query, context)</code> function will always receive
<code>context.results</code> for these types of slots.
</p>
<p><strong>Examples from the official store:</strong></p>
<ul>
<li>
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/tmdb-slot"
class="external"
target="_blank"
rel="noopener"
>TMDb</a
>
is a slot above the results showing movie and TV details. It uses
a secret API key stored in settings.
</li>
<li>
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/math-slot"
class="external"
target="_blank"
rel="noopener"
>Math</a
>
and
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/github-slot"
class="external"
target="_blank"
rel="noopener"
>GitHub</a
>
are examples of slots appearing above the results.
</li>
<li>
<a
href="https://github.com/degoog-org/official-extensions/tree/main/plugins/rss"
class="external"
target="_blank"
rel="noopener"
>RSS</a
>
is a slot that reads feed URLs from settings and uses
<code>card.html</code> through <code>ctx.readFile()</code>.
</li>
</ul>
<p>
<strong>Slot API:</strong> Calling <code>POST /api/slots</code> with
the query and results returns the panels for the main positions.
Calling
<code>POST /api/slots/glance</code>
returns only the glance panels. Slots also work perfectly for custom
tabs. The client simply fetches the panels after a tab search and
renders them in the exact same positions.
</p>
<h2 id="search-result-tabs">Search result tabs</h2>
<p>
Search result tabs let you add new entries to the main tab bar, just
like the Web or Images tabs. Simply export <code>tab</code> or
<code>searchResultTab</code> from your plugin folder. You use the
exact same folder structure as any other plugin.
</p>
<p>
<strong>Required properties:</strong> You must provide an
<strong>id</strong> and a <strong>name</strong>. You also need to
provide either an <strong>engineType</strong> string like
<code>web</code>, <code>images</code>, <code>videos</code>,
<code>news</code>, or a custom type from your engines, or an
<strong>executeSearch(query, page?, context?)</strong> async
function. If you use the function, it must return an object
containing your results array and an optional totalPages number.
Each result needs a title, url, snippet, and source, plus an
optional thumbnail and duration.
</p>
<p>
<strong>Optional properties:</strong> You can add an
<strong>icon</strong>, <strong>settingsId</strong>,
<strong>settingsSchema</strong>,
<strong>configure(settings)</strong>, and
<strong>init(ctx)</strong>. If you are sharing this on the Store,
make sure to set your type to <code>search-result-tab</code> in your
<code>package.json</code>. You can also add a dependencies array
containing URLs if your tab relies on a specific engine, just like
how the File tab depends on the Internet Archive engine.
</p>
<p>
<strong>API:</strong> A <code>GET</code> request to
<code>/api/search-tabs</code> returns the list of available tabs. A
<code>GET</code> request to <code>/api/tab-search</code> along with
your tab id, query, and page number will run the specific search for
that tab.
</p>
<h2>Search bar actions</h2>
<p>
Your plugins can also add buttons right next to the search bar. Just
export <code>searchBarActions</code> as an array of objects
containing an <strong>id</strong>, a <strong>label</strong>, and a
<strong>type</strong>. The type can be <code>navigate</code> to open
a specific URL, <code>bang</code> to fill the search bar with your
trigger, or <code>custom</code>. If you use custom, your
<code>script.js</code> will listen for a
<code>search-bar-action</code> event that contains the action
details. You can also include an optional
<strong>icon</strong> image URL.
</p>
<h2>Plugin routes</h2>
<p>
Plugins can expose their own HTTP endpoints under the
<code>/api/plugin/<folderName>/</code> path. You do this by
exporting <code>routes</code> as an array containing the
<code>method</code>, <code>path</code>, and
<code>handler(req)</code>. Your method can be <code>get</code>,
<code>post</code>, <code>put</code>, <code>delete</code>, or
<code>patch</code>. The path is just the URL segment that comes
after your plugin id. Your handler receives the standard Request
object and needs to return a Response or a Promise that resolves to
a Response. These routes become available the moment your plugin
loads, meaning your <code>script.js</code> can call them immediately
using fetch.
</p>
<p>
When installed from the store, the plugin folder name is
<code><author>-<repo>-<plugin-name></code>. Never
hardcode that in your API URLs. In <strong>frontend</strong> scripts
use the injected <strong><code>__PLUGIN_ID__</code></strong> constant,
which Degoog injects automatically into every plugin script at serve
time. In <strong>backend</strong> plugin code use
<code>ctx.apiBase</code> or <code>ctx.routeUrl("path")</code> from
<code>init(ctx)</code>.
</p>
<pre><code>// frontend script.js
const MY_API = `/api/plugin/${__PLUGIN_ID__}/data`;
fetch(MY_API).then(r => r.json()).then(data => { /* ... */ });
// backend index.js
let apiBase = "";
export default {
routes: [{ method: "get", path: "/thumb", handler: async (req) => { /* ... */ } }],
init(ctx) { apiBase = ctx.apiBase; },
async execute() {
return { title: "Example", html: `<img src="${apiBase}/thumb?id=abc">` };
},
};</code></pre>
<h2 id="interceptors">Query interceptors</h2>
<p>
Interceptors run <strong>before</strong> the search engines execute.
They receive the raw query the user typed and return the query that
should actually be searched. The plugin can do anything in between:
correct spelling, expand abbreviations, translate, enrich, or replace
the query entirely. Export <code>interceptor</code> as an object with
a <strong>name</strong>, a <strong>description</strong>, and an
<strong>intercept(query, context)</strong> async function that returns
<code>{ query: string }</code>.
</p>
<p>
You can also return an optional <code>overrides</code> object to
influence how the search is executed - without touching the query text
at all. This is useful when your interceptor has enough information to
determine the best search context upfront.
</p>
<pre><code>export const interceptor = {
name: "My Interceptor",
description: "Does something to the query.",
settingsSchema: [
{ key: "enabled", label: "Enabled", type: "toggle", default: "true" },
],
configure(settings) {
// called when settings change
},
init(ctx) {
// same ctx as other plugin types: ctx.fetch, ctx.useCache, ctx.readFile
},
async intercept(query, context) {
// context: { fetch, useCache, lang }
// return the query to actually search - may be the original or anything else
// overrides is optional: searchType routes to a tab, lang/timeFilter override search params
return { query, overrides: { searchType: "my-tab" } };
},
};</code></pre>
<h3>Supported overrides</h3>
<ul>
<li><code>searchType</code> - route the search to a specific tab by its engine type (e.g. <code>"images"</code>, <code>"news"</code>, or any custom tab type registered by a plugin)</li>
<li><code>lang</code> - override the language for this search</li>
<li><code>timeFilter</code> - override the time filter (e.g. <code>"day"</code>, <code>"week"</code>)</li>
</ul>
<p>
All fields are optional. When multiple interceptors run, overrides are merged in order - later interceptors win for each field.
</p>
<p>
Interceptors are a plugin subtype - they live in the same
<code>data/plugins/</code> directory as bang commands and slots. A
single plugin folder can export an <code>interceptor</code> alongside
a <code>slot</code> or <code>command</code> if needed. There are no
builtin interceptors; all interceptors come from plugins.
</p>
<h2 id="multi-hook-plugins">Multi-hook plugins</h2>
<p>
A single plugin folder can export any combination of hooks - a
<code>slot</code>, an <code>interceptor</code>, a bang
<code>command</code>, a <code>tab</code>, <code>middleware</code>,
or a <code>route</code>. By default each hook gets its own settings
card in the UI. To merge them all into a single card with shared
settings, export a top-level <strong>plugin</strong> object as the
plugin's identity:
</p>
<pre><code>export const plugin = {
id: "my-plugin", // shared settingsId for all hooks in this file
name: "My Plugin", // name shown on the settings card
description: "...",
// fields listed here appear first in the combined settings form
settingsSchema: [
{ key: "url", label: "Service URL", type: "url" },
{ key: "apiKey", label: "API Key", type: "password", secret: true },
],
};
// registered as a hook - not shown as a separate card
export const slot = {
name: "My Slot",
position: "above-results",
// slot-specific fields (appended after plugin fields in the form)
settingsSchema: [],
configure(settings) { /* receives the full merged settings object */ },
async trigger(query) { return query.length > 0; },
async execute(query, context) { return { html: "" }; },
};
// registered as a hook - not shown as a separate card
export const interceptor = {
name: "My Interceptor",
// interceptor-specific fields (appended after slot fields in the form)
settingsSchema: [
{ key: "firstMode", label: "Enable first mode", type: "toggle" },
],
configure(settings) { /* also receives the full merged settings object */ },
async intercept(query) { return { query }; },
};</code></pre>
<p>
When <code>plugin</code> is present, both hooks use
<code>plugin.id</code> as their <code>settingsId</code>. The settings
form shows manifest fields first, then slot fields, then interceptor
fields. Saving calls <code>configure()</code> on each hook separately
with the same settings object - shared module-level state (caches,
config variables) works naturally since all hooks live in the same
file. Plugins that do not export <code>plugin</code> are unaffected
and continue to show as individual cards.
</p>
<h2>Request middleware</h2>
<p>
Middleware allows your plugin to hook into specific request flows.
You export <code>middleware</code> as an object containing an
<strong>id</strong>, a <strong>name</strong>, and a
<strong>handle(req, context)</strong> function. The context might
include specific route information like <code>settings-auth</code>.
Your function should return a Response, a redirect URL object, or
simply null to let the request continue normally. The application
uses this middleware for the <strong>settings gate</strong>. To
choose a plugin for the gate, just click Use as settings gate in
that plugin configuration menu under Settings. This updates your
<code>plugin-settings.json</code> file automatically.
</p>
<h2>Settings gate (login flow)</h2>
<p>
You can protect your settings using a simple password with
<code>DEGOOG_SETTINGS_PASSWORDS</code> or by using a
<strong>middleware plugin</strong>. When you use a plugin, anyone
opening the Settings page goes through your custom flow like a magic
link or external login before returning to the settings with a valid
session token.
</p>
<h3>What your middleware must do</h3>
<ul>
<li>
<strong>route "settings-auth"</strong>: Return a JSON object with
required set to true, valid set to false, and your loginUrl.
</li>
<li>
<strong>route "settings-auth-callback"</strong>: After a
successful authentication, return a redirect to
<code>/settings</code>. The application will issue a session token
and redirect the user automatically.
</li>
<li>
<strong>route "settings-auth-post"</strong>: If you do not want to
support password submissions via POST, just return a 400 error or
something similar.
</li>
</ul>
<p>
Make sure to expose a <code>GET /login</code> route that redirects
back to the callback URL. You can clear the
<code>degoog-settings-token</code> in your browser Session Storage
anytime you need to test the flow.
</p>
<h2>Example: minimal bang command</h2>
<p>
Here is what a simple folder at
<code>data/plugins/greeting/</code> looks like with an
<code>index.js</code>, <code>template.html</code>, and
<code>style.css</code> file.
</p>
<pre><code>let template = "";
export default {
name: "Greeting",
description: "Say hello",
trigger: "hello",
init(ctx) { template = ctx.template; },
async execute(args) {
const name = args.trim() || "world";
const html = template.replace("{{name}}", name);
return { title: "Hello", html };
},
};</code></pre>
<p><strong>template.html</strong></p>
<pre><code><div class="command-result greeting">
<h3 class="greeting-title">Hello, {{name}}!</h3>
</div></code></pre>
<p>
For your <strong>style.css</strong>, you should use variables like
<code>var(--text-primary)</code> to ensure everything matches. You
can find more details on the
<a href="styling.html">Styling</a> page.
</p>
<h2 id="declaring-client-exposure">Declaring client exposure</h2>
<p>
The settings page shows a small icon on each extension card indicating
whether the extension causes the user's browser to contact external
services directly. Set <code>isClientExposed</code> on your exported
object so users know what to expect:
</p>
<table>
<thead>
<tr>
<th>Value</th>
<th>Meaning</th>
<th>Badge</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>true</code></td>
<td>The browser makes direct requests to external services (images, APIs, scripts rendered into HTML).</td>
<td><i class="fa-solid fa-triangle-exclamation" style="color: var(--warning)"></i> Orange triangle</td>
</tr>
<tr>
<td><code>false</code></td>
<td>All network access goes through the server. Nothing contacts the outside from the browser.</td>
<td><i class="fa-solid fa-circle-check" style="color: var(--success)"></i> Green checkmark</td>
</tr>
<tr>
<td><em>not set</em></td>
<td>The extension does not declare its network behaviour. Users see an ambiguous indicator.</td>
<td><i class="fa-solid fa-circle-info" style="color: var(--warning); opacity: 0.6"></i> Grey info</td>
</tr>
</tbody>
</table>
<p>
Use <code>context.signProxyUrl(url)</code> to route external images
through the server proxy. Doing so means you can declare
<code>isClientExposed: false</code>.
</p>
<pre><code>export const slot = {
name: "My Slot",
isClientExposed: false, // all images are proxied via signProxyUrl
async execute(query, context) {
const imgUrl = context.signProxyUrl("https://example.com/cover.jpg");
return { html: `<img src="${imgUrl}">` };
},
};</code></pre>
<pre><code>export const slot = {
name: "My Slot",
isClientExposed: true, // renders raw external URLs the browser will fetch
async execute(query, context) {
return { html: `<img src="https://example.com/cover.jpg">` };
},
};</code></pre>
<h2>Debugging plugins</h2>
<p>
If you need to troubleshoot, set <code>LOG_LEVEL=debug</code> to
print the execution times for all your plugin types directly to the
server console. You can check the Environment variables page for
more details.
</p>
</main>
</div>
<div id="degoog-docs-backdrop" class="degoog-docs-backdrop"></div>
</div>
<script
src="https://code.jquery.com/jquery-4.0.0.min.js"
crossorigin="anonymous"
></script>
<script src="docs.js"></script>
<script src="docs-ui.js"></script>
</body>
</html>