Skip to content

Commit

Permalink
DuckDuckGo suggestions and Obfuscate
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebelung-Dev committed Mar 26, 2023
1 parent 436bc4a commit bc195b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
- [x] Move roadmap
- [x] Update Github and Discord links
- [x] Footer component
- [x] Use DuckDuckGo suggestions
- [x] Obfuscate suggestions

### Roadmap
The roadmap has moved [here](https://github.com/orgs/Metallic-Web/projects/1/views/1).
18 changes: 10 additions & 8 deletions src/pages/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { bareServerURL } from "../consts.js";
import { getLink } from "../util.js";
import { useLocalAppearance } from "../settings.js";
import { useTranslation } from 'react-i18next';
import { renderToStaticMarkup } from 'react-dom/server';

function Home() {
const { t } = useTranslation("home");
Expand Down Expand Up @@ -48,18 +49,19 @@ function Home() {

try {
var site = await bare.fetch(
"https://www.google.com/complete/search?client=gws-wiz&q=" + query
"https://duckduckgo.com/ac/?q=" + query + "&type=list"
);
results = await site.text();
results = JSON.parse(
results.replaceAll("window.google.ac.h(", "").slice(0, -1)
)[0];
results.forEach((item, number) => (results[number] = item[0]));
results = await site.json();
results = results[1];
results = results.slice(0, 6);
} catch (err) {
console.error(err);
results = [];
}
results = results.map((result) => {
return renderToStaticMarkup(<Obfuscate>{result}</Obfuscate>);
})

setSuggestions(results);
if (suggestionsChildren.current.children.length === 0) {
hideOmnibox();
Expand Down Expand Up @@ -115,7 +117,7 @@ function Home() {
e.target.className !== "search" &&
e.target.className !== "searchicon" &&
e.target.className !== "suggestions" &&
e.target.className !== "sugg"
e.target.className !== "link sugg"
) {
if (omniboxcontainer.current.hasAttribute("open")) {
hideOmnibox();
Expand Down Expand Up @@ -163,7 +165,7 @@ function Home() {
{suggestions.map((item, i) => (
<div
key={i}
className="sugg"
className="link sugg"
onClick={(e) => submit(e.target.textContent)}
dangerouslySetInnerHTML={{ __html: item }}
></div>
Expand Down

0 comments on commit bc195b6

Please sign in to comment.