1

拡張機能があり、次のことをしたい:

  1. ユーザーが単語をダブルクリックして選択すると、単語が検出されます
  2. Word で何かを実行し、結果をツールチップのような小さなインタラクティブ ページに表示する

Google Dictionary 拡張機能のようなものを探しています

誰か助けてくれませんか?私は何をすべきか ?

前もって感謝します。モルテザ

4

1 に答える 1

1

テキストを選択すると、選択したテキストが警告ウィンドウに表示されます。良い出発点....

マニフェスト.json

{
  "name": "Selecty thingy",
  "version": "1.0.1",
  "manifest_version": 2,
  "description": "Selecty thingy",  
    "browser_action": {
  },
  "permissions": [
    "tabs", "*://*/*"
  ],
  "content_scripts": [
    {
      "matches": ["*://*/*"],
      "js": ["jquery-1.7.2.min.js","content_script.js"],
      "run_at": "document_end"
    }
  ]
}

content_script.js

$(document).ready(function(){
    $('html').mouseup(function() {
        var selectedText = getSelectedText();
        if(selectedText > ''){
            alert(selectedText);
        }
    });

    function getSelectedText() {
        if (window.getSelection) {
            var selection = window.getSelection().toString();
            if(selection.trim() > ''){
                return selection;
            }
        } else if (document.selection) {
            var selection = document.selection.createRange().text;
            if(selection.trim() > ''){
                return selection;
            }
        }
        return '';
    } });

これは、クロム拡張機能の外部の機能を示すjsfiddleです...

于 2013-08-29T16:21:56.817 に答える