Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @id tera-servers
- // @name tera-servers
- // @version 1.0
- // @namespace hurr
- // @author durr
- // @description Keeps you notified whenever a TERA NA server goes down or up. Updates every 5 minutes.
- // @include http://tera.enmasse.com/server-status
- // @run-at window-load
- // ==/UserScript==
- try {
- var d = document, a = d.querySelector('[aria-controls="server-status-table"]'), regx = /<tr class="server-(up|down|maint)[^<]*<[^<]*<[^<]*<[^<]*/g, i,
- servers = ["Ascension Valley","Celestial Hills - Roleplay","Highwatch","Lake of Tears","Mount Tyrannas","Tempest Reach","Valley of Titans"], msg = "", no = servers.length,
- process = function (a) {
- var b = new Array(no);
- a = a.match(regx);
- if (!a) return;
- for ( i = 0; i < no; i++ ) {
- b[ servers.indexOf( a[i].match(/[ACHLMTV][A-Za-z\- ]*$/)[0] ) ] = a[i].indexOf('u') === 18 ? true : false;
- }
- return b;
- }, latest = process(d.body.innerHTML) || [!1,!1,!1,!1,!1,!1], xmlHttpTimeout,
- list = d.querySelectorAll('tr[class^="server-"]'), stat, f = function () {
- var x = new XMLHttpRequest();
- x.open("GET", window.location.href, true);
- x.setRequestHeader("Cache-Control", "no-cache");
- x.onreadystatechange = function () {
- if (x.readyState === 4) {
- if (x.status === 200 || x.status === 304) {
- var nw = process(x.responseText);
- clearTimeout(xmlHttpTimeout);
- if (!nw) return;
- for ( i = 0; i < no; i++ ) {
- if ( latest[i] !== nw[i] ) {
- stat = nw[i] ? "up" : "down";
- msg += servers[i] + " is " + stat + "\n";
- try{ list[i].className = "server-" + stat + " " + list[i].className.split(' ')[1]; } catch(e){}
- }
- }
- latest = nw;
- if (msg) { document.body.dispatchEvent(new CustomEvent("tera-server", {bubbles:true,detail:msg})); msg = "";}
- }
- }
- };
- x.send(null);
- xmlHttpTimeout = setTimeout(function (x) {
- x.abort();
- if ( !/true/.test(latest+"") ) return;
- latest = [!1,!1,!1,!1,!1,!1];
- for ( i = 0; i < no; i++ ) {
- try{ list[i].className = "server-down " + list[i].className.split(' ')[1]; } catch(e){}
- }
- }, 3E4, x);
- setTimeout(f, 1 * 30 * 1E3);
- };
- a && a.parentNode.removeChild(a);
- document.addEventListener("tera-server", function(a){
- setTimeout(function(a){
- alert(a.detail)
- }, 50, a)
- }, false);
- f();
- } catch(e) {console.log(e.stack)}
- // https://archive.foolz.us/_/search/image/0VmPjU4uFVZ%2BEYoKqtJVBg%3D%3/page/1/
Advertisement
Add Comment
Please, Sign In to add comment