someone_

Tera NA servers

Feb 20th, 2014
372
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @id             tera-servers
  3. // @name           tera-servers
  4. // @version        1.0
  5. // @namespace      hurr
  6. // @author         durr
  7. // @description    Keeps you notified whenever a TERA NA server goes down or up. Updates every 5 minutes.
  8. // @include        http://tera.enmasse.com/server-status
  9. // @run-at         window-load
  10. // ==/UserScript==
  11. try {
  12. var d = document, a = d.querySelector('[aria-controls="server-status-table"]'), regx = /<tr class="server-(up|down|maint)[^<]*<[^<]*<[^<]*<[^<]*/g, i,
  13.     servers = ["Ascension Valley","Celestial Hills - Roleplay","Highwatch","Lake of Tears","Mount Tyrannas","Tempest Reach","Valley of Titans"], msg = "", no = servers.length,
  14.     process = function (a) {
  15.         var b = new Array(no);
  16.         a = a.match(regx);
  17.         if (!a) return;
  18.         for ( i = 0; i < no; i++ ) {
  19.             b[ servers.indexOf( a[i].match(/[ACHLMTV][A-Za-z\- ]*$/)[0] ) ] = a[i].indexOf('u') === 18 ? true : false;
  20.         }
  21.         return b;
  22.     }, latest = process(d.body.innerHTML) || [!1,!1,!1,!1,!1,!1], xmlHttpTimeout,
  23.     list = d.querySelectorAll('tr[class^="server-"]'), stat, f = function () {
  24.         var x = new XMLHttpRequest();
  25.         x.open("GET", window.location.href, true);
  26.         x.setRequestHeader("Cache-Control", "no-cache");
  27.         x.onreadystatechange = function () {
  28.             if (x.readyState === 4) {
  29.                 if (x.status === 200 || x.status === 304) {
  30.                     var nw = process(x.responseText);
  31.                     clearTimeout(xmlHttpTimeout);
  32.                     if (!nw) return;
  33.                     for ( i = 0; i < no; i++ ) {
  34.                         if ( latest[i] !== nw[i] ) {
  35.                             stat = nw[i] ? "up" : "down";
  36.                             msg += servers[i] + " is " + stat + "\n";
  37.                             try{ list[i].className = "server-" + stat + " " + list[i].className.split(' ')[1]; } catch(e){}
  38.                         }
  39.                     }
  40.                     latest = nw;
  41.                     if (msg) { document.body.dispatchEvent(new CustomEvent("tera-server", {bubbles:true,detail:msg})); msg = "";}
  42.                 }
  43.             }
  44.         };
  45.         x.send(null);
  46.         xmlHttpTimeout = setTimeout(function (x) {
  47.             x.abort();
  48.             if ( !/true/.test(latest+"") ) return;
  49.             latest = [!1,!1,!1,!1,!1,!1];
  50.             for ( i = 0; i < no; i++ ) {
  51.                 try{ list[i].className = "server-down " + list[i].className.split(' ')[1]; } catch(e){}
  52.             }
  53.         }, 3E4, x);
  54.         setTimeout(f, 1 * 30 * 1E3);
  55.     };
  56. a && a.parentNode.removeChild(a);
  57. document.addEventListener("tera-server", function(a){
  58.     setTimeout(function(a){
  59.         alert(a.detail)
  60.     }, 50, a)
  61. }, false);
  62. f();
  63. } catch(e) {console.log(e.stack)}
  64. // https://archive.foolz.us/_/search/image/0VmPjU4uFVZ%2BEYoKqtJVBg%3D%3/page/1/
RAW Paste Data