SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    rochester hillz
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help ME with script

    hello im looking for a javascript, pretty simple but im nothing for making scripts, i just create and design web sites. Well i need a script that does this.
    Searchs web site<http://eternal-lands.solexine.fr/~radu/online_players.htm> for a name. and if it finds the name it puts up this image http://www.freewebs.com/shadowtactics/Online1.jpg, if it does not find a match it displays this http://www.freewebs.com/shadowtactics/offline.jpg.

    Eternal lands is an mmorpg i play with alot of my friends and have been wanting an online/offline status page for a while. That is simply all i ask a sample page of what im asking for here -->http://www.iostr.com/scoguild/online.php, please help me im no good at scripting.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't think this can be done with just javascript, you'd need a server side script (php or asp) to poll that page and supply the correct image.

  3. #3
    SitePoint Addict Guimauve's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, it can be done. Here's how:

    Code:
    <html>
    <head>
      <script>
        var httpObject = newXmlHTTP() ;
        var sourceURL  = "http://eternal-lands.solexine.fr/~radu/online_players.htm"
    
        function newXmlHTTP()
          {
          var xmlhttp;
          /*@cc_on @*/
          /*@if (@_jscript_version >= 5)
            // JScript gives us Conditional compilation, we can cope with old IE versions.
            // and security blocked creation of the objects.
            try {
              xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
              try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
              } catch (E) {
                xmlhttp = false;
              }
            }
          @else
            xmlhttp = false;
          @end @*/
    
          if (!xmlhttp) {
            if (typeof XMLHttpRequest != undefined) {
              xmlhttp = new XMLHttpRequest();
            } else {
              xmlhttp = false;
            }
          }
    
          return xmlhttp;
      }
    
      function checkOnline(userName) {
    
        httpObject.open("GET", sourceURL, true);
        httpObject.onreadystatechange=function() {
          var responseHTML ;
          var imageObject ;
    
          if (httpObject.readyState==4) {
    
           responseHTML = httpObject.responseText.toUpperCase() ;
           imageObject = document.getElementById("OnlineImage") ;
    
           if (responseHTML.indexOf('USER=' + userName.toUpperCase() + '"') > 0) {
             imageObject.src = "http://www.freewebs.com/shadowtactics/Online1.jpg" ;
             imageObject.style.display = "inline";
             }
           else {
             imageObject.src = "http://www.freewebs.com/shadowtactics/offline.jpg" ;
             imageObject.style.display = "inline";
             }
           }
          }
    
        httpObject.send(null)
        }
      </script>
      <style>
        body {
          font: bold 10pt Arial;
          }
        label {
          width: 120px;
          text-align: right;
          margin-top: 20px;
          }
      </style>
    </head>
    <body>
      <form name="form1">
        <fieldset style="width: 340px;">
          <legend>Eternal Lands Online Status</legend>
          <label for="userName">User Name:</label>
          <input id="userName" name="userName">
          <img id="OnlineImage" src="" style="display:none;">
          <br>
          <label>&nbsp;</label>
          <input type="button" value="Check if Online" onclick="checkOnline(document.form1.userName.value)">
        </fieldset>
      </form>
    </body>
    Charles

  4. #4
    SitePoint Member
    Join Date
    Nov 2004
    Location
    rochester hillz
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok now that i have the script where do i put and how do i make it show up all the users, im used to php but java im not, i need help where to put script and how to run for all my members

  5. #5
    SitePoint Addict Guimauve's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's an updated script that processes a list of players. Just change the top portion of the source to list all of your players like this:

    Code:
        playerList[playerList.length] = new player('Enderoth',      'Guildmaster, founder');
    Feel free to change the HTML that is built on the fly using the line variable.
    Code:
    <html>
    <head>
      <script>
        var playerList = new Array() ;
        playerList[playerList.length] = new player('Enderoth',      'Guildmaster, founder');
        playerList[playerList.length] = new player('Carrie',        'Guildmaster, founder');
        playerList[playerList.length] = new player('AlcheMistress', 'Sorceress');
        playerList[playerList.length] = new player('zMaster',       'Barbarian');
    
        var httpObject    = newXmlHTTP() ;
        var sourceURL     = 'http://eternal-lands.solexine.fr/~radu/online_players.htm'
        var userLookupURL = 'http://eternal-lands.solexine.fr/~radu/view_user.php?user='
        var responseHTML  = '' ;
    
        function newXmlHTTP() {
          var xmlhttp;
          /*@cc_on @*/
          /*@if (@_jscript_version >= 5)
          // JScript gives us Conditional compilation, we can cope with old IE versions.
          // and security blocked creation of the objects.
          try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
          catch (e) {
            try {
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
              }
            catch (E) {
              xmlhttp = false;
              }
            }
          @else
            xmlhttp = false;
          @end @*/
    
          if (!xmlhttp) {
            if (typeof XMLHttpRequest != undefined) {
              xmlhttp = new XMLHttpRequest();
              }
            else {
              xmlhttp = false;
              }
            }
    
          return xmlhttp;
          }
    
        function player(pName, pDescription) {
          this.name = pName ;
          this.description = pDescription ;
          }
    
        function isOnline(name) {
          if (responseHTML.indexOf('USER=' + name.toUpperCase() + '"') > 0) {
            return true ;
            }
          else {
            return false ;
            }
          }
    
        function loadPlayers() {
          var i ;
          var line = "" ;
          var div = document.getElementById("playerList");
    
          for (i=0; i < playerList.length; i++) {
            line += '<div class="player"><span class="name">'
            line += '<a href="' + userLookupURL + playerList[i].name + '">'
            line += playerList[i].name
            line += '</a></span>'
    
            if (isOnline(playerList[i].name)) {
              line += '<span class="status">Online</span>'
              }
            else
              {
              line += '<span class="status">Offline</span>'
              }
    
            line += '<div>' + playerList[i].description + '</div></div>'
            }
    
          div.innerHTML = line;
          }
    
        function init() {
          httpObject.open("GET", sourceURL, true);
    
          httpObject.onreadystatechange=function() {
            if (httpObject.readyState==4) {
              responseHTML = httpObject.responseText.toUpperCase() ;
              loadPlayers();
              }
            }
    
          httpObject.send(null)
          }
    
      </script>
      <style>
        body {
          font: normal 10pt Arial;
          }
    
        #playerList {
          margin-left: 30px;
          }
    
        #playerList .player {
          width: 230px;
          border: dashed 1px black;
          padding: 4px 10px 4px 10px;
          margin-top: 15px;
          }
    
        #playerList .name {
          font-weight: bold;
          width: 50%;
          }
    
        #playerList .status {
          width: 50%;
          text-align: right;
          }
      </style>
    </head>
    
    <body onload="init();">
      <h1>Welcome to the ETERNAL LANDS so and so Guild</h1>
      <h3>Members</h3>
      <div id="playerList">
        Loading member list, please wait.
      </div>
    </body>
    </html>
    Charles

  6. #6
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guimauve :
    Out of curiousity, may i ask from where you got that newXmlHTTP implementation ?

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's pretty slick!

    I've not used XML objects with javascript much, is that solution ok for all browsers/operating systems?

    Cheers

  8. #8
    SitePoint Addict Guimauve's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the deal, which I just found out this morning when I tried to test the script in Firefox 1.0.

    Firefox doesn't allow you to read from another domain using newXmlHTTP, so this script doesn't work in Firefox because it is trying to download status information from another web site. I have tested in Firefox where the URL is in the same domain and it works very well.

    You can find out more about newXmlHTTP at this page, which is where I got the initial implementation a while ago. The page also explains how to use it and the caveats.

    http://jibbering.com/2002/4/httprequest.html

    Charles


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •