Search Selected text on Google with Ctrl+Q shortcut

Simple script to search google for results of a selected text with shortcut or hotkey Ctrl+Q (like ctrl+query). The mechanism is the same as the "Search Google for ..." in the right click menu

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name           Search Selected text on Google with Ctrl+Q shortcut
// @copyright      2021 - Balazs Zubak
// @description    Simple script to search google for results of a selected text with shortcut or hotkey Ctrl+Q (like ctrl+query). The mechanism is the same as the "Search Google for ..." in the right click menu
// @version        1.2
// @namespace      *
// @include        *
// @website	       https://greasyfork.org/en/scripts/428030-search-selected-text-on-google-with-ctrl-q-shortcut
// ==/UserScript==

document.addEventListener("keyup", function(e){
    // get selected text
    var seltext = getSelectedText();
    if(seltext && e.code == "KeyQ" && e.ctrlKey)
    {
        window.open('http://www.google.co.in/search?hl=en&q='+seltext , '_blank');
    }
});

function getSelectedText()
{
	// For Firefox, Safari and other non-IE browsers
	if(window.getSelection)
    {
		return window.getSelection();
    }
	else if(document.getSelection)
    {
		return document.getSelection();
    }
	else
	{
		// For IE
		var selection = document.selection && document.selection.createRange();
		if(selection.text)
        {
			return selection.text;
        }
		return false;
	}
	return false;
}