Greasy Fork is available in English.

QT Framework for Grepolis

A script framework for Grepolis

2014-07-29 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name QT Framework for Grepolis
  3. // @namespace Quack
  4. // @description A script framework for Grepolis
  5. // @include http://*.grepolis.*/game*
  6. // @icon http://s1.directupload.net/images/140711/eshmcqzu.png
  7. // @version 1.02.00
  8. // @grant GM_listValues
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @grant GM_deleteValue
  12. // @grant GM_info
  13. // @grant GM_xmlhttpRequest
  14. // ==/UserScript==
  15.  
  16. /************************************************************************
  17. * Main Script
  18. ***********************************************************************/
  19. function main_script(DATA) {
  20. /************************************************************************
  21. * Global variables
  22. ***********************************************************************/
  23. var QT = {};
  24. var wID = Game.world_id;
  25. var mID = Game.market_id;
  26. var aID = Game.alliance_id;
  27. var sID = Game.player_id;
  28. var pName = Game.player_name;
  29.  
  30. /************************************************************************
  31. * Languages
  32. ***********************************************************************/
  33. QT.Lang = {
  34. get : function (a, b) {
  35. if (QT.Lang[mID] != undefined && QT.Lang[mID][a] != undefined && QT.Lang[mID][a][b] != undefined) {
  36. return QT.Lang[mID][a][b]
  37. } else {
  38. return QT.Lang.en[a][b]
  39. }
  40. },
  41. de : {
  42. meta : {
  43. flag : 'http://s14.directupload.net/images/140408/xpd69nmj.png',
  44. changelog : 'http://adf.ly/cph8j',
  45. changelog_addfree : 'https://docs.google.com/document/d/10AyoYbgB1ml30EhSyXF7lDgEw_VqgHIQoJrJPCT0Z3w/edit?usp=sharing',
  46. forumlink : 'http://adf.ly/cbQaZ',
  47. forumlink_addfree : 'http://forum.de.grepolis.com/showthread.php?20742',
  48. donation_btn : '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2HJ88ATTBYXSQ&lc=DE&item_name=Quack%20Toolsammlung&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted" target="_blank"><img src="https://www.paypal.com/de_DE/i/btn/btn_donate_LG.gif" alt="Spenden"></a>'
  49. },
  50. test : {
  51. teststring : 'Sprache wurde erkannt'
  52. }
  53. },
  54. en : {
  55. meta : {
  56. flag : 'http://s14.directupload.net/images/140408/e2nfyth9.png',
  57. changelog : 'http://adf.ly/cpi89',
  58. changelog_addfree : 'https://docs.google.com/document/d/1Q9wIHhXUu6cDUdxr0onT8sHOcSXxpAtbg6R_oOrhiA8/edit?usp=sharing',
  59. forumlink : 'http://adf.ly/fJDMD',
  60. forumlink_addfree : 'http://forum.en.grepolis.com/showthread.php?51999',
  61. donation_btn : '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=2HJ88ATTBYXSQ&lc=US&item_name=Quack%20Toolsammlung&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted" target="_blank"><img src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" alt="Donate"></a>'
  62. },
  63. test : {
  64. teststring : 'Language detected'
  65. }
  66. }
  67. };
  68.  
  69. /************************************************************************
  70. * Images
  71. ***********************************************************************/
  72. QT.Images = {};
  73.  
  74. /************************************************************************
  75. * Links
  76. ***********************************************************************/
  77. QT.Links = {};
  78.  
  79. /************************************************************************
  80. * Settings
  81. ***********************************************************************/
  82. QT.Settings = {
  83. values : {
  84. "messageOpenAlert" : true,
  85. "reportOpenAlert" : true,
  86. "onlinetotal" : 0
  87. },
  88. save : function (name, value) {
  89. QT_saveValue(name, value);
  90. },
  91. save_all : function (valuesToSave) {
  92. QT_saveAllValues(QT.Settings.values, valuesToSave);
  93. },
  94. delete : function (name) {
  95. QT_deleteValue(name);
  96. },
  97. delete_all : function () {
  98. QT_deleteAllValues();
  99. },
  100. setValues : function () {
  101. for (var opt in DATA) {
  102. QT.Settings.values[opt] = DATA[opt];
  103. }
  104. }
  105. };
  106.  
  107. /************************************************************************
  108. * Ajax Call functions
  109. ***********************************************************************/
  110. QT.CallAjaxFunction = {
  111. message : {
  112. default:
  113. function (event, xhr, settings) {
  114. if (QT.Settings.values.messageOpenAlert)
  115. QT.Functions.messageOpenAlert();
  116. }
  117. },
  118. report : {
  119. index : function () {
  120. if (QT.Settings.values.reportOpenAlert)
  121. QT.Functions.reportOpenAlert();
  122. }
  123. }
  124. };
  125.  
  126. /************************************************************************
  127. * Functions
  128. ***********************************************************************/
  129. QT.Functions = {
  130. messageOpenAlert : function () {
  131. alert("Die Nachrichten wurden geöffnet");
  132. },
  133. reportOpenAlert : function () {
  134. alert("Die Berichte wurden geöffnet");
  135. },
  136. testButtons : function () {
  137. $('#ui_box').append('<div id="qt_buttons" style="position: relative;top: 54px;z-index: 100"><button id="qt_save">Save</button><button id="qt_saveall">Save all</button><button id="qt_delete">Delete</button><button id="qt_deleteall">Delete all</button></div>');
  138. $("#qt_save").click(function () {
  139. QT.Settings.save("messageOpenAlert", false);
  140. });
  141. $("#qt_saveall").click(function () {
  142. var values = {};
  143. values.messageOpenAlert = false;
  144. values.reportOpenAlert = false;
  145. QT.Settings.save_all(values);
  146. });
  147. $("#qt_delete").click(function () {
  148. QT.Settings.delete("messageOpenAlert");
  149. });
  150. $("#qt_deleteall").click(function () {
  151. QT.Settings.delete_all();
  152. });
  153. }
  154. };
  155.  
  156. /************************************************************************
  157. * Observer
  158. ***********************************************************************/
  159. $.Observer(GameEvents.game.load).subscribe('QT', function (e, data) {
  160. QT.Settings.setValues();
  161. QT.Functions.testButtons();
  162.  
  163. $(document).ajaxComplete(function (event, xhr, settings) {
  164. var a = settings.url.split("?");
  165. var b = a[0].substr(6);
  166. var c = a[1].split("&")[1].substr(7);
  167. if (b in QT.CallAjaxFunction && c in QT.CallAjaxFunction[b]) {
  168. QT.CallAjaxFunction[b][c](event, xhr, settings);
  169. }
  170. });
  171. });
  172. }
  173.  
  174. /************************************************************************
  175. * Start Method
  176. ***********************************************************************/
  177. var DATA = {
  178. script_version : GM_info.script.version
  179. };
  180.  
  181. var keys = GM_listValues();
  182. for (var i = 0, key = null; key = keys[i]; i++) {
  183. DATA[key] = GM_getValue(key);
  184. }
  185.  
  186. unsafeWindow.QT_saveValue = function (name, val) {
  187. setTimeout(function () {
  188. GM_setValue(name, val);
  189. window.location.reload();
  190. }, 0);
  191. };
  192. unsafeWindow.QT_saveAllValues = function (QTsettings, values) {
  193. setTimeout(function () {
  194. var exceptions = ["qmenu_update_next", "qmenu_online_version", "onlinetotal"];
  195. for (key in QTsettings) {
  196. if (exceptions.indexOf(key) === -1) {
  197. if (key in values) {
  198. GM_setValue(key, values[key]);
  199. } else {
  200. GM_deleteValue(key);
  201. }
  202. }
  203. }
  204. window.location.reload();
  205. }, 0);
  206. };
  207. unsafeWindow.QT_deleteValue = function (name) {
  208. setTimeout(function () {
  209. GM_deleteValue(name);
  210. window.location.reload();
  211. }, 0);
  212. };
  213. unsafeWindow.QT_deleteAllValues = function () {
  214. setTimeout(function () {
  215. var keys = GM_listValues();
  216. for (var i = 0, key = null; key = keys[i]; i++) {
  217. GM_deleteValue(key);
  218. }
  219. window.location.reload();
  220. }, 0);
  221. };
  222.  
  223. if (typeof exportFunction == 'function') {
  224. exportFunction(unsafeWindow.QT_saveValue, unsafeWindow, {
  225. defineAs : "QT_saveValue"
  226. });
  227. exportFunction(unsafeWindow.QT_saveAllValues, unsafeWindow, {
  228. defineAs : "QT_saveAllValues"
  229. });
  230. exportFunction(unsafeWindow.QT_deleteValue, unsafeWindow, {
  231. defineAs : "QT_deleteValue"
  232. });
  233. exportFunction(unsafeWindow.QT_deleteAllValues, unsafeWindow, {
  234. defineAs : "QT_deleteAllValues"
  235. });
  236. }
  237.  
  238. function appendScript() {
  239. if (unsafeWindow.Game) {
  240. var QT_script = document.createElement('script');
  241. QT_script.type = 'text/javascript';
  242. QT_script.textContent = main_script.toString() + "\n main_script(" + JSON.stringify(DATA) + ");";
  243. document.body.appendChild(QT_script);
  244. } else {
  245. setTimeout(function () {
  246. appendScript();
  247. }, 100);
  248. }
  249. }
  250.  
  251. appendScript();