Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Perfect attack
- // @version RTM 1.0.4
- // @description Pozwala automatycznie wysyłać ataki i karety
- // @downloadURL http://pastebin.com/raw/LmXZDkw9
- // @updateURL http://pastebin.com/raw/LmXZDkw9
- // @match https://*.plemiona.pl/game.php?village=*&screen=place&try=confirm*
- // @match http://*.plemiona.pl/game.php?village=*&screen=place&try=confirm*
- // ==/UserScript==
- // 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.
- // 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 :)
- if (!('contains' in String.prototype)) {
- String.prototype.contains = function (str, startIndex) {
- return -1 !== String.prototype.indexOf.call(this, str, startIndex);
- };
- }
- if (!('replaceAll' in String.prototype)) {
- String.prototype.replaceAll = function (token, newToken, ignoreCase) {
- var _token;
- var str = this + "";
- var i = -1;
- if (typeof token === "string") {
- if (ignoreCase) {
- _token = token.toLowerCase();
- while ((
- i = str.toLowerCase().indexOf(
- _token, i >= 0 ? i + newToken.length : 0
- )
- ) !== -1
- ) {
- str = str.substring(0, i) +
- newToken +
- str.substring(i + token.length);
- }
- } else {
- return this.split(token).join(newToken);
- }
- }
- return str;
- };
- }
- function stringToDate(_date, _format, _delimiter) {
- var formatLowerCase = _format.toLowerCase();
- var formatItems = formatLowerCase.split(_delimiter);
- var dateItems = _date.split(_delimiter);
- var monthIndex = formatItems.indexOf("mm");
- var dayIndex = formatItems.indexOf("dd");
- var yearIndex = formatItems.indexOf("yyyy");
- var month = parseInt(dateItems[monthIndex]);
- month -= 1;
- var formatedDate = new Date(dateItems[yearIndex], month, dateItems[dayIndex]);
- return formatedDate;
- }
- function sleep(milliseconds) {
- var start = new Date().getTime();
- for (var i = 0; i < 1e7; i++) {
- if ((new Date().getTime() - start) > milliseconds) {
- break;
- }
- }
- }
- function round(n, k) {
- var factor = Math.pow(10, k);
- return Math.round(n * factor) / factor;
- }
- function median(values) {
- values.sort(function (a, b) { return a - b; });
- var half = Math.floor(values.length / 2);
- if (values.length % 2) {
- return values[half];
- } else {
- return (values[half - 1] + values[half]) / 2.0;
- }
- }
- function formateDigit(digit) {
- var number = digit;
- if (digit < 10) {
- number = "0" + digit;
- }
- return number;
- }
- var PerfectAttack_Graphic = {
- PASTE_FIELD_REMOVE: true,
- init: function () {
- var place = document.getElementById('inner-border');
- var nowDate = PerfectAttack_Core.getFormatedServerDate();
- var todayDay = nowDate.getFullYear() + '-' + PerfectAttack_Core.getCustomMonthFormat(nowDate) +
- '-' + nowDate.getDate();
- var width = document.getElementById('place_confirm_units').offsetWidth;
- place.innerHTML = place.innerHTML +
- '<table width="100%" cellspacing="0" id="main-table-autoattack" align="left"><tbody><tr><td style="width: 100%;padding: 10px;">' +
- ' <table id="attackTime-table"><tbody><tr>' +
- ' <td valign="top">' +
- ' <table class="vis" style="min-width:' + width + 'px" width="100%"><tbody>' +
- ' <tr><th width="100%">Czas dojścia ataku</th></tr>' +
- ' <tr><td class="nowrap" style="height: 35px;" align="left">' +
- ' <form id="time" name="timeForm" action="">' +
- ' <input id="date" type="date" name="date" min=' + todayDay + '>' +
- ' <input id="tH" type="number" name="hours" min="1" max="24" step="1" placeholder="godzina">:' +
- ' <input id="tM" type="number" name="minutes" min="0" max="60" step="1" placeholder="minuta">:' +
- ' <input id="tS" type="number" name="seconds" min="0" max="60" step="1" placeholder="sekunda">:' +
- ' <input id="tMS" type="number" name="miliseconds" min="0" max="1000" step="1" placeholder="milisekunda">' +
- ' <button id="btnSumbitAttakTime" type="button" class="btn">Zatwierdź</button>' +
- ' <a>' +
- ' <font size="2.5" color="red" id="errorInfoSumbitTimeAttack" style="visibility: hidden;">' +
- ' <b>Nie zatwierdziłeś zmiany!</b>' +
- ' </font>' +
- ' </a>' +
- ' </form>' +
- ' <font id="pasteInfoLabel" color="black">Możesz też wkleić datę!</font>' +
- ' <form id="pasteFieldForm">' +
- ' <a>Możesz to też po prostu wkleić!</a><input type="text" id="pasteField"></form>' +//value="yyyy.MM.dd HH:mm:ss:ms"
- ' </td></tr>' +
- ' </tbody></table>' +
- ' </td>' +
- ' </tr></tbody></table>' +
- ' <table id="server-delay-table"><tbody><tr>' +
- ' <td valign="top">' +
- ' <table class="vis" style="min-width:' + width + 'px" width="100%"><tbody>' +
- ' <tr><th width="100%">Opóźnienie do serwera</th></tr>' +
- ' <tr><td class="nowrap" style="height: 35px;" align="left">' +
- ' <form id="timeDelayServer" name="timeDelayServer" action="">' +
- ' <input id="timeDelayServerValue" type="number" name="timeDelayServer" min="0" max="10000" step="1" value="' + Timing.offset_to_server + '">' +
- ' <button id="sumbitDelayServer" type="button" class="btn">Zatwierdź</button>' +
- ' <a>' +
- ' <font size="2.5" color="red" id="errorInfoSumbitDelay" style="visibility: hidden;">' +
- ' <b>Nie zatwierdziłeś zmiany!</b>' +
- ' </font>' +
- ' </a>' +
- ' </form>' +
- ' </td></tr>' +
- ' </tbody></table>' +
- ' </td>' +
- ' </tr></tbody></table>' +
- ' <table id="time-diff-table"><tbody><tr>' +
- ' <td valign="top">' +
- ' <table class="vis" style="min-width:' + width + 'px" width="100%"><tbody>' +
- ' <tr><th width="100%">Różnica czasu między komputerem a serwerem(w milisekundach)</th></tr>' +
- ' <tr><td class="nowrap" style="height: 24px;">' +
- ' <form id="time-different">' +
- ' <input id="timeDifferentValue" type="number" name="timeDifferent" min="0" max="10000" step="1" value="' + this.diffBetweenServerAndClientTime + '">' +
- ' <button id="sumbitTimeDifferentValue" type="button" class="btn">Zatwierdź</button>' +
- ' <a>' +
- ' <font size="2.5" color="red" id="errorInfoSumbitTimeDifferent" style="visibility: hidden;">' +
- ' <b>Nie zatwierdziłeś zmiany!</b>' +
- ' </font>' +
- ' </a>' +
- ' </form>' +
- ' </td></tr>' +
- ' </tbody></table>' +
- ' </td>' +
- ' </tr></tbody></table>' +
- ' <table id="nobleman-mod-table"><tbody><tr>' +
- ' <td valign="top">' +
- ' <table class="vis" style="min-width:' + width + 'px" width="100%"><tbody>' +
- ' <tr><th width="100%">Tryb karety</th></tr>' +
- ' <tr><td class="nowrap" style="height: 24px;">' +
- ' <form id="nobleman-mode">' +
- ' <input type="checkbox" id="nobleman-mode-checkbox" value="Tryb karety">Tryb karety</input>' +
- ' </form>' +
- ' </td></tr>' +
- ' </tbody></table>' +
- ' </td>' +
- ' </tr></tbody></table>' +
- ' <table id="log-list-table"><tbody><tr>' +
- ' <td valign="top">' +
- ' <table class="vis" style="min-width:' + width + 'px" width="100%"><tbody>' +
- ' <tr><th width="100%">Logs</th></tr>' +
- ' <tr><td class="nowrap">' +
- ' <form id="log-list">' +
- ' <textarea id="logsOfAutoSend" name="log" rows="10" cols="70" readonly="true" style="min-width:' + width + 'px" width="100%">' +
- 'Wykonane czyności:' +
- '</textarea>' +
- ' </form>' +
- ' </td></tr>' +
- ' </tbody></table>' +
- ' </td>' +
- ' </tr></tbody></table>' +
- '</td></tr></tbody></table>';
- $("#attackTime-table").outerWidth(($("#logsOfAutoSend").outerWidth()));
- $("#server-delay-table").outerWidth(($("#logsOfAutoSend").outerWidth()));
- $("#time-diff-table").outerWidth(($("#logsOfAutoSend").outerWidth()));
- $("#nobleman-mod-table").outerWidth(($("#logsOfAutoSend").outerWidth()));
- if (PerfectAttack_Graphic.PASTE_FIELD_REMOVE) {
- document.getElementById('pasteFieldForm').remove();
- } else {
- document.getElementById('pasteInfoLabel').remove();
- }
- },
- addLogInfo: function (log) {
- document.getElementById("logsOfAutoSend").value = document.getElementById("logsOfAutoSend").value + '\n' + log;
- },
- textareaResize: function (source, dest) {
- var resizeInt = null;
- var resizeEvent = function () {
- dest.outerWidth(source.outerWidth());
- };
- source.on("mousedown", function (e) {
- resizeInt = setInterval(resizeEvent, 1000 / 23);
- });
- $(window).on("mouseup", function (e) {
- if (resizeInt !== null) {
- clearInterval(resizeInt);
- }
- resizeEvent();
- });
- },
- disableSettings: function (disableValue) {
- document.getElementById("date").disabled = disableValue;
- document.getElementById("tH").disabled = disableValue;
- document.getElementById("tM").disabled = disableValue;
- document.getElementById("tS").disabled = disableValue;
- document.getElementById("tMS").disabled = disableValue;
- document.getElementById("btnSumbitAttakTime").disabled = disableValue;
- document.getElementById("timeDelayServerValue").disabled = disableValue;
- document.getElementById("sumbitDelayServer").disabled = disableValue;
- document.getElementById("timeDifferentValue").disabled = disableValue;
- document.getElementById("sumbitTimeDifferentValue").disabled = disableValue;
- document.getElementById("nobleman-mode-checkbox").disabled = disableValue;
- },
- setErrorInfoCondition: function (hideInfo) {
- var elementToChange = document.getElementById(hideInfo.name);
- if (hideInfo.isToHide) {
- elementToChange.style.visibility = 'visible';
- } else {
- elementToChange.style.visibility = 'hidden';
- }
- },
- /*
- 2017.01.02 17:21:23:001
- 2017-01-02 17:21:23:001
- 01.02.2017 17:21:23:001
- 02-05-2017 17:21:23:001
- jutro o 23:21:23:001
- */
- //test: 2017.01.02 17:21:23:001
- pasteTimeEventHandler: function (e) {
- if (e !== null) {
- var pastedValue = e.clipboardData.getData('Text');
- var finalValue;
- var dontAdOneToMonth = false;
- if (pastedValue.contains('jutro') || pastedValue.contains('tomorrow')) {
- dontAdOneToMonth=true;
- var today = new Date(Date.now());
- var tomorrow = new Date();
- tomorrow.setDate(today.getDate() + 1);
- if (tomorrow.toLocaleString().contains(',')) {
- pastedValue = pastedValue.replaceAll('jutro o', tomorrow.toLocaleString().split(',')[0]);
- pastedValue = pastedValue.replaceAll('tomorrow at', tomorrow.toLocaleString().split(',')[0]);
- } else {
- pastedValue = pastedValue.replaceAll('jutro o', tomorrow.toLocaleString());
- pastedValue = pastedValue.replaceAll('tomorrow at', tomorrow.toLocaleString());
- }
- finalValue = pastedValue;
- console.log(finalValue);
- }
- if (pastedValue.contains(' ')) {
- finalValue = pastedValue;
- } else {
- finalValue = '01.01.2000 ' + pastedValue;
- }
- //var date = new Date(Date.parse(finalValue, "dd.MM.yyyy HH:mm:ss:SSS"));
- finalValue.replaceAll('-', '.');
- var date = new Date(
- parseInt(finalValue.split(' ')[0].split('.')[2]),
- parseInt(finalValue.split(' ')[0].split('.')[1]),
- parseInt(finalValue.split(' ')[0].split('.')[0]),
- parseInt(finalValue.split(' ')[1].split(':')[0]),
- parseInt(finalValue.split(' ')[1].split(':')[1]),
- parseInt(finalValue.split(' ')[1].split(':')[2]),
- parseInt(finalValue.split(' ')[1].split(':')[3])
- );
- console.log(date);
- if (!isNaN(date)) {
- console.log(date.getTime());
- console.log(Date.now());
- console.log(date.getMonth());
- if (date.getTime() > Date.now()) {
- setTimeout(function () {
- if (dontAdOneToMonth) {
- document.getElementById("date").value =
- date.getFullYear() + '-' +
- formateDigit(date.getMonth()) + '-' +
- formateDigit(date.getDate());
- } else {
- document.getElementById("date").value =
- date.getFullYear() + '-' +
- formateDigit(date.getMonth() + 1) + '-' +
- formateDigit(date.getDate());
- }
- document.getElementById("tH").value = date.getHours();
- document.getElementById("tM").value = date.getMinutes();
- document.getElementById("tS").value = date.getSeconds();
- document.getElementById("tMS").value = date.getMilliseconds();
- PerfectAttack_Graphic.setErrorInfoCondition({
- isToHide: true,
- name: 'errorInfoSumbitTimeAttack'
- });
- }, 100);
- } else {
- setTimeout(function () {
- e.target.value = "";
- PerfectAttack_Graphic.addLogInfo('Podana data(' + pastedValue + ') już mineła!');
- });
- }
- } else {
- setTimeout(function () {
- e.target.value = "";
- PerfectAttack_Graphic.addLogInfo('Użyto daty w błędnym formacie(' + pastedValue + ')');
- });
- }
- }
- },
- };
- var PerfectAttack_Core = {
- getFormatedServerDate: function () {
- return stringToDate(PerfectAttack_Core.getServerDateLabel(), "dd/MM/yyyy", "/");
- },
- getServerDateLabel: function () {
- return document.getElementById('serverDate').innerHTML;
- },
- getCustomMonthFormat: function (date) {
- if (date === null) {
- date = new Date();
- }
- var month = (date.getMonth()) + 1;
- if (month < 10) {
- month = "0" + month;
- }
- return month;
- }
- };
- (function () {
- var URL = document.URL;
- if (URL.contains('plemiona.pl') && URL.contains('game.php?village=') && URL.contains('&screen=place&try=confirm')) {
- PerfectAttack_Graphic.init();
- document.getElementById("date").addEventListener("paste", function (e) {
- PerfectAttack_Graphic.pasteTimeEventHandler(e);
- });
- document.getElementById("tH").addEventListener("paste", function (e) {
- PerfectAttack_Graphic.pasteTimeEventHandler(e);
- });
- document.getElementById("tM").addEventListener("paste", function (e) {
- PerfectAttack_Graphic.pasteTimeEventHandler(e);
- });
- document.getElementById("tS").addEventListener("paste", function (e) {
- PerfectAttack_Graphic.pasteTimeEventHandler(e);
- });
- document.getElementById("tMS").addEventListener("paste", function (e) {
- PerfectAttack_Graphic.pasteTimeEventHandler(e);
- });
- if (!PerfectAttack_Graphic.PASTE_FIELD_REMOVE) {
- document.getElementById("pasteField").addEventListener("paste", function (e) {
- PerfectAttack_Graphic.pasteTimeEventHandler(e);
- });
- }
- var scriptList = document.getElementsByTagName('script');
- for (var i = 0; i < scriptList.length; i++) {
- var scriptCode = scriptList[i].innerText;
- if (scriptCode.contains('Place.confirmScreen.init(')) {
- eval(scriptCode);
- }
- }
- document.getElementById("timeDifferentValue").addEventListener("change", function () {
- PerfectAttack_Graphic.setErrorInfoCondition({
- isToHide: true,
- name: 'errorInfoSumbitTimeDifferent'
- });
- });
- document.getElementById("timeDelayServerValue").addEventListener("change", function () {
- PerfectAttack_Graphic.setErrorInfoCondition({
- isToHide: true,
- name: 'errorInfoSumbitDelay'
- });
- });
- document.getElementById("date").addEventListener("change", function () {
- PerfectAttack_Graphic.setErrorInfoCondition({
- isToHide: true,
- name: 'errorInfoSumbitTimeAttack'
- });
- });
- document.getElementById("tH").addEventListener("change", function () {
- PerfectAttack_Graphic.setErrorInfoCondition({
- isToHide: true,
- name: 'errorInfoSumbitTimeAttack'
- });
- });
- document.getElementById("tM").addEventListener("change", function () {
- PerfectAttack_Graphic.setErrorInfoCondition({
- isToHide: true,
- name: 'errorInfoSumbitTimeAttack'
- });
- });
- document.getElementById("tS").addEventListener("change", function () {
- PerfectAttack_Graphic.setErrorInfoCondition({
- isToHide: true,
- name: 'errorInfoSumbitTimeAttack'
- });
- });
- document.getElementById("tMS").addEventListener("change", function () {
- PerfectAttack_Graphic.setErrorInfoCondition({
- isToHide: true,
- name: 'errorInfoSumbitTimeAttack'
- });
- });
- document.getElementById("sumbitDelayServer").addEventListener("click", function () {
- PerfectAttack_Graphic.setErrorInfoCondition({
- isToHide: false,
- name: 'errorInfoSumbitDelay'
- });
- });
- document.getElementById("sumbitTimeDifferentValue").addEventListener("click", function () {
- PerfectAttack_Graphic.setErrorInfoCondition({
- isToHide: false,
- name: 'errorInfoSumbitTimeDifferent'
- });
- });
- document.getElementById("btnSumbitAttakTime").addEventListener("click", function () {
- PerfectAttack_Graphic.setErrorInfoCondition({
- isToHide: false,
- name: 'errorInfoSumbitTimeAttack'
- });
- });
- PerfectAttack_Graphic.textareaResize($("#logsOfAutoSend"), $("#attackTime-table"));
- PerfectAttack_Graphic.textareaResize($("#logsOfAutoSend"), $("#server-delay-table"));
- PerfectAttack_Graphic.textareaResize($("#logsOfAutoSend"), $("#time-diff-table"));
- PerfectAttack_Graphic.textareaResize($("#logsOfAutoSend"), $("#nobleman-mod-table"));
- }
- })();
- //https://raw.githubusercontent.com/jdfreder/pingjs/master/ping.js
- (function (root, factory) {
- if (typeof define === 'function' && define.amd) { define([], factory); } else if (typeof module === 'object' && module.exports) { module.exports = factory(); } else { root.ping = factory(); }
- } (this, function () {
- /**
- * Creates and loads an image element by url.
- * @param {String} url
- * @return {Promise} promise that resolves to an image element or
- * fails to an Error.
- */
- function request_image(url) {
- return new Promise(function (resolve, reject) {
- var img = new Image();
- img.onload = function () { resolve(img); };
- img.onerror = function () { reject(url); };
- img.src = url + '?random-no-cache=' + Math.floor((1 + Math.random()) * 0x10000).toString(16);
- });
- }
- /**
- * Pings a url.
- * @param {String} url
- * @param {Number} multiplier - optional, factor to adjust the ping by. 0.3 works well for HTTP servers.
- * @return {Promise} promise that resolves to a ping (ms, float).
- */
- function ping(url, multiplier) {
- return new Promise(function (resolve, reject) {
- var start = (new Date()).getTime();
- var response = function () {
- var delta = ((new Date()).getTime() - start);
- delta *= (multiplier || 1);
- resolve(delta);
- };
- request_image(url).then(response).catch(response);
- });
- }
- return ping;
- }));
Advertisement
Add Comment
Please, Sign In to add comment