0

I've been looking all over for this, and I think the problem is that I inherently suck at programming or scripting of any sort, and I don't know the right words to use...

Basically: I want to make a Chrome extension that reads the the innerText value from the ticketing system at the place I work with. As an example...

<span class="infomsg">Tickets Found [<span id="tickets_count">5</span>]</span>

The goal would be for the extension to display the text "5" over the icon.

What's the best way to do this? I've tried configuring the background.html page with an iframe with the URL with the ticket count as the source, but then I run into the cross-domain scripting issue. document.getElementById("tickets_count").innerHTML can't use a specified URL, as near as I've found.

I'm sure I haven't described it very well at all - totally floundering here, to be honest...let me know what I can clarify, and I'll edit my post.

Thanks!

  • What do you mean by "can't use a specified URL"? And can you clarify what you mean by "without opening the page"? – inquiryqueue May 06 '15 at 17:38
  • Does this post on the difference between `innerHTML` and `innertext` accessors help? http://stackoverflow.com/questions/19030742/difference-between-innertext-and-innerhtml-in-javascript – inquiryqueue May 06 '15 at 17:39

1 Answers1

0

It depends on whether the page you're looking at is static (e.g. the server sends you HTML with this information already in it) or dynamic (e.g. some JavaScript on the page requests additional information and then adds this to the page).

If it's static, you can use XHR to request the page and find the string you need in the "raw" HTML response. You can't use getElementById in that case - you'll need to find a way to find the string yourself.

If it's dynamic, that won't work. An iframe-in-the-background approach is valid - but you can't access the contents of the iframe. Instead, you should inject a content script in that page and request the information you need.

I understand it's a broad answer - but your question is also quite broad.

Xan
  • 74,770
  • 16
  • 179
  • 206