blob: c443b723cb5396d00f094f9d3d727d8faa7f7381 (
plain)
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
|
// Extracted from newOS4 index.html — DuckDuckGoModule
class DuckDuckGoModule {
constructor() {
this.commands = {};
this.terminal = null;
}
getHelpInfo() {
return {
'ddg': 'ddg <query> — Search DuckDuckGo (opens query in new tab)',
'duck': 'duck <query> — Alias for ddg',
};
}
registerCommands() {
this.commands['ddg'] = (args) => this.search(args);
this.commands['duck'] = (args) => this.search(args);
}
async search(args) {
if (!args[0]) {
this.terminal.print("Usage: ddg <search-query>", "warning");
this.terminal.print("Example: ddg javascript tutorials", "info");
this.terminal.print("Note: Due to CORS, results may be limited. Try 'search' command for better results.", "warning");
return;
}
const query = args.join(' ');
this.terminal.print(`🦆 DuckDuckGo Search: ${query}`, "info");
// DuckDuckGo doesn't have a public API, so we provide alternatives
this.terminal.print("⚠️ DuckDuckGo doesn't provide a public API for direct access.", "warning");
this.terminal.print("Opening search in new tab...", "info");
// Open in new tab as fallback
const ddgUrl = `https://duckduckgo.com/?q=${encodeURIComponent(query)}`;
window.open(ddgUrl, '_blank');
this.terminal.print(`\n💡 Alternative: Use 'search <query>' for SearXNG (privacy-focused)`, "info");
this.terminal.print(`🔗 Direct link: ${ddgUrl}`, "info");
}
}
|