// ==UserScript== // @name TW Friends // @version 0.01 // @description Friend Management for The West Events // @author hiroaki // @include http://*.the-west.*/game.php* // @namespace https://greasyfork.org/users/3197 // @downloadURL none // ==/UserScript== function hf(fn) { var script = document.createElement('script'); script.setAttribute("type", "application/javascript"); script.textContent = '(' + fn + ')();'; document.body.appendChild(script); document.body.removeChild(script); } hf (function() { HiroFriends = new Object ({ event : Game.sesData['Independence'].friendsbar, friends : [], total : 0, avail: 0, }); HiroFriends.init = function() { var hiro_div = document.createElement('div'); hiro_div.setAttribute("id", "hiro_friends_container"); hiro_div.setAttribute("style", "position: absolute; top: 32px; right: 50%; margin-right: 120px; z-index: 16; width: 180px; height: 36px; text-align: left; text-shadow: 1px 1px 1px #000; background: url('http://westzz.innogamescdn.com/images/interface/custom_unit_counter_sprite.png?2') no-repeat scroll 50% 0px transparent;"); hiro_div.innerHTML='
(' + val.time.formatDurationBuffWay() + ') | '); else { td = $('' + HiroFriends.event.label + " | ").click({ id: val.id, ev: e }, function (e) { $(this).parent().remove(); var t = e.handleObj.data; Ajax.remoteCall("friendsbar", "event", { player_id: t.id, event: t.ev }, function (e) { if (e.error) return MessageError(e.msg).show(); MessageSuccess(e.msg).show(); HiroFriends.friends[key].time = HiroFriends.event.cooldown; }) }) } tbl.append($('
' + idx + '. | ' + val.name + " | "), td)) ++ idx; }); var hiroWindow = wman.open("HiroFriends"+title, null).setMiniTitle(title).setTitle(title); var hiroPane = new west.gui.Scrollpane; hiroPane.appendContent(tbl); hiroWindow.appendToContentPane(hiroPane.getMainDiv()) }; HiroFriends.fetch = function() { var event_times = {}; HiroFriends.friends = new Array(); HiroFriends.total = HiroFriends.avail = 0; var server_time = (new ServerDate).getTime() / 1e3; $.post( "/game.php?window=friendsbar&mode=search", { search_type: "friends" } , function (data) { $.each(data.eventActivations, function (key, val) { if (val.event_name == 'Independence') event_times[val.friend_id] = val.activation_time; }); $.each(data.players, function (key, val) { if (val.name !== Character.name) { activation_time = (event_times[val.player_id] !== undefined) ? event_times[val.player_id]: 0; friend_time = activation_time + HiroFriends.event.cooldown - server_time; HiroFriends.friends.push ({ id: val.player_id, name: val.name, time: friend_time }); ++ HiroFriends.total; if (friend_time <= 0) ++ HiroFriends.avail; } }); HiroFriends.friends.sort(HiroFriends.compare); console.log (HiroFriends.friends); document.getElementById("hiro_friends").innerHTML = (HiroFriends.avail+" / "+HiroFriends.total); }); }; HiroFriends.init(); HiroFriends.fetch(); setInterval(function() { HiroFriends.fetch(); }, 120000); });