Safari extension - Too many injected scripts responding to message

Posted by Philipp on Stack Overflow See other posts from Stack Overflow or by Philipp
Published on 2010-06-16T15:26:54Z Indexed on 2010/06/18 7:33 UTC
Read the original article Hit count: 420

Filed under:
|

Hi, I am trying to code a safari extension similar to Bubble Translate for Chrome.

when you click a button on the toolbar, it automatically translates the text currently selected to the language of your choice using the Google language API.

I use the following injected script to get the highlighted text and display the result (as an alert for the time being): http://pastebin.com/bYVuQAmp

I use the following global script to call the injected script if neccessary: hxxp://pastebin.com/VHaAKM5a

The problem I have is the following:

The script does not just get injected into the main page but also into ads and similar stuff that is embedded into the page. Due to that, the selected text gets translated multiple times because all the embedded scripts in one page respond to the message.

How can I make sure that the script is injected only into the right page or only the right page responds?

Thank you,

Philipp

© Stack Overflow or respective owner

Related posts about safari

Related posts about safari-extension