Google Search Translate Button

Adds a Translate button to the Google Search page

< Feedback on Google Search Translate Button

Review: Good - script works

§
Posted: 2017-12-17
Edited: 2017-12-17

Fix Quotes issue

I updated the script to fix an issue when searching a text containing quotes...

// ==UserScript==
// @name Google Search Translate Button
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Adds a Translate button to the Google Search page
// @author gllms
// @include *://www.google.tld/search*
// @grant none
// @licence https://opensource.org/licenses/mit-license.php
// ==/UserScript==

(function() {
'use strict';
var search = document.getElementById("lst-ib").value;
var search_unescaped = search.replace(new RegExp('"', 'g'),'"');
var url = "https://translate.google.com/#auto/en/" + search_unescaped;
document.getElementById("hdtb-msb-vis").innerHTML += `

`;
})();

gllmsAuthor
§
Posted: 2018-02-27

Thanks for the idea, but JavaScript already has a built-in function for escaping all sorts of characters: encodeURI(). So I'm going to use that in the new update.

Post reply

Sign in to post a reply.