// ==UserScript== // @name TW Friends // @name:el TW Friends // @name:es TW Friends // @name:fr TW Friends // @name:pt-PT TW Friends // @version 0.20 // @description Friend Management for The West Events // @description:el Διαχείριση Φίλων για τις Εκδηλώσεις του The West // @description:es Gestión de Amigos para Eventos de The West // @description:fr Gestion des Amis pour les Evénements de The West // @description:pt-PT Gestão de amigos para eventos no The West // @author hiroaki // @translation pepe100 (es_ES) // @translation jccwest (pt_PT) // @include http://*.the-west.*/game.php* // @include https://*.the-west.*/game.php* // @grant none // @namespace https://greasyfork.org/users/3197 // @downloadURL none // ==/UserScript== function hiroFriendsScript(fn) { var script = document.createElement('script'); script.setAttribute("type", "application/javascript"); script.textContent = '(' + fn + ')();'; document.body.appendChild(script); document.body.removeChild(script); } hiroFriendsScript(function() { var VERSION = 0.20; var installURL = "https://greasyfork.org/scripts/2992-tw-friends"; var codeURL = "https://greasyfork.org/scripts/2992-tw-friends/code/TW%20Friends.user.js"; var versionURL = "https://gist.githubusercontent.com/TWFriends/974718d615afe3d2c2a2/raw/version?"+Date.now(); var scriptName = "TW Friends"; var scriptAuthor = "hiroaki"; var refreshMs = 2 * 60 * 1e3; // 2 minutes HiroFriends = { api: TheWestApi.register('HiroFriends', scriptName, '2.04', Game.version.toString(), scriptAuthor, installURL), version: VERSION, latestVersion: undefined, storageItem: "HiroFriends.version", cdnBase: '', eventName : '', eventInfo : {}, eventEndStamp : 0, friends : [], interval: false, locale: 'en_US', pendingInvitations: 0, messages: { el_GR: { description: '

Διαχείριση Φίλων για τις Εκδηλώσεις του The West

Μην κλικάρετε πολύ γρήγορα, για να αποφύγετε ένα σερί κακής τύχης :)

Υποστηριζόμενες Εκδηλώσεις:

Συζήτηση στο Φόρουμ | Feedback: Αναφορά Bugs, Ιδέες, Μεταφράσεις.

Ευχαριστίες: jccwest, noolas, pepe100

', version: 'έκδοση', upgrade: 'Μια νέα έκδοση είναι διαθέσιμη. Θες να την εγκαταστήσεις;', refresh: 'Ανανέωση', timeLeft: 'Χρόνος που υπολείπεται μέχρι το τέλος της εκδήλωσης', serverTime: 'ώρα διακομιστή', availFriends: 'Αριθμός Φιλων στους οποίους μπορείς να στείλεις τώρα', totalFriends: 'Αριθμός Φίλων', pendingInvitation: 'Μία εκκρεμής πρόσκληση', pendingInvitations: 'εκκρεμείς πρoσκλήσεις', noFriends: 'Δεν έχεις φίλους', name: 'Όνομα', received: 'Έλαβες', removeFriend: 'Αφαίρεση φίλου', removeConfirm: 'Θέλεις πραγματικά να διαγράψεις αυτόν τον παίχτη από τη λίστα;', removeSuccess: 'Ο φίλος αφαιρέθηκε από τη λίστα.', removeFailed: 'Ο φίλος δεν μπόρεσε να αφαιρεθεί', exporter: 'Εξαγωγή', everything: 'Όλα', stats: 'Στατιστικά', since: 'από', collected: 'Έχεις συλλέξει', friends: 'Φίλοι', jobs: 'Εργασίες', fortBattles: 'Μάχες Οχυρών', adventures: 'Περιπέτειες', duels: 'Μονομαχίες', npcDuels: 'Μονομαχίες με NPC', construction: 'Χτίσιμο', itemUse: 'Χρήση Αντικειμένων', other: 'Άλλα', used: 'Έχεις χρησιμοποιήσει', timerReset: 'Μηδενισμός χρονομέτρου', bribe: 'Δωροδοκίες', nextYear: 'Του χρόνου', theEnd: 'Τετέλεσται', }, en_US: { description: '

Friend Management for The West Events

Don't click too fast, to avoid a streak of bad luck upon you :)

Supported Events:

Feedback: Bug Reports, Ideas, Translations (in English).

Credits: jccwest, noolas, pepe100

', version: 'version', upgrade: 'A new version is available. Do you want to upgrade now?', refresh: 'Refresh', timeLeft: 'Time Left until the event ends', serverTime: 'server time', availFriends: 'Number of Friends you can send now', totalFriends: 'Number of Friends', pendingInvitation: 'One pending invitation', pendingInvitations: 'pending invitations', noFriends: 'No Friends', name: 'Name', received: 'Received', removeFriend: 'Remove friend', removeConfirm: 'Do you really want to delete this player from the list?', removeSuccess: 'Friend removed from your list.', removeFailed: 'Friend could not be removed', exporter: 'Export', everything: 'Everything', stats: 'Stats', since: 'since', collected: 'Collected', friends: 'Friends', jobs: 'Jobs', fortBattles: 'Fort Battles', adventures: 'Adventures', duels: 'Duels', npcDuels: 'NPC Duels', construction: 'Construction', itemUse: 'Item Use', other: 'Other', used: 'Used', timerReset: 'Reset Timers', bribe: 'Bribe', nextYear: 'Next Year', theEnd: 'The End', }, es_ES: { description: '

Gestión de Amigos para Eventos de The West

No haga clic demasiado rápido, para evitar una racha de mala suerte :)

Eventos soportados:

Comentarios: Bug Reports, Ideas, Translations (in English).

Créditos: jccwest, noolas, pepe100

', version: 'versión', upgrade: 'Una nueva versión está disponible. ¿Quieres instalarla ahora?', refresh: 'Actualizar', timeLeft: 'Tiempo que queda hasta el final del evento', serverTime: 'hora del servidor', availFriends: 'Número de Amigos que se puede enviar ahora', totalFriends: 'Número de Amigos', pendingInvitation: 'Una invitación pendiente', pendingInvitations: 'invitaciones pendientes', noFriends: 'Sin Amigos', name: 'Nombre', received: 'Recibidos', removeFriend: 'Remover amigo', removeConfirm: '¿Estas seguro que quieres eliminar a este jugador de tu lista?', removeSuccess: 'Amigo removido de tu lista', removeFailed: 'El amigo no ha podido ser eliminado', exporter: 'Exportar', everything: 'Todo', stats: 'Estadísticas', since: 'desde', collected: 'Conseguidos', friends: 'Amigos', jobs: 'Trabajos', fortBattles: 'Batallas de fuertes', adventures: 'Aventuras', duels: 'Duelos', npcDuels: 'Duelos NPC', construction: 'Ampliación', itemUse: 'Objetos usados', other: 'Otros', used: 'Usados', timerReset: 'Reiniciar temporizadores', bribe: 'Soborno', nextYear: 'El próximo año', theEnd: 'Final', }, fr_FR: { description: '

Gestion des Amis pour les Evénements de The West

Ne cliquez pas trop vite, pour éviter une série de malchance sur vous :)

Evénements:

Commentaires: Bug Reports, Ideas, Translations (in English).

Credits: jccwest, noolas, pepe100

', version: 'version', upgrade: 'Une nouvelle version est disponible. Installer maintenant?', refresh: 'Rafraîchir', timeLeft: "Temps restant jusqu'à la fin de l'événement", serverTime: 'horaire du serveur', availFriends: 'Nombre des amis que tu peux envoyer maintenant', totalFriends: 'Nombre des Amis', pendingInvitation: 'Une invitation en attente', pendingInvitations: 'invitations en attentes', noFriends: "Pas d'Amis", name: 'Nom', received: 'Tu as reçu', removeFriend: "Supprimer l'ami(e)", removeConfirm: 'Veux-tu vraiment supprimer ce joueur de la liste?', removeSuccess: 'Ami supprimé de la liste', removeFailed: "L'ami n'a pas pu être supprimé", exporter: 'Exportation', everything: 'Tout', stats: 'Statistiques', since: 'à partir de', collected: 'Collectés', friends: 'Amis', jobs: 'Travaux', fortBattles: 'Batailles', adventures: 'Aventures', duels: 'Duels', npcDuels: 'Duels PNJ', construction: 'Agrandissement', itemUse: 'Objets utilisés', other: 'Autres', used: 'Utilisés', timerReset: 'Se battre en duel', bribe: 'Soudoyer', nextYear: "L'année prochaine", theEnd: 'La Fin', }, pt_PT: { description: '

Gestão de amigos para eventos no The West

não clique rápido demais, para evitar uma maré de azar :)

Eventos suportados:

Comentários: Bug Reports, Ideas, Translations (in English).

Créditos: jccwest, noolas, pepe100

', version: 'versão', upgrade: 'A nova versão está disponível. Atualize agora?', refresh: 'Actualizar', timeLeft: 'Tempo restante até ao final do evento', serverTime: 'hora do servidor', availFriends: 'Número de amigos a quem pode enviar agora', totalFriends: 'Número de Amigos', pendingInvitation: 'Um convite pendente', pendingInvitations: 'convites pendentes', noFriends: 'Sem Amigos', name: 'Nome', received: 'Recebidos', removeFriend: 'Remover amigo', removeConfirm: 'Queres mesmo remover amigo da lista ?', removeSuccess: 'Amigo removido da lista', removeFailed: 'Amigo não pode ser removido', exporter: 'Exportar', everything: 'Tudo', stats: 'Estatísticas', since: 'desde', collected: 'Recolhidos', friends: 'Amigos', jobs: 'Trabalhos', fortBattles: 'Batalhas de Forte', adventures: 'Aventuras', duels: 'Duelos', npcDuels: 'Duelos NPC', construction: 'Construção', itemUse: 'Itens usados', other: 'Outros', used: 'Usados', timerReset: 'Reiniciar temporizadores', bribe: 'Suborno', nextYear: 'Próximo Ano', theEnd: 'Final', }, }, timeLeft : 0, total : 0, avail: 0, log: { firstLog: Date.now()/1e3, lastLog: 0, friendLog: {}, entries: [], count_friends: 0, count_job: 0, count_duel: 0, count_npc: 0, count_fort: 0, count_mpi: 0, count_build: 0, count_item: 0, count_other: 0, count_reset: 0, count_bribe: 0, times_reset: 0, times_bribe: 0, received: 0, used: 0 }, spanCounter: $("", { id: "hiro_friends_counter", style: "position: absolute; right: 5px; color: #f8c57c; font-size: 13pt; height: 25px; line-height: 25px; bottom: 0px" }), spanInvitations: null, spanTimeLeft: null, eventManager: function(eventName) { if(undefined === Game.sesData[eventName] || undefined === Game.sesData[eventName].friendsbar) return false; this.eventName = eventName; this.eventInfo = Game.sesData[eventName].friendsbar; if(undefined === Game.sesData[this.eventName].meta.end) return false; this.eventEndStamp = (buildTimestamp(Game.sesData[this.eventName].meta.end) - Game.serverTimeDifference) / 1e3; this.timeLeft = this.eventEndStamp - Game.getServerTime(); if(this.timeLeft < 0) return false; this.cdnBase = (undefined === Game.cdnURL) ? "https://westzzs.innogamescdn.com" : Game.cdnURL; this.getLog(); this.spanTimeLeft = $("", { id: "hiro_event_timeleft", style: "position: absolute; left: 5px; color: #d3d3d3; font-size: 11px; height: 25px; line-height: 25px; cursor: pointer", title: this.localeMsg('timeLeft')+'
('+new Date(buildTimestamp(Game.sesData[this.eventName].meta.end)).toDateTimeStringNice()+' '+this.localeMsg('serverTime')+')' }); var eventImage = this.cdnBase + "/images/interface/friendsbar/events/" + this.eventName + ".png"; // event based var divContainer = $("
", { id: "hiro_friends_container", 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('"+this.cdnBase+"/images/interface/custom_unit_counter_sprite.png?2') no-repeat scroll 50% 0px transparent;" }) var divCounter = $("
", { id: "hiro_friends", style: "background: url('"+this.cdnBase+"/images/interface/custom_unit_counter_sprite.png?2') no-repeat scroll 0 -36px rgba(0, 0, 0, 0); height: 25px; left: 32px; line-height: 25px; padding: 0 5px; position: absolute; top: 3px; width: 105px; z-index: 1; text-shadow: 1px 1px 1px #000;" }); var divRefresh = $("
", { style: "width: 24px; height: 24px; position: absolute; left: 8px; top: 3px; z-index: 3; padding: 4px 0px 0px 4px;" }); var spanRefresh = $('', { title: this.localeMsg('refresh'), style: "display: inline-block; width: 20px; height: 20px; cursor: pointer; background: url('"+this.cdnBase+"/images/tw2gui/window/window2_buttons.png?5') repeat scroll 0px -20px transparent;" }); var spanSend = $("", { style: "width: 26px; height: 26px; left: auto; position: absolute; right: 7px; top: 2px; z-index: 3;" }); var imageSend = $("", { src: eventImage, title: this.eventInfo.label, style: "width: 26px; height: 26px; cursor: pointer" }); if(this.pendingInvitations) { this.spanCounter.css("right", "20px"); this.spanInvitations = $("", { id: "hiro_friends_invitations", title: HiroFriends.pendingInvitationsMsg(), style: "position: absolute; right: 0px; width: 19px; height: 25px; background-image: url('"+this.cdnBase+"/images/interface/more.jpg'); background-repeat: no-repeat;" }); this.spanInvitations.hover(function() { $(this).css("background-position", "0px -25px"); }, function() { $(this).css("background-position", ""); }); this.spanInvitations.click(function() { $(this).hide(); HiroFriends.spanCounter.css("right", "5px"); FriendslistWindow.open('openrequests'); return false; }); divCounter.append(this.spanInvitations); } divContainer.append(divRefresh.append(spanRefresh), spanSend.append(imageSend), divCounter.append(this.spanTimeLeft, this.spanCounter)).appendTo("#user-interface"); spanRefresh.hover(function() { $(this).css("background-position", ""); }, function() { $(this).css("background-position", "0px -20px"); }); spanRefresh.click(function() { HiroFriends.spanCounter.slideUp(500, function() { HiroFriends.fetch(); }).slideDown(1500); return false; }); imageSend.click(function() { HiroFriends.open(); return false; }); this.updateTimer(); if(typeof(Storage) !== "undefined") { var previousVersion = (localStorage.getItem(this.storageItem) === null) ? 0 : parseFloat(localStorage.getItem(this.storageItem)); localStorage.setItem(this.storageItem, this.version); // if(previousVersion && this.version > previousVersion) var msg=new west.gui.Dialog("TW Friends", "Script upgraded to version "+this.version, west.gui.Dialog.SYS_WARNING).addButton("OK").show(); } $("").appendTo("head"); return true; }, localeMsg: function(msg) { if(undefined !== this.messages[this.locale][msg]) return this.messages[this.locale][msg]; if(undefined !== this.messages['en_US'][msg]) return this.messages['en_US'][msg]; return ''; }, fetch: function() { if(this.interval !== false) clearInterval(this.interval); var event_times = {}; var friends = [], total = 0, avail = 0, recv = 0; var server_time = Game.getServerTime(), activation_time, friend_time; if(this.timeLeft < 0) { $("#hiro_friends_container").slideUp(5000); throw "Event is over"; } return $.post("/game.php?window=friendsbar&mode=search", { search_type: "friends" } , function(data) { $.each(data.eventActivations, function(key, val) { if(val.event_name == HiroFriends.eventName) 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; recv = (undefined === HiroFriends.log.friendLog[val.player_id]) ? 0 : HiroFriends.log.friendLog[val.player_id].total; friends.push({ id: val.player_id, name: val.name, activation_time: activation_time, recv: recv }); ++ total; if(activation_time + HiroFriends.eventInfo.cooldown - server_time <= 0) ++ avail; } }); HiroFriends.friends = friends; HiroFriends.avail = avail; HiroFriends.total = total; HiroFriends.interval = setInterval(function() { HiroFriends.fetch(); }, refreshMs); HiroFriends.update(); }); }, getPendingInvitations: function() { return $.post("/game.php?window=character&mode=get_open_requests", function(data) { var openReq = 0; $.each(data.open_friends, function(key, val) { if(val.inviter_id != Character.playerId) ++ openReq; }); HiroFriends.pendingInvitations = openReq; }); }, pendingInvitationsMsg: function() { return this.pendingInvitations == 1 ? this.localeMsg('pendingInvitation') : this.pendingInvitations+' '+this.localeMsg('pendingInvitations'); }, getLog: function() { var hasNext = true; var limit = 100; var page = 1; var count = 0; var details; var maxDate = HiroFriends.log.lastLog; while(hasNext) { $.ajax({ type: "POST", url: "/game.php?window=ses&mode=log", data: { ses_id: HiroFriends.eventName, page: page, limit: limit }, async: false, success: function(data) { hasNext = data.hasNext; limit = data.limit; page = data.page + 1; $.each(data.entries, function(key, val) { count = parseInt(val.value); if(val.date < HiroFriends.log.firstLog) HiroFriends.log.firstLog = val.date; if(val.date <= HiroFriends.log.lastLog) { hasNext = false; return false; } HiroFriends.log.entries.push(val); if(val.date > maxDate) maxDate = val.date; switch(val.type) { case "friendDrop": details = JSON.parse(val.details); if(undefined !== HiroFriends.friends[details.player_id]) HiroFriends.friends[details.player_id].recv += count; if(undefined === HiroFriends.log.friendLog[details.player_id]) HiroFriends.log.friendLog[details.player_id] = { name: details.name, total: count, dates: [] }; else HiroFriends.log.friendLog[details.player_id].total += count; HiroFriends.log.friendLog[details.player_id].dates.push(val.date); HiroFriends.log.count_friends += count; HiroFriends.log.received += count; break; case "jobDrop": HiroFriends.log.count_job += count; HiroFriends.log.received += count; break; case "buildDrop": HiroFriends.log.count_build += count; HiroFriends.log.received += count; break; case "duelDrop": HiroFriends.log.count_duel += count; HiroFriends.log.received += count; break; case "duelNPCDrop": HiroFriends.log.count_npc += count; HiroFriends.log.received += count; break; case "battleDrop": HiroFriends.log.count_fort += count; HiroFriends.log.received += count; break; case "adventureDrop": HiroFriends.log.count_mpi += count; HiroFriends.log.received += count; break; case "itemUse": HiroFriends.log.count_item += count; HiroFriends.log.received += count; break; case "wofPay": HiroFriends.log.used += count; if(val.details == "timerreset") { HiroFriends.log.count_reset += count; ++ HiroFriends.log.times_reset; } else if(val.details == "sneakyshot") { HiroFriends.log.count_bribe += count; ++ HiroFriends.log.times_bribe; } break; default: HiroFriends.log.count_other += count; HiroFriends.log.received += count; } }); } }); } this.log.lastLog = maxDate; Chat.Request.Nop(); }, display: function(sort) { var friend_time, server_time = Game.getServerTime(); var maindiv = $('
'); if(!this.friends.length) $('

'+this.localeMsg('noFriends')+'

').appendTo(maindiv); else { var hiroTable; switch(sort) { case "name" : this.friends.sort(this.nameCompare); break; case "name_desc": this.friends.sort(this.nameCompare).reverse(); break; case "recv" : this.friends.sort(this.recvCompare); break; case "recv_asc" : this.friends.sort(this.recvCompare).reverse(); break; case "time_asc" : this.friends.sort(this.timeCompare).reverse(); break; case "time" : default : sort = "time"; this.friends.sort(this.timeCompare); } var thName = $(' '+this.localeMsg('name')+'').click(function(){ HiroFriends.display(sort == 'name' ? 'name_desc' : 'name'); return false; }); var thAction = $(' '+this.eventInfo.label+'').click(function(){ HiroFriends.display(sort == 'time' ? 'time_asc' : 'time'); return false; }); var thRecv = $(' '+this.localeMsg('received')+'').click(function(){ HiroFriends.display(sort == 'recv' ? 'recv_asc' : 'recv'); return false; }); hiroTable = new west.gui.Table().appendTo(maindiv).addColumn("hf_idx").addColumn("hf_player").addColumn("hf_action").addColumn("hf_log").addColumn("hf_delete").appendToCell("head", "hf_idx", ' ').appendToCell("head", "hf_player", thName).appendToCell("head", "hf_action", thAction).appendToCell("head","hf_log",thRecv).appendToCell("head", "hf_delete", ' '); var idx = 1; $.each(this.friends, function(key, val) { var actionCell, recvCell; friend_time = val.activation_time + HiroFriends.eventInfo.cooldown - server_time; if(friend_time > HiroFriends.timeLeft) actionCell = '('+HiroFriends.localeMsg('nextYear')+')'; else if(friend_time > 0) actionCell = '('+friend_time.formatDurationBuffWay()+')'; else { actionCell = $(''+HiroFriends.eventInfo.label+'').click({ id: val.id, ev: HiroFriends.eventName }, function(e) { $(this).parent().parent().remove(); Ajax.remoteCall("friendsbar", "event", { player_id: val.id, event: HiroFriends.eventName }, function(response) { if(response.error) return MessageError(response.msg).show(); MessageSuccess(response.msg).show(); val.activation_time = Date.now()/1e3; if(HiroFriends.avail) -- HiroFriends.avail; HiroFriends.update(); if(WestUi.FriendsBar.friendsBarUi !== null) WestUi.FriendsBar.friendsBarUi.friendsBar.eventActivations[val.id][HiroFriends.eventName] = response.activationTime; }); return false; }); } if(val.recv) { var recv_list = '
    '; HiroFriends.log.friendLog[val.id].dates.sort(function(a, b){ return new Date(a)-new Date(b); }); $.each(HiroFriends.log.friendLog[val.id].dates, function(dkey, dval) { recv_list += '
  1. ' + new Date(dval * 1e3).toDateTimeStringNice() + '
  2. '; }); recv_list += '
      '; recvCell = ''+val.recv+''; } else recvCell = val.recv; hiroTable.appendRow(null, 'hiroFriendRow_'+val.id) .appendToCell(-1, "hf_idx", idx) .appendToCell(-1, "hf_player", '' + val.name + '') .appendToCell(-1, "hf_action", actionCell) .appendToCell(-1, "hf_log", recvCell) .appendToCell(-1, "hf_delete", 'delete'); ++ idx; }); hiroTable.appendToCell('foot', 'hf_idx', ''); hiroTable.appendToCell('foot', 'hf_player', 'TW Friends '+this.localeMsg('version')+' ' + this.version.toFixed(2)); if('http://gr1.the-west.gr' == Game.gameURL || 'http://gr4.the-west.gr' == Game.gameURL || 'http://gr5.the-west.gr' == Game.gameURL) hiroTable.appendToCell('foot', 'hf_action', 'by '+scriptAuthor+''); else if('https://zz1.beta.the-west.net' == Game.gameURL) hiroTable.appendToCell('foot', 'hf_action', 'by '+scriptAuthor+''); if (this.pendingInvitations) hiroTable.appendToCell('foot', 'hf_delete', 'add'); hiroTable.appendToCell('foot', 'hf_log', $(''+HiroFriends.localeMsg('exporter')+'').click(function() { HiroFriends.log.entries.sort(function(a,b) { return a.date - b.date; }); new west.gui.Dialog(HiroFriends.localeMsg('exporter'),''+HiroFriends.localeMsg('friends')+':

      '+HiroFriends.localeMsg('everything')+':
      ').setModal(true,true,{bg:HiroFriends.cdnBase+'/images/curtain_bg.png',opacity:0.7}).addButton("ok").show(); return false; }) ); } var statsTable = $(''+(this.log.used?'' : '') + '
      '+this.localeMsg('stats')+' ('+this.localeMsg('since')+' '+new Date(this.log.firstLog*1e3).toDateTimeString()+')
      '+this.localeMsg('collected')+':'+this.log.received+' '+this.localeMsg('friends')+': '+this.log.count_friends+', '+this.localeMsg('jobs')+': '+this.log.count_job+', '+this.localeMsg('fortBattles')+': '+this.log.count_fort+', '+this.localeMsg('adventures')+': '+this.log.count_mpi+', '+this.localeMsg('duels')+': '+this.log.count_duel+', '+this.localeMsg('npcDuels')+': '+this.log.count_npc+', '+this.localeMsg('construction')+': '+this.log.count_build+', '+this.localeMsg('itemUse')+': '+this.log.count_item+', '+this.localeMsg('other')+': '+this.log.count_other+'
      '+this.localeMsg('used')+':'+this.log.used+''+this.localeMsg('timerReset')+': '+this.log.count_reset+' (#'+this.log.times_reset+'), '+this.localeMsg('bribe')+': '+this.log.count_bribe+' (#'+this.log.times_bribe+')
      ').appendTo(maindiv); var hiroPane = new west.gui.Scrollpane(); hiroPane.appendContent(maindiv); var hiroWindow = wman.open("HiroFriends_"+this.eventName, null, "noreload").setMiniTitle(this.eventInfo.label).setTitle(this.eventInfo.label).appendToContentPane(hiroPane.getMainDiv()); }, open: function() { if(!WestUi.FriendsBar.hidden) WestUi.FriendsBar.toggle(); this.getLog(); return this.fetch().done(function() { HiroFriends.getPendingInvitations().done(function() { HiroFriends.display('time'); }) }); }, nameCompare: function(a, b) { return a.name.toLowerCase().localeCompare(b.name.toLowerCase()); }, recvCompare: function(a, b) { return b.recv - a.recv; }, timeCompare: function(a, b) { return a.activation_time - b.activation_time; }, updateTimer: function() { this.timeLeft = this.eventEndStamp - Game.getServerTime(); if(this.timeLeft <= 0) { this.spanTimeLeft.html(this.localeMsg('theEnd')); this.fetch(); return; } this.spanTimeLeft.html(this.timeLeft.formatDurationBuffWay()); var seconds = 0; if(this.timeLeft < 70) seconds = 1; else if(this.timeLeft < 3660) seconds = 10; else if(this.timeLeft < 86520) seconds = 60; else seconds = 120; setTimeout(function() { HiroFriends.updateTimer(); }, seconds * 1e3); }, update: function() { this.spanCounter.html(''+this.avail+' / '+this.total+''); }, removeFriend: function(charId) { new west.gui.Dialog(HiroFriends.localeMsg('removeFriend'), HiroFriends.localeMsg('removeConfirm')).setIcon(west.gui.Dialog.SYS_QUESTION).addButton("yes", function() { Ajax.remoteCall('character', 'cancel_friendship', { friend_id: charId }, function(json) { if(json["result"]) { new UserMessage(HiroFriends.localeMsg('removeSuccess'), UserMessage.TYPE_SUCCESS).show(); $("div.hiroFriendRow_" + charId).remove(); $("div.friendData_" + charId, FriendslistWindow.DOM).remove(); if(HiroFriends.avail) -- HiroFriends.avail; if(HiroFriends.total) -- HiroFriends.total; HiroFriends.update(); Chat.Friendslist.removeFriend(charId); } else new UserMessage(HiroFriends.localeMsg('removeFailed'), UserMessage.TYPE_ERROR).show(); }) }).addButton("no").show(); }, scriptInit: function(tries, maxTries) { var ev, eventName; if(tries >= maxTries) return false; if(Game && Game.loaded && Character.playerId) { this.locale = (undefined === Game.locale || undefined == this.messages[Game.locale]) ? "en_US" : Game.locale; this.api.setGui(this.localeMsg('description')); this.getPendingInvitations(); try { $.getScript(versionURL).done(function() { if (HiroFriends.latestVersion && HiroFriends.latestVersion > VERSION) { var upgradeDialog = new west.gui.Dialog(scriptName, HiroFriends.localeMsg('upgrade'), west.gui.Dialog.SYS_WARNING).addButton('ok', function () { try { upgradeDialog.hide(); location.href = codeURL; } catch (e) {} }).addButton('cancel').show(); } }); } catch (e) { } for(eventName in Game.sesData) { if(!Game.sesData.hasOwnProperty(eventName)) continue; var ev = Game.sesData[eventName]; if(!ev.friendsbar) continue; if('Hearts' == eventName || 'Easter' == eventName || 'Independence' == eventName || 'DayOfDead' == eventName) { if(this.eventManager(eventName)) this.fetch(); return false; } } return true; } ++ tries; setTimeout(function() { HiroFriends.scriptInit(tries, maxTries); }, tries * 1e3); }, } HiroFriends.scriptInit(0, 100); });