You are not connected. Please login or register


Virtual Pet




      • Please log in to reply

    View previous topic View next topic Go down  Message [Page 1 of 1]

    #1

    OfflineDrakius

    Drakius
    Admin
    Fri Sep 05, 2014 9:54 pm
    Code will be put here once I finish it's recognition function.

    use the first code below in an html sheet.
    Code:
    <html>
    <!-- Credits to Drakius (Nitemare) and Epixors for some HTML and some JS -->
      <head>
        <title>Virtual Pet</title>

        <script type="text/javascript" src="cookie.js"></script>

        <script type="text/javascript">
          var userName;

          function resizeSmile() {
            document.getElementById("rsmileImg").style.height = (document.body.clientHeight - 100) * 0.9;
          }

          function greetUser() {
            if (navigator.cookieEnabled)
              userName = readCookie("smile_username");
            if (userName)
              alert("Hello " + userName + ", I missed you :(.");
            else
              alert('Hello, I am your pet smilie.');
          }

          function touchSmile() {
            if (userName) {
              alert("I like the attention, " + userName + ". Thank you.");
            }
            else {
              userName = prompt("What is your name?");
              if (userName) {
                alert("It is good to meet you, " + userName + ".");
                if (navigator.cookieEnabled)
                  writeCookie("smile_username", userName, 5 * 365);
                else
                  alert("Cookies aren't supported/enabled in your browser, which means I won't remember you later. I'm sorry.");
              }
            }
            document.getElementById("smileImg").src = "http://2img.net/i/fa/i/avatars/gallery/Smiley_Jaunes/fi_av_smiles_y_39.gif";
            setTimeout("document.getElementById('smileImg').src = 'http://2img.net/i/fa/i/avatars/gallery/Smiley_Jaunes/fi_av_smiles_y_39.gif';", 5 * 60 * 1000);
          }
        </script>
      </head>

      <body onload="resizeSmile(); greetUser();" onresize="resizeSmile();">
        <div style="margin-top:100px; text-align:center">
          <img id="smileImg" src="http://2img.net/i/fa/i/avatars/gallery/Smiley_Jaunes/fi_av_smiles_y_14.gif" alt="happy" style="cursor:pointer" onclick="touchSmile();" />
        </div>
      </body>
    </html>

    Use this code for a JavaScript sheet. Save as cookie.js . You can set your cookies in this script too.

    Code:

    function writeCookie(name, value, days) {
      // Set cookie pls
      var expires = "";

      // Stuff... cool stuff...
      if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
      }

      // Cookies are yummy
      document.cookie = name + "=" + value + expires + "; path=/";
    }

    function readCookie(name) {
      // Find the specified cookie and return its value
      var searchName = name + "=";
      var cookies = document.cookie.split(';');
      for(var i=0; i < cookies.length; i++) {
        var c = cookies[i];
        while (c.charAt(0) == ' ')
          c = c.substring(1, c.length);
        if (c.indexOf(searchName) == 0)
          return c.substring(searchName.length, c.length);
      }
      return null;
    }

    function eraseCookie(name) {
      // Eat cookie
      writeCookie(name, "", -1);
    }

    To use this on FM, create an html page and enter the first code, use an external host to enter in the cookie script. Edit the cookie url to your need.

    https://code15.board-directory.net

    View previous topic View next topic Go down  Message [Page 1 of 1]



    Permissions in this forum:
    You cannot reply to topics in this forum