// ==UserScript== // @name Bing to Google // @version 1 // @grant none // @include https://www.bing.com/search* // ==/UserScript==
try { console.log("[B2G] Initializing..."); addStyles(); addGoogleButton(); console.log("[B2G] Done."); } catch (error) { console.error("[B2G] Error: " + error); }
function /void/ addGoogleButton() {
const searchForm = document.querySelector("form#sb_form");
if (!searchForm) {
console.error("[B2G] Search Form not found");
return;
}
const googleSearchButton = document.createElement("DIV");
googleSearchButton.innerHTML = Ask Google
;
googleSearchButton.classList.add("google_button");
googleSearchButton.onclick = (evt) => searchOnGoogle();
searchForm.appendChild(googleSearchButton);
}
function /void/ addStyles() { const styles = `
.google_button { position: relative; display: inline-block; margin-left: 20px; transform: translateY(2px); user-select: none; font-size: 1em; color: #444; transition: 0.125s ease-in-out; }
.google_button:hover { color: #666; }
.google_button > img { vertical-align: middle; width: 1.5em; transform: translateY(-2px); line-height: 1em; }
`;
var pluginStyle = document.createElement("style"); pluginStyle.innerHTML = styles; document.head.appendChild(pluginStyle); }
function /void/ searchOnGoogle() { const query = getSearchQuery(); if (query == null) { console.error("[B2G] Could not find search query"); return; } document.location.href = "https://www.google.com/search?q=" + encodeURIComponent(query); }
function /string?/ getSearchQuery() { const searchQueryInput = document.querySelector("div.b_searchboxForm > input"); if (!searchQueryInput || !searchQueryInput.value) return null; return searchQueryInput.value; }