Skip to content

Commit

Permalink
feat: random user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Hunam6 committed Apr 21, 2021
1 parent aa8ad4d commit 1816146
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
- No ads
- Proxy support (maybe Tor too in the future)
- Customizable but requiring almost no or no configuration (simple to use)
- *Todo Tree
surely way more*

### Documentation

Expand Down
13 changes: 12 additions & 1 deletion app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,22 @@ const search = async (params: Record<string, string>) => {
else if (params.lang != undefined) url += '&hl=' + params.lang
}

//Random user agent
const rdmStr = () => Date.now().toString(36) + Math.random().toString(36).substring(2)
const OSs = [
'Windows NT;',
'Macintosh',
'X11; Linux x86_64',
'X11; Linux i686',
'X11; CrOS i686',
'X11; OpenBSD i386',
'X11; NetBSD'
]
const getDoc = async (url: string) =>
new DOMParser().parseFromString(
await fetch(url, {
headers: {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41'
'user-agent': `Mozilla/5.0 (${OSs[~~(Math.random() * OSs.length)]} ${rdmStr()}) AppleWebKit/${rdmStr()} (KHTML, like Gecko) Chrome/${Math.floor(Math.random() * (500 - 50)) + 49} Safari/${rdmStr()} OPR/${rdmStr()}`
}
}).then(res => res.text()),
'text/html'
Expand Down
3 changes: 2 additions & 1 deletion views/images.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
}
main>img {
margin-bottom: 1rem;
margin: .5rem .25rem;
cursor: pointer;
}
Expand All @@ -111,6 +111,7 @@
padding: 2.5rem 1rem;
text-align: center;
width: 32.5%;
height: 75vh;
}
figure {
Expand Down

0 comments on commit 1816146

Please sign in to comment.