Create a content script and use the following piece of code:

//Create a request listener
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { 
	//Check if the requested method equals getSelection
	if (request.method == "getSelection") 
		//Send back the selected text.
		sendResponse({data: window.getSelection().toString()}); 
	else 
		//Snub them.
		sendResponse({}); 
});

This will start a request listener. With this you can send a request named getSelect from your browser_action to the content_script.

To send the getSelect request you can use the following piece of code in your browser_action.

function selectedTextPaste() { 
	//Get the current selected tab
        chrome.tabs.getSelected(null, function(tab) { 
		//Send a request to the content script of the tab with as method getSelection
                chrome.tabs.sendRequest(tab.id, {method: "getSelection"}, function(response) { 
                        //do something with response.data 
                }); 
        }); 
}

And thats all you have to do! Now you can do whatever you want with the data the browser_action has received.

 

Today I discovered that it is possible to “increment” alphabet characters in PHP.

$letter = "a";
$letter++;
echo($letter);

This will result in b. The same applies to capitals.
Note that character variables can be incremented but not decremented!

Now you wonder what happens if you reach the last letter in the alphabet:

$letter = "z";
$letter++;
echo($letter);

This will result in aa. The same applies to capitals.

Did you know this was possible with PHP?

 

I made another Google Chrome extension: Pastebin.com
It’s the official extension for the #1 paste tool Pastebin.com.

With this extension you can quickly paste any type of text to the website http://pastebin.com. The extension installs a small icon in your browser. When you highlight any text in Google Chrome and press the ‘Pastebin’ button, it will automatically paste the selected text into the textarea. When you press submit you will be presented with a unique URL where you can find your pasted text.

You can download the extension from the Gallery.

© 2011 Joshua Lückers Suffusion theme by Sayontan Sinha