Greasemonkey not working?

So I have the following Greasemonkey script:

// ==UserScript==
// @name       InstaTranslate+
// @namespace  http://use.i.E.your.homepage/
// @version    1.0.0
// @description  A browser add-on to easily translate words using the Google Translate engine.
// @include     http://*
// @copyright  2014+, Tyler Jablonski
// ==/UserScript==
function getSelectedText() {
    var text = "";
    if (typeof window.getSelection != "undefined") {
        text = window.getSelection().toString();
    } else if (typeof document.selection != "undefined" && document.selection.type == "Text") {
        text = document.selection.createRange().text;
    }
    return text;
}

function doSomethingWithSelectedText() {
    var selectedText = getSelectedText();
    if (selectedText && event.keyCode === 81) {
                var canDo = confirm("Would you like to translate this text?");
                if (canDo==true)
                {
                var myword=selectedText;
                var urlSetUp="http://www.translate.google.com/#auto/en/";
                var urlGo=urlSetUp.concat(myword);
                window.open(urlGo);
                }
    }
    else if (event.keyCode === 81) {
            var myword=prompt("What phrase would you like to translate?");
            if (myword!=null)
            {
            var urlSetUp="http://www.translate.google.com/#auto/en/";
            var urlGo=urlSetUp.concat(myword);
            window.open(urlGo);
            }
    }
}

document.onmouseup = doSomethingWithSelectedText;
document.onkeyup = doSomethingWithSelectedText;

Unfortunately, it does not work at all. However, when I copy and paste the code into the address bar and run it that way, it works fine. Why is this and what can I do to correct it?

Answers


Change function doSomethingWithSelectedText() to function doSomethingWithSelectedText(event), or add @grant none to your metadata block.


Need Your Help

Notes ACL Reader Level and Readers/Authors fields

lotus-notes

I have 3 groups in my ACL that are associated with a corresponding Role. Default is set to No Access. There are no user names listed in the ACL, only groups.

Smartface in action does not work on android devices

smartface.io

I have opened smartface in action application on the IDE, but it does not work on android devices. When the application opens just a white and empty page is appeared on the device screen.