Greasy Fork is available in English.
Shows list of Friends gifts (log) from current Event. TW Friends script req.
当前为
// ==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
// ==/UserScript==
// TW Friends script needed!!! http://greasyfork.icu/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',
'<div class="txcenter"><b>TW Friends script needed</b><br /><a href="http://greasyfork.icu/users/3197" target=_blank>Link</a></div>',
west.gui.Dialog.SYS_WARNING).addButton("OK").show();
return;
}
fcContainer = $("<div />",
{
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 = $("<a href='#' onclick='return TWFCheck.get();'>Test</a>",
fcLink = $("<a />",
{
id: "twfc_a",
style: "color:red; font-size:18px;",
onclick: "return TWFCheck.get();",
html: "LOAD",
}
);
fcContainer.append('<div style="margin-top:5px;" id="twfc_wrap"></div>');
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 = $('<table style="width: 100%" border="0" cellpadding="0" cellspacing="0">');
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 = $('<td style="vertical-align: middle;">'+val.count+'</td>');
dstr = '';
if (val.count) dstr = val.date.getFormattedTimeString4Timestamp();
td2 = $('<td style="vertical-align: middle;">'+dstr+'</td>');
tbl.append($('<tr style="background-image: url(\'/images/tw2gui/table/table_row.png\'); height: 29px;">)').append($('<td style="width: 10%; vertical-align: middle; text-align: right; padding-right: 8px">' + idx + '.</td><td style="width: 35%; vertical-align: middle;"><a href="javascript:void(PlayerProfileWindow.open('+key+'));">' + val.name + '</a></td>'), td1, td2));
++ idx;
}
tbl.append($('<tr style="background-image: url(\'/images/tw2gui/table/table_row_you.png\'); height: 29px;">)').append($('<td style="vertical-align: middle; text-align: right; padding-right: 8px" colspan="4"><a target="_blank" href="'+installURL+'">'+NAME+'</a> version <b>' + VERSION + '</b></td>')));
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;
}
}
);