Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/prem-k-r/MaterialYouNewTab/compare/v3.2...main)

### Improved

- Updated search suggestion behavior to autocomplete the current search term upon selection via keyboard ([@prem-k-r](https://github.com/prem-k-r)), ([@itz-rj-here](https://github.com/itz-rj-here)) ([#33](https://github.com/prem-k-r/MaterialYouNewTab/pull/33))

### Localized
Expand Down Expand Up @@ -65,7 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added edit functionality for todo list ([@GauravKukreti](https://github.com/GauravKukreti)) ([#719](https://github.com/XengShi/materialYouNewTab/pull/719))

### Changed

- DuckDuckGo now makes POST requests for search instead of GET requests ([@spj2401Dev](https://github.com/spj2401Dev))
- Weather retention time set to 7.25 minutes for user-entered API keys and 16 minutes otherwise ([@prem-k-r](https://github.com/prem-k-r)) ([#428](https://github.com/XengShi/materialYouNewTab/pull/428))
- Changed default Vietnamese font to 'Be Vietnam Pro' ([@prem-k-r](https://github.com/prem-k-r)) ([#442](https://github.com/XengShi/materialYouNewTab/pull/442))
- Improved date format for Japanese and Korean ([@prem-k-r](https://github.com/prem-k-r)), ([@dempavof](https://github.com/dempavof)) ([#529](https://github.com/XengShi/materialYouNewTab/pull/529))
Expand Down
27 changes: 27 additions & 0 deletions scripts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const searchQueryURLs = {
engine9: "https://www.quora.com/search?q="
};

// DDG supports POST requests
const duckDuckGoConfig = {
url: "https://duckduckgo.com/",
param: "q"
};

// Showing border or outline when you click on the searchbar
searchbar.addEventListener("click", function (event) {
event.stopPropagation();
Expand Down Expand Up @@ -218,13 +224,34 @@ function performSearch(query) {
var fallbackUrl = searchQueryURLs.engine1 + encodeURIComponent(searchTerm);
window.location.href = fallbackUrl;
}
} else if (selectedOption === "engine2") {
// POST request for DDG
submitPostSearch(duckDuckGoConfig, searchTerm);
} else {
// GET request for all other search engines
var searchUrl = searchQueryURLs[selectedOption] + encodeURIComponent(searchTerm);
window.location.href = searchUrl;
}
}
}

function submitPostSearch(config, searchTerm) {
const form = document.createElement("form");
form.method = "POST";
form.action = config.url;
form.style.display = "none";

const searchInput = document.createElement("input");
searchInput.type = "hidden";
searchInput.name = config.param;
searchInput.value = searchTerm;
form.appendChild(searchInput);

document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
}

// Event listeners
enterBTN.addEventListener("click", () => performSearch());
// Enter key handling is managed in the search suggestions keydown listener
Expand Down