-
-
Save austin-dudzik/419789777b2510d00f7add77d57f9a22 to your computer and use it in GitHub Desktop.
Companion code for "Earn Microsoft Rewards from any search engine (w/JavaScript)" tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Loading...</title> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> | |
</head> | |
<body> | |
<script> | |
// Run when the document is ready | |
$(document).ready(function () { | |
// Create a new variable to grab search params | |
var urlParams = new URLSearchParams(window.location.search); | |
// Get the specific query | |
var searchParam = urlParams.get('q'); | |
var searchProvider = urlParams.get('p'); | |
// Create hidden iframe and load Bing search | |
$("<iframe>").attr({ src: "https://bing.com?q=" + searchParam, id: "bingSearch" }).css("display", "none").appendTo("body"); | |
// Add loading message to page | |
$("<p>").text("Loading...").appendTo("body"); | |
// Logic to decide which provider to use | |
switch (searchProvider) { | |
case "google": | |
providerUrl = "https://google.com/search?q="; | |
break; | |
case "yahoo": | |
providerUrl = "https://search.yahoo.com/search?p="; | |
break; | |
case "baidu": | |
providerUrl = "http://www.baidu.com/s?wd="; | |
break; | |
case "aol": | |
providerUrl = "https://search.aol.com/aol/search?q="; | |
break; | |
case "ask.com": | |
providerUrl = "https://www.ask.com/web?q="; | |
break; | |
case "duckduckgo": | |
providerUrl = "https://duckduckgo.com/?q="; | |
break; | |
case "yandex": | |
providerUrl = "https://yandex.com/search/?text="; | |
break; | |
default: | |
providerUrl = searchProvider; | |
} | |
// Once Bing search has loaded... | |
$("#bingSearch").on("load", function () { | |
// Redirect to Google results | |
window.location.replace(providerUrl + searchParam); | |
}) | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment