TW Friends Check

Shows list of Friends gifts (log) from current Event. TW Friends script req.

  1. // ==UserScript==
  2. // @name TW Friends Check
  3. // @name:ru TW Friends Check
  4. // @namespace TW Friends Check
  5. // @description Shows list of Friends gifts (log) from current Event. TW Friends script req.
  6. // @description:ru Журнал подарков от друзей
  7. // @include http*://*.the-west.*/game.php*
  8. // @include http*://*.tw.innogames.*/game.php*
  9. // @version 0.06
  10. // @grant none
  11. // @license none
  12. // ==/UserScript==
  13. // TW Friends script needed!!! https://gf.qytechs.cn/users/3197
  14. // Based on ideas of TW Friends script
  15. //
  16. // $.post("/game.php?window=ses&mode=log", {ses_id:"Easter", limit:100, page:2} )
  17.  
  18.  
  19. function FCScript(fn) {
  20. var script = document.createElement('script');
  21. script.setAttribute("type", "application/javascript");
  22. script.textContent = '(' + fn + ')();';
  23. document.body.appendChild(script); // left for other use
  24. //document.body.removeChild(script);
  25. }
  26.  
  27. FCScript(function() {
  28. var VERSION = "0.06";
  29. var NAME = "TW Friends Check";
  30. var installURL = 'https://gf.qytechs.cn/ru/scripts/9134-tw-friends-check';
  31. console.log(NAME+' starting...');
  32. if (!isDefined(window.HiroFriends))
  33. {
  34. new west.gui.Dialog(
  35. 'TW Friends Check',
  36. '<div class="txcenter"><b>TW Friends script needed</b><br /><a href="https://gf.qytechs.cn/users/3197" target=_blank>Link</a></div>',
  37. west.gui.Dialog.SYS_WARNING).addButton("OK").show();
  38. return;
  39. }
  40. console.log('HiroFriends finded');
  41. /*
  42. if(Game && Game.loaded)
  43. {
  44. // if (!Game.sesData) return; // if have Event - then it is Obj
  45. // if (!Game.sesData.length) return; // if no Event... it is Array!!!
  46. if (!HiroFriends.eventName) return;
  47. }
  48. */
  49. //console.log('Event: ' +HiroFriends.eventName);
  50. TWFCheck = {
  51. max_page: 100,
  52. is_inited: false,
  53. is_ready: false,
  54. is_calc: false,
  55. ses_id: '',
  56. friends: [],
  57. mes_loaded: 0,
  58. mes_friends: [],
  59. mes_load_done: false,
  60. window: null,
  61. winName: 'TWFC_window',
  62. fcLink: false,
  63. };
  64. TWFCheck.init = function()
  65. {
  66. if (!(Game && Game.loaded && Character.playerId)) return;
  67. if (TWFCheck.is_inited) return;
  68. var fcContainer = $(
  69. "<div />",
  70. {
  71. id: "twfc_container",
  72. 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;"
  73. }
  74. );
  75. fcContainer.appendTo("#user-interface");
  76. //aLink = $("<a href='#' onclick='return TWFCheck.get();'>Test</a>",
  77. TWFCheck.fcLink = $(
  78. "<a />",
  79. {
  80. id: "twfc_a",
  81. style: "color:red; font-size:18px;",
  82. onclick: "return TWFCheck.get();",
  83. html: "LOAD",
  84. }
  85. );
  86. fcContainer.append('<div style="margin-top:5px;" id="twfc_wrap"></div>');
  87. TWFCheck.fcLink.appendTo("#twfc_wrap");
  88. TWFCheck.is_inited = true;
  89. console.log("TWFC ready!");
  90. }
  91. TWFCheck.startScript = function(tryCount)
  92. {
  93. console.log("TWFC start:" + tryCount);
  94. TWFCheck.init();
  95. if (TWFCheck.is_inited) return true;
  96. if (tryCount > 10) return false;
  97. tryCount++;
  98. console.log("TWFC not ready");
  99. setTimeout(function() { TWFCheck.startScript(tryCount); }, 2000);
  100. }
  101. TWFCheck.prepare = function()
  102. {
  103. if (TWFCheck.is_ready) return;
  104. TWFCheck.ses_id = HiroFriends.eventName;
  105. TWFCheck.friends = HiroFriends.friends;
  106. console.log('TWFC:prepared');
  107. TWFCheck.is_ready = true;
  108. }
  109. TWFCheck.get = function()
  110. {
  111. TWFCheck.prepare();
  112. if (!TWFCheck.mes_loaded) TWFCheck.loadMsgList();
  113. else TWFCheck.show();
  114. return false;
  115. }
  116. TWFCheck.loadMsgList = function(page)
  117. {
  118. if (!page) page = 1;
  119. TWFCheck.prepare();
  120. TWFCheck.fcLink.html("...");
  121. var hasNext = true;
  122. while (hasNext) {
  123. $.ajax({ type: "POST", url: "/game.php?window=ses&mode=log", data: {ses_id:TWFCheck.ses_id, limit:100, page:page}, async: false,
  124. success: function(data)
  125. {
  126. console.log(data);
  127. hasNext = data.hasNext;
  128. TWFCheck.mes_loaded += data.entries.length;
  129.  
  130. $.each(data.entries,
  131. function (key, val)
  132. {
  133. if (val.type == 'friendDrop')
  134. {
  135. var d = val.details;
  136. d = JSON.parse(d);
  137. var fid = d.player_id;
  138.  
  139. var p = TWFCheck.mes_friends[fid];
  140. if (p) {p.count++;}
  141. else
  142. {
  143. p = {count:1, date:val.date, name:d.name, deleted:true, id:fid};
  144. }
  145. TWFCheck.mes_friends[fid] = p;
  146. }
  147. }); //each
  148. } //f.data
  149. }); //ajax
  150. //OFF if (page > TWFCheck.max_page) break;
  151. page++;
  152. } //while
  153. TWFCheck.mes_load_done = true;
  154. TWFCheck.fcLink.html("VIEW");
  155. }
  156. TWFCheck.show = function()
  157. {
  158. if (!TWFCheck.mes_load_done) return;
  159. if (!TWFCheck.is_calc) TWFCheck.calc();
  160. var key; //player id -> friend_id
  161. var td1;
  162. var td2;
  163. var td3;
  164. var cols = 5;
  165. var dstr = '';
  166. var idx = 1;
  167. var tbl = $('<table style="width: 100%" border="0" cellpadding="0" cellspacing="0">');
  168. var deletedAr = [];
  169. var mes = TWFCheck.mes_friends;
  170. for(key in mes)
  171. {
  172. if (!mes.hasOwnProperty(key)) continue;
  173. var val = TWFCheck.mes_friends[key];
  174. if (val.deleted)
  175. {
  176. deletedAr.push(val);
  177. continue;
  178. }
  179. //console.log(idx+"/"+key+"/"+val);
  180. td1 = $('<td style="vertical-align: middle;">'+val.count+'</td>');
  181. dstr = '';
  182. if (val.count) dstr = val.date.getFormattedTimeString4Timestamp();
  183. td2 = $('<td style="vertical-align: middle;">'+dstr+'</td>');
  184. td3 = $('<td style="vertical-align: middle;"><a href="javascript:void(TWFCheck.removeFriend('+key+'));"><img style="width:16px; height: 16px;" alt="'+HiroFriends.localeMsg('removeFriend')+'" title="'+HiroFriends.localeMsg('removeFriend')+'" src="/images/icons/delete.png" /></a></td>');
  185. tbl.append(
  186. $('<tr style="background-image: url(\'/images/tw2gui/table/table_row.png\'); height: 29px;">)').append(
  187. $('<td style="width: 10%; vertical-align: middle; text-align: right; padding-right: 8px">' + idx
  188. + '.</td><td style="width: 35%; vertical-align: middle;"><a href="javascript:void(PlayerProfileWindow.open('+key+'));">' + val.name + '</a></td>'
  189. ), td1, td2, td3));
  190. idx++;
  191. }
  192. // deleted friends
  193. if (deletedAr.length)
  194. {
  195. td1 = $('<td style="vertical-align: middle; padding-left:8px;" colspan="'+cols+'"><b>Removed Friends</b></td>');
  196. tbl.append($('<tr style="background-image: url(\'/images/tw2gui/table/table_row_you.png\'); height: 29px;">)').append(td1));
  197. idx = 1;
  198. $.each(deletedAr, function(key,val)
  199. {
  200. td1 = $('<td style="vertical-align: middle;">'+val.count+'</td>');
  201. dstr = '';
  202. if (val.count) dstr = val.date.getFormattedTimeString4Timestamp();
  203. td2 = $('<td style="vertical-align: middle;" colspan="'+(cols-3)+'">'+dstr+'</td>');
  204. tbl.append(
  205. $('<tr style="background-image: url(\'/images/tw2gui/table/table_row.png\'); height: 29px;">)').append(
  206. $('<td style="width: 10%; vertical-align: middle; text-align: right; padding-right: 8px">' + idx
  207. + '.</td><td style="width: 35%; vertical-align: middle;"><a href="javascript:void(PlayerProfileWindow.open('+val.id+'));">' + val.name + '</a></td>'
  208. ), td1, td2));
  209. idx++;
  210. });
  211. }
  212. 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="'+cols+'"><a target="_blank" href="'+installURL+'">'+NAME+'</a> version <b>' + VERSION + '</b></td>')));
  213. var hiroWindow = wman.open(TWFCheck.winName, null, "noreload").setMiniTitle(TWFCheck.ses_id).setTitle(TWFCheck.ses_id);
  214. var hiroPane = new west.gui.Scrollpane;
  215. hiroPane.appendContent(tbl);
  216. hiroWindow.appendToContentPane(hiroPane.getMainDiv())
  217. TWFCheck.window = hiroWindow;
  218. }
  219. TWFCheck.calc = function()
  220. {
  221. //adding friends withot gifts + checking for deleted friends
  222. $.each(TWFCheck.friends, function(key,val)
  223. {
  224. var fid = val.id;
  225. if (!fid) fid = key;
  226. var p = TWFCheck.mes_friends[fid];
  227. if (!p) { p = {count:0, name:val.name, date:0, deleted:false, id:fid}; } // no gifts from friend
  228. else
  229. {
  230. p.deleted = false;
  231. }
  232. TWFCheck.mes_friends[fid] = p;
  233. });
  234. TWFCheck.is_calc = true;
  235. }
  236. TWFCheck.removeFriend = function(fid)
  237. {
  238. FriendslistWindow.deleteFromFriendList(fid);
  239. TWFCheck.mes_friends[fid].deleted = true;
  240. wman.close(TWFCheck.winName);
  241. TWFCheck.show();
  242. }
  243. TWFCheck.startScript(0);
  244. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址