Skip to content

Commit

Permalink
fix: add new encode method to avoid deletion of characters outside AS…
Browse files Browse the repository at this point in the history
…CII set
  • Loading branch information
Karytonn committed Dec 11, 2022
1 parent fe3689a commit 2ed895f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tabnews-google-search",
"version": "0.0.2",
"version": "0.0.4",
"author": "Karytonn DEV",
"license": "ISC",
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "TabNews Google Search",
"description": "A simple search for the TabNews",
"version": "0.0.2",
"version": "0.0.4",
"manifest_version": 3,
"permissions": ["scripting"],
"action": {
"default_popup": "index.html",
"default_icon": "icon48.png"
Expand Down
20 changes: 15 additions & 5 deletions src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@ const input = document.querySelector('#search-input');
const GOOGLE_BASE_URL = "https://www.google.com/search?q=";
const GOOGLE_HACKING_SITE = "site%3Atabnews.com.br";

const encodeSearchText = (text) =>
encodeURIComponent(text)
.replace(/\-/g, '%2D')
.replace(/\_/g, '%5F')
.replace(/\./g, '%2E')
.replace(/\!/g, '%21')
.replace(/\~/g, '%7E')
.replace(/\*/g, '%2A')
.replace(/\'/g, '%27')
.replace(/\(/g, '%28')
.replace(/\)/g, '%29')
//by default "#" is encoded to %23

form.addEventListener('submit', (event) => {
event.preventDefault();

if(input.value) {

const textFindSanitized = input.value.replace(/\s/g, '%20')
const url = `${GOOGLE_BASE_URL}${textFindSanitized}+${GOOGLE_HACKING_SITE}`

const url = `${GOOGLE_BASE_URL}${encodeSearchText(input.value)}+${GOOGLE_HACKING_SITE}`;
window.open(url, "_target");

} else {
alert("😬 acho que esqueceu de inserir algo no campo de busca.")
alert("😬 acho que esqueceu de inserir algo no campo de busca.");
}

});
File renamed without changes.
Binary file added v-0-0-3.zip
Binary file not shown.

0 comments on commit 2ed895f

Please sign in to comment.