Advertisement
erinx

8chan status checker

Jul 31st, 2015
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        8chan Status Checker
  3. // @namespace   erin
  4. // @description check the current status of 8chan during downtime, and see if it's safe to post
  5. // @include     *8ch.net/*
  6. // @version     0.1
  7. // @grant       none
  8. // ==/UserScript==
  9.  
  10.   function goChanStatus(){
  11.       var d, db, h, namespace, $, $$, version;
  12.      
  13.       d = document;
  14.       db = document.body;
  15.       h = document.getElementsByTagName('head')[0];
  16.      
  17.       namespace = "chanStatus";
  18.       version = 0.1;
  19.      
  20.       $ = function(s, p){
  21.         if(!p || p == null){
  22.           p = db;
  23.         }
  24.         return p.querySelector(s);
  25.       };
  26.      
  27.       $$ = function(s, p){
  28.         if(!p || p == null){
  29.           p = db;
  30.         }
  31.         return p.querySelectorAll(s);
  32.       };
  33.      
  34.       $.elm = function(t, a, s){
  35.         var e = d.createElement(t);
  36.         if(a){
  37.           for (key in a){
  38.             e.setAttribute(key, a[key]);
  39.           }
  40.         }
  41.         if(s){
  42.           s.appendChild(e);
  43.         }
  44.         return e;
  45.       };
  46.      
  47.       $.htm = function(s, v){
  48.         if(v == null){
  49.           return s.innerHTML;
  50.         }else{
  51.           s.innerHTML = v;
  52.         }
  53.         return s;
  54.       };
  55.      
  56.       $.time = function(t, c, l){
  57.         if(c == false){
  58.           return clearInterval(t);
  59.         }else{
  60.           if(l == true){
  61.             return setInterval(function(){
  62.               c();
  63.             },t);
  64.           }else{
  65.             return setTimeout(function(){
  66.               c();
  67.             },t);
  68.           }
  69.         }
  70.       };
  71.    
  72.          /*---------------------------------------------*/
  73.  
  74.  
  75.     $tar = {};
  76.     $tar['id'] = 'chanStatusTar';
  77.     $tar['style'] = 'position:fixed;bottom:150px;right:50px;border:1px solid;background:#d6daf0;z-index: 1000;padding:10px;border-radius:10px;text-align:center;';
  78.     $tar = $.elm('div', $tar, db);
  79.     $.htm($tar, '<span id="chanStatusHeading"><h2 style="color:orange;">getting status...</h2></span><br><span id="chanStatusLoading">(waiting)</span>');
  80.     function getChanStatus(){
  81.         $.htm($('#chanStatusLoading'), '(connecting)');  
  82.         var xhr = new XMLHttpRequest();
  83.         xhr.open("GET", window.location.href);
  84.         xhr.onreadystatechange = function(){
  85.           if(xhr.readyState == 4) {
  86.             $.htm($('#chanStatusLoading'), '(Updated)');
  87.             $.time(1500, function(){ $.htm($('#chanStatusLoading'), '(waiting)'); }, false);
  88.             $.time(5000, function(){ getChanStatus(); }, false);
  89.             if(xhr.status != 200) {
  90.               $.htm($('#chanStatusHeading'), '<h2 style="color:red;margin:0px !important;">' + xhr.status + '</h2><h3 style="color:red;margin:0px !important;">' + xhr.statusText + '</h3>');  
  91.             }else{
  92.               $.htm($('#chanStatusHeading'), '<h2 style="color:green;margin:0px !important;">200!</h2><h3 style="color:green;margin:0px !important;">Post!</h3>');
  93.             }
  94.           }
  95.         }
  96.         xhr.send();              
  97.     }
  98.     getChanStatus();
  99.   }
  100.  
  101.   goChanStatus();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement