// ==UserScript==
// @name TW Friends Check
// @name:ru TW Friends Check
// @namespace TW Friends Check
// @description Shows list of Friends gifts (log) from current Event. TW Friends script req.
// @description:ru Журнал подарков от друзей
// @include http://*.the-west.*/game.php*
// @include https://*.the-west.*/game.php*
// @version 0.02 alfa
// @grant none
// @downloadURL none
// ==/UserScript==
// TW Friends script needed!!! https://greasyfork.org/users/3197
// Based on ideas of TW Friends script
//
// $.post("/game.php?window=ses&mode=log", {ses_id:"Easter", limit:100, page:2} )
function FCScript(fn) {
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = '(' + fn + ')();';
document.body.appendChild(script); // left for other use
document.body.removeChild(script);
}
FCScript(function() {
var VERSION = "0.02 alfa";
var NAME = "TW Friends Check";
var installURL = '';
if (!isDefined(window.HiroFriends))
{
new west.gui.Dialog('TW Friends Check',
'
TW Friends script neededLink ',
west.gui.Dialog.SYS_WARNING).addButton("OK").show();
return;
}
fcContainer = $("",
{
id: "twfc_container",
style: "position: absolute; top: 32px; right: 50%; margin-right: 20px; padding-right:25px; z-index: 15; width: 100px; height: 36px; text-align: right; background: url('/images/interface/custom_unit_counter_sprite.png') no-repeat scroll right 0px transparent;"
}
);
fcContainer.appendTo("#user-interface");
//aLink = $("Test",
fcLink = $("",
{
id: "twfc_a",
style: "color:red; font-size:18px;",
onclick: "return TWFCheck.get();",
html: "LOAD",
}
);
fcContainer.append('');
fcLink.appendTo("#twfc_wrap");
TWFCheck = {
max_page: 10,
is_init: false,
is_calc: false,
ses_id: '',
friends: [],
mes_loaded: 0,
mes_friends: [],
};
TWFCheck.init = function()
{
if (TWFCheck.is_init) return;
TWFCheck.ses_id = HiroFriends.eventName;
TWFCheck.friends = HiroFriends.friends;
console.log('inited');
TWFCheck.is_init = true;
}
TWFCheck.get = function()
{
TWFCheck.init();
if (!TWFCheck.mes_loaded) TWFCheck.loadMsgList();
else TWFCheck.show();
fcLink.html("SHOW");
return false;
}
TWFCheck.loadMsgList = function(page)
{
if (!page) page = 1;
if (page > TWFCheck.max_page) return;
TWFCheck.init();
$.post("/game.php?window=ses&mode=log", {ses_id:TWFCheck.ses_id, limit:100, page:page},
function(data)
{
//console.log(data);
TWFCheck.mes_loaded += data.entries.length;
$.each(data.entries, function (key, val)
{
if (val.type == 'friendDrop')
{
var d = val.details;
d = JSON.parse(d);
var fid = d.player_id;
var p = TWFCheck.mes_friends[fid];
if (p) {p.count++;}
else
{
p = {count:1, date:val.date, name:d.name};
}
TWFCheck.mes_friends[fid] = p;
}
});
if (data.hasNext) TWFCheck.loadMsgList(data.page+1);
} // f.data
);
return;
}
TWFCheck.show = function()
{
if (!TWFCheck.is_calc) TWFCheck.calc();
var key;
var td1;
var td2;
var dstr = '';
var idx = 1;
var tbl = $('');
var mes = TWFCheck.mes_friends;
for(key in mes)
{
if (!mes.hasOwnProperty(key)) continue;
var val = TWFCheck.mes_friends[key];
//console.log(idx+"/"+key+"/"+val);
td1 = $(''+val.count+' | ');
dstr = '';
if (val.count) dstr = val.date.getFormattedTimeString4Timestamp();
td2 = $(''+dstr+' | ');
tbl.append($(')').append($('' + idx + '. | ' + val.name + ' | '), td1, td2));
++ idx;
}
tbl.append($('
)').append($(''+NAME+' version ' + VERSION + ' | ')));
var hiroWindow = wman.open("TWFC_"+TWFCheck.ses_id, null, "noreload").setMiniTitle(TWFCheck.ses_id).setTitle(TWFCheck.ses_id);
var hiroPane = new west.gui.Scrollpane;
hiroPane.appendContent(tbl);
hiroWindow.appendToContentPane(hiroPane.getMainDiv())
}
TWFCheck.calc = function()
{
$.each(TWFCheck.friends, function(key,val)
{
var fid = val.id;
var p = TWFCheck.mes_friends[fid];
if (!p) { p = {count:0, name:val.name, date:0}; }
else
{
/*recalc date*/
}
TWFCheck.mes_friends[fid] = p;
});
TWFCheck.is_calc = true;
}
}
);