Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Catch the text changed event on a foreign page and do something

 
Ranch Hand
Posts: 153
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On this Minecraft server control panel website (which I didn't write), you can see the amount of players currently logged into the server in the 'Online Players 0/8' section at the top right.

I want to listen to the DOM for changes in that particular 'Online players' text. If the number changes to anything greater than '0 players online', I want to generate an alert('new player!'); and possibly play a sound.

What would be the best approach to do this? What scripting languages? I prefer to work with languages I already know such as Javascript. I read online it should be possible with jQuery.
I tried to inject a script at runtime when the page is loaded (Chrome Developer tools -> Elements section), but that doesn't seem to trigger anything. I tried to put jquery code between the <script></script> tags of the <head></head> tags, but that didn't seem to do anything. Not even a simple alert(); works, so I'm not sure what I'm doing wrong.

Here's what I know:
The control panel seems to be refreshing (polling) the 'status_onlineplayers' td element every second. If you inspect that element, you get this code:
<td id="status_onlineplayers">0 / 8</td>

So, does anyone know how to make this happen? I haven't been successful thus far.

Thanks.
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't just inject code into someone else's site. What you are trying to do is not possible (thankfully) with the security constraints in place.

You can resort to screen scraping if you like, but that's not going to affect the behavior of the other page.
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic