Slupik98

[PLEMIONA] ReportVaultManager

Mar 12th, 2017
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.75 KB | None | 0 0
  1. // ==UserScript==
  2. // @name ReportVaultManager
  3. // @description Dodaje raporty do skarbce w tle
  4. // @author Slupio98(only little) and others
  5. // @version 1.0.1
  6. // @updateURL http://pastebin.com/raw/iWC9HEK1
  7. // @downloadURL http://pastebin.com/raw/iWC9HEK1
  8. // @run-at document-end
  9. // @match https://*.plemiona.pl/game.php?village=*&screen=report&mode=all&group_id=*&view=*
  10. // @match http://*.plemiona.pl/game.php?village=*&screen=report&mode=all&group_id=*&view=*
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. unsafeWindow.MyTwstats = {
  15. "hash": "e3f3f1321b62b75e13ed",
  16. "address": "https://pl.mytwstats.com/reportsVault/",
  17. "alert_msg": ["Błąd połączenia z serwerem pl.mytwstats.com", "Ta strona nie zawiera raportu"],
  18. "loaded": false,
  19. "load": function () {
  20. this.timer = setTimeout(function () {
  21. alert(MyTwstats.alert_msg[0]);
  22. }, 5000);
  23. // var c = document.createElement("script");
  24. // c.src = this.address + "ext/server.js";
  25. // document.getElementsByTagName("head")[0].appendChild(c);
  26. },
  27. "init": function () {
  28. if (/view=\d+/i.test(location.href) && /screen=report/i.test(location.href)) {
  29. if (this.loaded) {
  30. this.sendReport(this.getReport());
  31. } else {
  32. this.load();
  33. }
  34. } else {
  35. alert(this.alert_msg[1]);
  36. }
  37. }
  38. };
  39. setTimeout(function(){
  40. MyTwstats.init();
  41. }, 100);
  42. })();
  43.  
  44. MyTwstats.vaultResponse = function (response) {
  45. console.log(response.message);
  46. };
  47.  
  48. MyTwstats.handleIframe = function (id, iframe, report) {
  49. var doc = iframe.contentWindow || iframe.contentDocument;
  50. if (doc.document) doc = doc.document;
  51.  
  52. var form = doc.getElementsByTagName('form')[0];
  53.  
  54. if (form) {
  55. inputA = form.getElementsByTagName('input');
  56. inputA[0].value = id;
  57. inputA[1].value = MyTwstats.hash;
  58. inputA[2].value = report;
  59.  
  60. var iframeLoad = function () {
  61. setTimeout(function () {
  62. iframe.parentNode.removeChild(iframe);
  63.  
  64. var c = document.createElement('script');
  65. c.src = MyTwstats.address + 'response.php?id=' + id + '&hash=' + MyTwstats.hash;
  66.  
  67. document.getElementsByTagName('head')[0].appendChild(c);
  68. }, 1);
  69. }
  70.  
  71. iframe.onload = function () {
  72. iframeLoad();
  73. };
  74.  
  75. iframe.onreadystatechange = function () {
  76. if (MyTwstats.readyState === 'complete') {
  77. iframeLoad();
  78. }
  79. };
  80.  
  81. form.submit();
  82. }
  83. }
  84.  
  85. MyTwstats.createIFrame = function () {
  86. var iframe = document.getElementById('MyTwstatsIframe');
  87. if (!iframe) {
  88. iframe = document.createElement('iframe');
  89. iframe.style.display = 'none';
  90. iframe.setAttribute('id', 'MyTwstatsIframe');
  91. document.body.appendChild(iframe);
  92. }
  93. return iframe;
  94. }
  95.  
  96. MyTwstats.createForm = function (iframe) {
  97. var doc = iframe.contentWindow || iframe.contentDocument;
  98. if (doc.document) doc = doc.document;
  99.  
  100. var form = doc.createElement('form');
  101. form.setAttribute('id', 'MyTwstatsIframe_form');
  102. form.method = 'post';
  103. form.action = MyTwstats.address + 'update_ext.php';
  104. form.setAttribute('enctype', 'multipart/form-data');
  105. doc.body.appendChild(form);
  106.  
  107. var input = doc.createElement('input');
  108. input.type = 'text';
  109. input.name = 'id';
  110. form.appendChild(input);
  111.  
  112. var input = doc.createElement('input');
  113. input.type = 'text';
  114. input.name = 'hash';
  115. form.appendChild(input);
  116.  
  117. var input = doc.createElement('input');
  118. input.type = 'text';
  119. input.name = 'val';
  120. form.appendChild(input);
  121. }
  122.  
  123. MyTwstats.getReport = function () {
  124. return document.getElementById('content_value').getElementsByTagName('tr')[0].childNodes[1].innerHTML;
  125. }
  126.  
  127. MyTwstats.sendReport = function (report) {
  128. if (report != false) {
  129. var iframe = MyTwstats.createIFrame();
  130. setTimeout(function () { MyTwstats.createForm(iframe) }, 1);
  131. var report = base64_encode(report);
  132. var id = Math.round(Math.random() * 1000000);
  133.  
  134. setTimeout(function () { MyTwstats.handleIframe(id, iframe, report) }, 5);
  135. }
  136. }
  137.  
  138. function utf8_encode(argString) {
  139. // http://kevin.vanzonneveld.net
  140. // + original by: Webtoolkit.info (http://www.webtoolkit.info/)
  141. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  142. // + improved by: sowberry
  143. // + tweaked by: Jack
  144. // + bugfixed by: Onno Marsman
  145. // + improved by: Yves Sucaet
  146. // + bugfixed by: Onno Marsman
  147. // + bugfixed by: Ulrich
  148. // * example 1: utf8_encode('Kevin van Zonneveld');
  149. // * returns 1: 'Kevin van Zonneveld'
  150.  
  151. var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
  152.  
  153. var utftext = "";
  154. var start, end;
  155. var stringl = 0;
  156.  
  157. start = end = 0;
  158. stringl = string.length;
  159. for (var n = 0; n < stringl; n++) {
  160. var c1 = string.charCodeAt(n);
  161. var enc = null;
  162.  
  163. if (c1 < 128) {
  164. end++;
  165. } else if (c1 > 127 && c1 < 2048) {
  166. enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
  167. } else {
  168. enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
  169. }
  170. if (enc !== null) {
  171. if (end > start) {
  172. utftext += string.substring(start, end);
  173. }
  174. utftext += enc;
  175. start = end = n + 1;
  176. }
  177. }
  178.  
  179. if (end > start) {
  180. utftext += string.substring(start, string.length);
  181. }
  182.  
  183. return utftext;
  184. }
  185.  
  186.  
  187. function base64_encode(data) {
  188. // http://kevin.vanzonneveld.net
  189. // + original by: Tyler Akins (http://rumkin.com)
  190. // + improved by: Bayron Guevara
  191. // + improved by: Thunder.m
  192. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  193. // + bugfixed by: Pellentesque Malesuada
  194. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  195. // - depends on: utf8_encode
  196. // * example 1: base64_encode('Kevin van Zonneveld');
  197. // * returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
  198. // mozilla has this native
  199. // - but breaks in 2.0.0.12!
  200. //if (typeof this.window['atob'] == 'function') {
  201. // return atob(data);
  202. //}
  203. var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  204. var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
  205. ac = 0,
  206. enc = "",
  207. tmp_arr = [];
  208.  
  209. if (!data) {
  210. return data;
  211. }
  212.  
  213. data = utf8_encode(data + '');
  214.  
  215. do { // pack three octets into four hexets
  216. o1 = data.charCodeAt(i++);
  217. o2 = data.charCodeAt(i++);
  218. o3 = data.charCodeAt(i++);
  219.  
  220. bits = o1 << 16 | o2 << 8 | o3;
  221.  
  222. h1 = bits >> 18 & 0x3f;
  223. h2 = bits >> 12 & 0x3f;
  224. h3 = bits >> 6 & 0x3f;
  225. h4 = bits & 0x3f;
  226.  
  227. // use hexets to index into b64, and append result to encoded string
  228. tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
  229. } while (i < data.length);
  230.  
  231. enc = tmp_arr.join('');
  232.  
  233. switch (data.length % 3) {
  234. case 1:
  235. enc = enc.slice(0, -2) + '==';
  236. break;
  237. case 2:
  238. enc = enc.slice(0, -1) + '=';
  239. break;
  240. }
  241.  
  242. return enc;
  243. }
  244.  
  245.  
  246. MyTwstats.loaded = true;
  247. MyTwstats.sendReport(MyTwstats.getReport());
  248. clearTimeout(MyTwstats.timer);
Add Comment
Please, Sign In to add comment