use crate::prelude::*;
use super::{ SearchOptions };
pub struct Duck;
impl SearchOptions for Duck {
fn new() -> Self {
Self {}
}
fn url(&self) -> String {
str!("https://duckduckgo.com/")
}
fn search(&self, query: &str) -> String {
str!() + r##"
try {
let form = document.querySelector('main form#searchbox_homepage');
let input = form.querySelector('input[aria-autocomplete]');
input.focus();
input.value = ""## + query + r##"";
input.dispatchEvent(new Event('input', { bubbles: true }));
input.dispatchEvent(new Event('change', { bubbles: true }));
form.submit();
return true;
} catch {
return false;
}
"##
}
fn parse(&self) -> String {
str!() + r##"
try {
let links = [];
document.querySelectorAll('body a[href] p').forEach(elem => {
let href = elem.textContent
.replaceAll(" ", " ")
.replaceAll(/\s+›\s+/g, "/")
.trim();
if (href && href.startsWith("https://")) {
links.push(href);
}
});
return links;
} catch {
return [];
}
"##
}
}