C&C Tiberium Alliances Chat Syncer and CP alerts

Syncs tiberium alliances (for now) chat with gtalk (for now) or email, and notifies when CP is close to the capacity. Change the CP_ALERT_HOURS value to tweak CP alert threshold (CP _ALERT_HOURS = how many hours before max capacity alert should be sent)

目前为 2015-11-20 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name C&C Tiberium Alliances Chat Syncer and CP alerts
  3. // @namespace http://careers.stackoverflow.com/boris-churzin
  4. // @version 2.0
  5. // @description Syncs tiberium alliances (for now) chat with gtalk (for now) or email, and notifies when CP is close to the capacity. Change the CP_ALERT_HOURS value to tweak CP alert threshold (CP _ALERT_HOURS = how many hours before max capacity alert should be sent)
  6. // @include https://www.tiberiumalliances.com/*
  7. // @include https://*.alliances.commandandconquer.com/*
  8. // @grant unsafeWindow
  9. // @grant GM_xmlhttpRequest
  10. // @copyright 2013+, Boris Churzin
  11. // ==/UserScript==
  12.  
  13. GROUP_TOKEN = 'beehive';
  14. CP_ALERT_HOURS = 1;
  15.  
  16. messages_done = {};
  17. setInterval(check_messages, 1000);
  18.  
  19. cp_done = false;
  20. setInterval(check_cp, 1000);
  21.  
  22. function send_message(player, message) {
  23. GM_xmlhttpRequest({
  24. method: "GET",
  25. url: "http://chat-syncer.herokuapp.com/message/" + GROUP_TOKEN + "/" + escape(player) + "/" + escape(message)
  26. });
  27. }
  28.  
  29. function check_cp() {
  30. try {
  31. var player = unsafeWindow.ClientLib.Data.MainData.GetInstance().get_Player();
  32. if(!cp_done && (player.GetCommandPointCount() > player.GetCommandPointMaxStorage() - player.GetCommandPointsGrowPerHour() * CP_ALERT_HOURS)) {
  33. console.log("Chat Syncer: CP alert triggered");
  34. cp_done = true;
  35. send_message(player.get_Name(), player.get_Name() + ": CP alert: " + Math.round(player.GetCommandPointCount()) + " out of " + player.GetCommandPointMaxStorage());
  36. } else {
  37. if(cp_done && !(player.GetCommandPointCount() > player.GetCommandPointMaxStorage() - player.GetCommandPointsGrowPerHour() * CP_ALERT_HOURS)) {
  38. cp_done = false;
  39. console.log("Chat Syncer: CP alert reset");
  40. }
  41. }
  42. } catch(e) {
  43. console.log("Chat Syncer (check_cp): " + e);
  44. }
  45. }
  46.  
  47. function check_messages() {
  48. try {
  49. var messages = [];
  50. var spans = document.getElementsByTagName('span');
  51. for (var i = 0; i < spans.length; ++i) {
  52. if (spans[i].id.match("CHAT_SENDER")) {
  53. messages.push(spans[i].parentNode);
  54. }
  55. }
  56. for(var i = 0; i < messages.length; i++) {
  57. if(messages[i].innerHTML.match("\\[Alliance\\]") || messages[i].innerHTML.match("\\[Officers\\]")) {
  58. if(!messages_done[messages[i].innerHTML]) {
  59. messages_done[messages[i].innerHTML] = true;
  60. send_message(messages[i].children[0].innerHTML, messages[i].children[1].innerHTML);
  61. }
  62. }
  63. }
  64. } catch(e) {
  65. console.log("Chat Syncer (check_messages): " + e);
  66. }
  67. }