erinx icon

8chan status checker

erinx | PRO | 07/31/15 09:48:13 PM UTC | 0 ⭐ | 1158 👁️ | Never ⏰ | []
JavaScript |

3.04 KB

|

None

|

0 👍

/

0 👎

// ==UserScript==
// @name        8chan Status Checker
// @namespace   erin
// @description check the current status of 8chan during downtime, and see if it's safe to post
// @include     *8ch.net/*
// @version     0.1
// @grant       none
// ==/UserScript==
 
  function goChanStatus(){
      var d, db, h, namespace, $, $$, version;
     
      d = document;
      db = document.body;
      h = document.getElementsByTagName('head')[0];
     
      namespace = "chanStatus";
      version = 0.1;
     
      $ = function(s, p){
        if(!p || p == null){
          p = db;
        }
        return p.querySelector(s);
      };
     
      $$ = function(s, p){
        if(!p || p == null){
          p = db;
        }
        return p.querySelectorAll(s);
      };
     
      $.elm = function(t, a, s){
        var e = d.createElement(t);
        if(a){
          for (key in a){
            e.setAttribute(key, a[key]);
          }
        }
        if(s){
          s.appendChild(e);
        }
        return e;
      };
     
      $.htm = function(s, v){
        if(v == null){
          return s.innerHTML;
        }else{
          s.innerHTML = v;
        }
        return s;
      };
     
      $.time = function(t, c, l){
        if(c == false){
          return clearInterval(t);
        }else{
          if(l == true){
            return setInterval(function(){
              c();
            },t);
          }else{
            return setTimeout(function(){
              c();
            },t);
          }
        }
      };
   
         /*---------------------------------------------*/
  
  
    $tar = {};
    $tar['id'] = 'chanStatusTar';
    $tar['style'] = 'position:fixed;bottom:150px;right:50px;border:1px solid;background:#d6daf0;z-index: 1000;padding:10px;border-radius:10px;text-align:center;';
    $tar = $.elm('div', $tar, db);
    $.htm($tar, '<span id="chanStatusHeading"><h2 style="color:orange;">getting status...</h2></span><br><span id="chanStatusLoading">(waiting)</span>'); 
    function getChanStatus(){
        $.htm($('#chanStatusLoading'), '(connecting)');  
        var xhr = new XMLHttpRequest();
        xhr.open("GET", window.location.href);
        xhr.onreadystatechange = function(){
          if(xhr.readyState == 4) {
            $.htm($('#chanStatusLoading'), '(Updated)');
            $.time(1500, function(){ $.htm($('#chanStatusLoading'), '(waiting)'); }, false);
            $.time(5000, function(){ getChanStatus(); }, false);
            if(xhr.status != 200) {
              $.htm($('#chanStatusHeading'), '<h2 style="color:red;margin:0px !important;">' + xhr.status + '</h2><h3 style="color:red;margin:0px !important;">' + xhr.statusText + '</h3>');  
            }else{
              $.htm($('#chanStatusHeading'), '<h2 style="color:green;margin:0px !important;">200!</h2><h3 style="color:green;margin:0px !important;">Post!</h3>'); 
            }
          }
        }
        xhr.send();               
    }
    getChanStatus();
  }
 
  goChanStatus();

Comments