Slupik98

[PLEMIONA] Perfect attack

Apr 27th, 2016
20,008
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.67 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Perfect attack
  3. // @version RTM 1.0.4
  4. // @description Pozwala automatycznie wysyłać ataki i karety
  5. // @downloadURL http://pastebin.com/raw/LmXZDkw9
  6. // @updateURL http://pastebin.com/raw/LmXZDkw9
  7. // @match https://*.plemiona.pl/game.php?village=*&screen=place&try=confirm*
  8. // @match http://*.plemiona.pl/game.php?village=*&screen=place&try=confirm*
  9. // ==/UserScript==
  10.  
  11. // Zabraniam rozpowszechniania, kopiowania i używania tego skryptu. Powstał do celów nauki języka JavaScript a nie hackingu gry. Łamie on regulamin, dlatego nakazuję natychmiastowe usunięcie wszystkich kopii.
  12. // W przypadku niezastosowania się do podanych wyżej rad rozważę podjęcie dalszych kroków w tym prawnych (łamanie zasad licencyjnych). Prawdopodobnie jednym z pierwszych będzie przekazanie adresów IP administracji gry :)
  13.  
  14. if (!('contains' in String.prototype)) {
  15. String.prototype.contains = function (str, startIndex) {
  16. return -1 !== String.prototype.indexOf.call(this, str, startIndex);
  17. };
  18. }
  19. if (!('replaceAll' in String.prototype)) {
  20. String.prototype.replaceAll = function (token, newToken, ignoreCase) {
  21. var _token;
  22. var str = this + "";
  23. var i = -1;
  24.  
  25. if (typeof token === "string") {
  26. if (ignoreCase) {
  27. _token = token.toLowerCase();
  28.  
  29. while ((
  30. i = str.toLowerCase().indexOf(
  31. _token, i >= 0 ? i + newToken.length : 0
  32. )
  33. ) !== -1
  34. ) {
  35. str = str.substring(0, i) +
  36. newToken +
  37. str.substring(i + token.length);
  38. }
  39. } else {
  40. return this.split(token).join(newToken);
  41. }
  42. }
  43. return str;
  44. };
  45. }
  46. function stringToDate(_date, _format, _delimiter) {
  47. var formatLowerCase = _format.toLowerCase();
  48. var formatItems = formatLowerCase.split(_delimiter);
  49. var dateItems = _date.split(_delimiter);
  50. var monthIndex = formatItems.indexOf("mm");
  51. var dayIndex = formatItems.indexOf("dd");
  52. var yearIndex = formatItems.indexOf("yyyy");
  53. var month = parseInt(dateItems[monthIndex]);
  54. month -= 1;
  55. var formatedDate = new Date(dateItems[yearIndex], month, dateItems[dayIndex]);
  56. return formatedDate;
  57. }
  58. function sleep(milliseconds) {
  59. var start = new Date().getTime();
  60. for (var i = 0; i < 1e7; i++) {
  61. if ((new Date().getTime() - start) > milliseconds) {
  62. break;
  63. }
  64. }
  65. }
  66. function round(n, k) {
  67. var factor = Math.pow(10, k);
  68. return Math.round(n * factor) / factor;
  69. }
  70. function median(values) {
  71. values.sort(function (a, b) { return a - b; });
  72. var half = Math.floor(values.length / 2);
  73. if (values.length % 2) {
  74. return values[half];
  75. } else {
  76. return (values[half - 1] + values[half]) / 2.0;
  77. }
  78. }
  79. function formateDigit(digit) {
  80. var number = digit;
  81. if (digit < 10) {
  82. number = "0" + digit;
  83. }
  84. return number;
  85. }
  86.  
  87. var PerfectAttack_Graphic = {
  88. PASTE_FIELD_REMOVE: true,
  89. init: function () {
  90. var place = document.getElementById('inner-border');
  91. var nowDate = PerfectAttack_Core.getFormatedServerDate();
  92. var todayDay = nowDate.getFullYear() + '-' + PerfectAttack_Core.getCustomMonthFormat(nowDate) +
  93. '-' + nowDate.getDate();
  94. var width = document.getElementById('place_confirm_units').offsetWidth;
  95. place.innerHTML = place.innerHTML +
  96. '<table width="100%" cellspacing="0" id="main-table-autoattack" align="left"><tbody><tr><td style="width: 100%;padding: 10px;">' +
  97. ' <table id="attackTime-table"><tbody><tr>' +
  98. ' <td valign="top">' +
  99. ' <table class="vis" style="min-width:' + width + 'px" width="100%"><tbody>' +
  100. ' <tr><th width="100%">Czas dojścia ataku</th></tr>' +
  101. ' <tr><td class="nowrap" style="height: 35px;" align="left">' +
  102. ' <form id="time" name="timeForm" action="">' +
  103. ' <input id="date" type="date" name="date" min=' + todayDay + '>' +
  104. ' <input id="tH" type="number" name="hours" min="1" max="24" step="1" placeholder="godzina">:' +
  105. ' <input id="tM" type="number" name="minutes" min="0" max="60" step="1" placeholder="minuta">:' +
  106. ' <input id="tS" type="number" name="seconds" min="0" max="60" step="1" placeholder="sekunda">:' +
  107. ' <input id="tMS" type="number" name="miliseconds" min="0" max="1000" step="1" placeholder="milisekunda">' +
  108. ' <button id="btnSumbitAttakTime" type="button" class="btn">Zatwierdź</button>' +
  109. ' <a>' +
  110. ' <font size="2.5" color="red" id="errorInfoSumbitTimeAttack" style="visibility: hidden;">' +
  111. ' <b>Nie zatwierdziłeś zmiany!</b>' +
  112. ' </font>' +
  113. ' </a>' +
  114. ' </form>' +
  115. ' <font id="pasteInfoLabel" color="black">Możesz też wkleić datę!</font>' +
  116. ' <form id="pasteFieldForm">' +
  117. ' <a>Możesz to też po prostu wkleić!</a><input type="text" id="pasteField"></form>' +//value="yyyy.MM.dd HH:mm:ss:ms"
  118. ' </td></tr>' +
  119. ' </tbody></table>' +
  120. ' </td>' +
  121. ' </tr></tbody></table>' +
  122. ' <table id="server-delay-table"><tbody><tr>' +
  123. ' <td valign="top">' +
  124. ' <table class="vis" style="min-width:' + width + 'px" width="100%"><tbody>' +
  125. ' <tr><th width="100%">Opóźnienie do serwera</th></tr>' +
  126. ' <tr><td class="nowrap" style="height: 35px;" align="left">' +
  127. ' <form id="timeDelayServer" name="timeDelayServer" action="">' +
  128. ' <input id="timeDelayServerValue" type="number" name="timeDelayServer" min="0" max="10000" step="1" value="' + Timing.offset_to_server + '">' +
  129. ' <button id="sumbitDelayServer" type="button" class="btn">Zatwierdź</button>' +
  130. ' <a>' +
  131. ' <font size="2.5" color="red" id="errorInfoSumbitDelay" style="visibility: hidden;">' +
  132. ' <b>Nie zatwierdziłeś zmiany!</b>' +
  133. ' </font>' +
  134. ' </a>' +
  135. ' </form>' +
  136. ' </td></tr>' +
  137. ' </tbody></table>' +
  138. ' </td>' +
  139. ' </tr></tbody></table>' +
  140. ' <table id="time-diff-table"><tbody><tr>' +
  141. ' <td valign="top">' +
  142. ' <table class="vis" style="min-width:' + width + 'px" width="100%"><tbody>' +
  143. ' <tr><th width="100%">Różnica czasu między komputerem a serwerem(w milisekundach)</th></tr>' +
  144. ' <tr><td class="nowrap" style="height: 24px;">' +
  145. ' <form id="time-different">' +
  146. ' <input id="timeDifferentValue" type="number" name="timeDifferent" min="0" max="10000" step="1" value="' + this.diffBetweenServerAndClientTime + '">' +
  147. ' <button id="sumbitTimeDifferentValue" type="button" class="btn">Zatwierdź</button>' +
  148. ' <a>' +
  149. ' <font size="2.5" color="red" id="errorInfoSumbitTimeDifferent" style="visibility: hidden;">' +
  150. ' <b>Nie zatwierdziłeś zmiany!</b>' +
  151. ' </font>' +
  152. ' </a>' +
  153. ' </form>' +
  154. ' </td></tr>' +
  155. ' </tbody></table>' +
  156. ' </td>' +
  157. ' </tr></tbody></table>' +
  158. ' <table id="nobleman-mod-table"><tbody><tr>' +
  159. ' <td valign="top">' +
  160. ' <table class="vis" style="min-width:' + width + 'px" width="100%"><tbody>' +
  161. ' <tr><th width="100%">Tryb karety</th></tr>' +
  162. ' <tr><td class="nowrap" style="height: 24px;">' +
  163. ' <form id="nobleman-mode">' +
  164. ' <input type="checkbox" id="nobleman-mode-checkbox" value="Tryb karety">Tryb karety</input>' +
  165. ' </form>' +
  166. ' </td></tr>' +
  167. ' </tbody></table>' +
  168. ' </td>' +
  169. ' </tr></tbody></table>' +
  170. ' <table id="log-list-table"><tbody><tr>' +
  171. ' <td valign="top">' +
  172. ' <table class="vis" style="min-width:' + width + 'px" width="100%"><tbody>' +
  173. ' <tr><th width="100%">Logs</th></tr>' +
  174. ' <tr><td class="nowrap">' +
  175. ' <form id="log-list">' +
  176. ' <textarea id="logsOfAutoSend" name="log" rows="10" cols="70" readonly="true" style="min-width:' + width + 'px" width="100%">' +
  177. 'Wykonane czyności:' +
  178. '</textarea>' +
  179. ' </form>' +
  180. ' </td></tr>' +
  181. ' </tbody></table>' +
  182. ' </td>' +
  183. ' </tr></tbody></table>' +
  184. '</td></tr></tbody></table>';
  185.  
  186. $("#attackTime-table").outerWidth(($("#logsOfAutoSend").outerWidth()));
  187. $("#server-delay-table").outerWidth(($("#logsOfAutoSend").outerWidth()));
  188. $("#time-diff-table").outerWidth(($("#logsOfAutoSend").outerWidth()));
  189. $("#nobleman-mod-table").outerWidth(($("#logsOfAutoSend").outerWidth()));
  190.  
  191. if (PerfectAttack_Graphic.PASTE_FIELD_REMOVE) {
  192. document.getElementById('pasteFieldForm').remove();
  193. } else {
  194. document.getElementById('pasteInfoLabel').remove();
  195. }
  196. },
  197. addLogInfo: function (log) {
  198. document.getElementById("logsOfAutoSend").value = document.getElementById("logsOfAutoSend").value + '\n' + log;
  199. },
  200. textareaResize: function (source, dest) {
  201. var resizeInt = null;
  202. var resizeEvent = function () {
  203. dest.outerWidth(source.outerWidth());
  204. };
  205. source.on("mousedown", function (e) {
  206. resizeInt = setInterval(resizeEvent, 1000 / 23);
  207. });
  208. $(window).on("mouseup", function (e) {
  209. if (resizeInt !== null) {
  210. clearInterval(resizeInt);
  211. }
  212. resizeEvent();
  213. });
  214. },
  215. disableSettings: function (disableValue) {
  216. document.getElementById("date").disabled = disableValue;
  217. document.getElementById("tH").disabled = disableValue;
  218. document.getElementById("tM").disabled = disableValue;
  219. document.getElementById("tS").disabled = disableValue;
  220. document.getElementById("tMS").disabled = disableValue;
  221. document.getElementById("btnSumbitAttakTime").disabled = disableValue;
  222. document.getElementById("timeDelayServerValue").disabled = disableValue;
  223. document.getElementById("sumbitDelayServer").disabled = disableValue;
  224. document.getElementById("timeDifferentValue").disabled = disableValue;
  225. document.getElementById("sumbitTimeDifferentValue").disabled = disableValue;
  226. document.getElementById("nobleman-mode-checkbox").disabled = disableValue;
  227. },
  228. setErrorInfoCondition: function (hideInfo) {
  229. var elementToChange = document.getElementById(hideInfo.name);
  230. if (hideInfo.isToHide) {
  231. elementToChange.style.visibility = 'visible';
  232. } else {
  233. elementToChange.style.visibility = 'hidden';
  234. }
  235. },
  236. /*
  237. 2017.01.02 17:21:23:001
  238. 2017-01-02 17:21:23:001
  239.  
  240. 01.02.2017 17:21:23:001
  241. 02-05-2017 17:21:23:001
  242.  
  243. jutro o 23:21:23:001
  244. */
  245. //test: 2017.01.02 17:21:23:001
  246. pasteTimeEventHandler: function (e) {
  247. if (e !== null) {
  248. var pastedValue = e.clipboardData.getData('Text');
  249. var finalValue;
  250. var dontAdOneToMonth = false;
  251. if (pastedValue.contains('jutro') || pastedValue.contains('tomorrow')) {
  252. dontAdOneToMonth=true;
  253. var today = new Date(Date.now());
  254. var tomorrow = new Date();
  255. tomorrow.setDate(today.getDate() + 1);
  256. if (tomorrow.toLocaleString().contains(',')) {
  257. pastedValue = pastedValue.replaceAll('jutro o', tomorrow.toLocaleString().split(',')[0]);
  258. pastedValue = pastedValue.replaceAll('tomorrow at', tomorrow.toLocaleString().split(',')[0]);
  259. } else {
  260. pastedValue = pastedValue.replaceAll('jutro o', tomorrow.toLocaleString());
  261. pastedValue = pastedValue.replaceAll('tomorrow at', tomorrow.toLocaleString());
  262. }
  263. finalValue = pastedValue;
  264. console.log(finalValue);
  265. }
  266. if (pastedValue.contains(' ')) {
  267. finalValue = pastedValue;
  268. } else {
  269. finalValue = '01.01.2000 ' + pastedValue;
  270. }
  271.  
  272. //var date = new Date(Date.parse(finalValue, "dd.MM.yyyy HH:mm:ss:SSS"));
  273. finalValue.replaceAll('-', '.');
  274. var date = new Date(
  275. parseInt(finalValue.split(' ')[0].split('.')[2]),
  276. parseInt(finalValue.split(' ')[0].split('.')[1]),
  277. parseInt(finalValue.split(' ')[0].split('.')[0]),
  278.  
  279. parseInt(finalValue.split(' ')[1].split(':')[0]),
  280. parseInt(finalValue.split(' ')[1].split(':')[1]),
  281. parseInt(finalValue.split(' ')[1].split(':')[2]),
  282. parseInt(finalValue.split(' ')[1].split(':')[3])
  283. );
  284. console.log(date);
  285. if (!isNaN(date)) {
  286. console.log(date.getTime());
  287. console.log(Date.now());
  288. console.log(date.getMonth());
  289. if (date.getTime() > Date.now()) {
  290. setTimeout(function () {
  291. if (dontAdOneToMonth) {
  292. document.getElementById("date").value =
  293. date.getFullYear() + '-' +
  294. formateDigit(date.getMonth()) + '-' +
  295. formateDigit(date.getDate());
  296. } else {
  297. document.getElementById("date").value =
  298. date.getFullYear() + '-' +
  299. formateDigit(date.getMonth() + 1) + '-' +
  300. formateDigit(date.getDate());
  301. }
  302. document.getElementById("tH").value = date.getHours();
  303. document.getElementById("tM").value = date.getMinutes();
  304. document.getElementById("tS").value = date.getSeconds();
  305. document.getElementById("tMS").value = date.getMilliseconds();
  306.  
  307. PerfectAttack_Graphic.setErrorInfoCondition({
  308. isToHide: true,
  309. name: 'errorInfoSumbitTimeAttack'
  310. });
  311. }, 100);
  312. } else {
  313. setTimeout(function () {
  314. e.target.value = "";
  315. PerfectAttack_Graphic.addLogInfo('Podana data(' + pastedValue + ') już mineła!');
  316. });
  317. }
  318. } else {
  319. setTimeout(function () {
  320. e.target.value = "";
  321. PerfectAttack_Graphic.addLogInfo('Użyto daty w błędnym formacie(' + pastedValue + ')');
  322. });
  323. }
  324. }
  325. },
  326. };
  327. var PerfectAttack_Core = {
  328. getFormatedServerDate: function () {
  329. return stringToDate(PerfectAttack_Core.getServerDateLabel(), "dd/MM/yyyy", "/");
  330. },
  331. getServerDateLabel: function () {
  332. return document.getElementById('serverDate').innerHTML;
  333. },
  334. getCustomMonthFormat: function (date) {
  335. if (date === null) {
  336. date = new Date();
  337. }
  338. var month = (date.getMonth()) + 1;
  339. if (month < 10) {
  340. month = "0" + month;
  341. }
  342. return month;
  343. }
  344. };
  345.  
  346. (function () {
  347. var URL = document.URL;
  348. if (URL.contains('plemiona.pl') && URL.contains('game.php?village=') && URL.contains('&screen=place&try=confirm')) {
  349. PerfectAttack_Graphic.init();
  350.  
  351. document.getElementById("date").addEventListener("paste", function (e) {
  352. PerfectAttack_Graphic.pasteTimeEventHandler(e);
  353. });
  354. document.getElementById("tH").addEventListener("paste", function (e) {
  355. PerfectAttack_Graphic.pasteTimeEventHandler(e);
  356. });
  357. document.getElementById("tM").addEventListener("paste", function (e) {
  358. PerfectAttack_Graphic.pasteTimeEventHandler(e);
  359. });
  360. document.getElementById("tS").addEventListener("paste", function (e) {
  361. PerfectAttack_Graphic.pasteTimeEventHandler(e);
  362. });
  363. document.getElementById("tMS").addEventListener("paste", function (e) {
  364. PerfectAttack_Graphic.pasteTimeEventHandler(e);
  365. });
  366. if (!PerfectAttack_Graphic.PASTE_FIELD_REMOVE) {
  367. document.getElementById("pasteField").addEventListener("paste", function (e) {
  368. PerfectAttack_Graphic.pasteTimeEventHandler(e);
  369. });
  370. }
  371.  
  372. var scriptList = document.getElementsByTagName('script');
  373. for (var i = 0; i < scriptList.length; i++) {
  374. var scriptCode = scriptList[i].innerText;
  375. if (scriptCode.contains('Place.confirmScreen.init(')) {
  376. eval(scriptCode);
  377. }
  378. }
  379.  
  380. document.getElementById("timeDifferentValue").addEventListener("change", function () {
  381. PerfectAttack_Graphic.setErrorInfoCondition({
  382. isToHide: true,
  383. name: 'errorInfoSumbitTimeDifferent'
  384. });
  385. });
  386. document.getElementById("timeDelayServerValue").addEventListener("change", function () {
  387. PerfectAttack_Graphic.setErrorInfoCondition({
  388. isToHide: true,
  389. name: 'errorInfoSumbitDelay'
  390. });
  391. });
  392. document.getElementById("date").addEventListener("change", function () {
  393. PerfectAttack_Graphic.setErrorInfoCondition({
  394. isToHide: true,
  395. name: 'errorInfoSumbitTimeAttack'
  396. });
  397. });
  398. document.getElementById("tH").addEventListener("change", function () {
  399. PerfectAttack_Graphic.setErrorInfoCondition({
  400. isToHide: true,
  401. name: 'errorInfoSumbitTimeAttack'
  402. });
  403. });
  404. document.getElementById("tM").addEventListener("change", function () {
  405. PerfectAttack_Graphic.setErrorInfoCondition({
  406. isToHide: true,
  407. name: 'errorInfoSumbitTimeAttack'
  408. });
  409. });
  410. document.getElementById("tS").addEventListener("change", function () {
  411. PerfectAttack_Graphic.setErrorInfoCondition({
  412. isToHide: true,
  413. name: 'errorInfoSumbitTimeAttack'
  414. });
  415. });
  416. document.getElementById("tMS").addEventListener("change", function () {
  417. PerfectAttack_Graphic.setErrorInfoCondition({
  418. isToHide: true,
  419. name: 'errorInfoSumbitTimeAttack'
  420. });
  421. });
  422.  
  423. document.getElementById("sumbitDelayServer").addEventListener("click", function () {
  424. PerfectAttack_Graphic.setErrorInfoCondition({
  425. isToHide: false,
  426. name: 'errorInfoSumbitDelay'
  427. });
  428. });
  429. document.getElementById("sumbitTimeDifferentValue").addEventListener("click", function () {
  430. PerfectAttack_Graphic.setErrorInfoCondition({
  431. isToHide: false,
  432. name: 'errorInfoSumbitTimeDifferent'
  433. });
  434. });
  435. document.getElementById("btnSumbitAttakTime").addEventListener("click", function () {
  436. PerfectAttack_Graphic.setErrorInfoCondition({
  437. isToHide: false,
  438. name: 'errorInfoSumbitTimeAttack'
  439. });
  440. });
  441.  
  442. PerfectAttack_Graphic.textareaResize($("#logsOfAutoSend"), $("#attackTime-table"));
  443. PerfectAttack_Graphic.textareaResize($("#logsOfAutoSend"), $("#server-delay-table"));
  444. PerfectAttack_Graphic.textareaResize($("#logsOfAutoSend"), $("#time-diff-table"));
  445. PerfectAttack_Graphic.textareaResize($("#logsOfAutoSend"), $("#nobleman-mod-table"));
  446. }
  447. })();
  448.  
  449. //https://raw.githubusercontent.com/jdfreder/pingjs/master/ping.js
  450. (function (root, factory) {
  451. if (typeof define === 'function' && define.amd) { define([], factory); } else if (typeof module === 'object' && module.exports) { module.exports = factory(); } else { root.ping = factory(); }
  452. } (this, function () {
  453. /**
  454. * Creates and loads an image element by url.
  455. * @param {String} url
  456. * @return {Promise} promise that resolves to an image element or
  457. * fails to an Error.
  458. */
  459. function request_image(url) {
  460. return new Promise(function (resolve, reject) {
  461. var img = new Image();
  462. img.onload = function () { resolve(img); };
  463. img.onerror = function () { reject(url); };
  464. img.src = url + '?random-no-cache=' + Math.floor((1 + Math.random()) * 0x10000).toString(16);
  465. });
  466. }
  467. /**
  468. * Pings a url.
  469. * @param {String} url
  470. * @param {Number} multiplier - optional, factor to adjust the ping by. 0.3 works well for HTTP servers.
  471. * @return {Promise} promise that resolves to a ping (ms, float).
  472. */
  473. function ping(url, multiplier) {
  474. return new Promise(function (resolve, reject) {
  475. var start = (new Date()).getTime();
  476. var response = function () {
  477. var delta = ((new Date()).getTime() - start);
  478. delta *= (multiplier || 1);
  479. resolve(delta);
  480. };
  481. request_image(url).then(response).catch(response);
  482. });
  483. }
  484. return ping;
  485. }));
Advertisement
Add Comment
Please, Sign In to add comment