Reputation: 1654
I have an extension, and i want it do followings:
I looking for something like Google Dictionary extension
May anyone help me? what should i do ?
Thanks in advance. Morteza
Upvotes: 1
Views: 184
Reputation: 5605
When text is selected, the selected text will be shown in an alert window. A good starting point....
manifest.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 '';
} });
Here is a jsfiddle showing the functionality outside of a chrome extension...
Upvotes: 1