Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript:
- var win = (window.frames.length > 0) ? window.main : window;
- function fnAjaxRequest(url, sendMethod, params, type) {
- var error = null, paylod = null;
- win.$.ajax({
- "async": false, "url": url, "data": params, "dataType": type, "type": String(sendMethod || "GET").toUpperCase(),
- "error": function (req, status, err) {
- error = "ajax: " + status;
- }, "success": function (data, status, req) {
- payload = data;
- }
- });
- if (error) throw (error);
- return payload;
- }
- function fnCreateConfig(name) {
- return win.$(fnAjaxRequest("/interface.php", "GET", { "func": name }, "xml")).find("config");
- }
- function fnCreateUnitConfig() {
- return fnCreateConfig("get_unit_info");
- }
- function getUnitSpeed(unit) {
- var unitConfig = fnCreateUnitConfig();
- var info = [];
- win.$(unitConfig).children(unit).each(function (i, e) { info.push(win.$(e).find("speed").text()); });
- return parseFloat(info) * 60 * 1000;
- }
- function setCookie(cname, cvalue) {
- var d = new Date();
- d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000));
- var expires = "expires=" + d.toUTCString();
- document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
- }
- function getCookie(cname) {
- var name = cname + "=";
- var decodedCookie = decodeURIComponent(document.cookie);
- var ca = decodedCookie.split(';');
- for (var i = 0; i < ca.length; i++) {
- var c = ca[i];
- while (c.charAt(0) == ' ') {
- c = c.substring(1);
- }
- if (c.indexOf(name) == 0) {
- return c.substring(name.length, c.length);
- }
- }
- return "";
- }
- function add() {
- var sum = getCookie("sum");
- setCookie("X" + sum, $('#X').val());
- setCookie("Y" + sum, $('#Y').val());
- setCookie("D" + sum, $('#D').val());
- setCookie("sum", parseInt(sum) + 1);
- }
- function remove(i) {
- var sum = getCookie("sum");
- if (i == (parseInt(sum) - 1)) {
- setCookie("sum", parseInt(sum) - 1);
- }
- else {
- setCookie("X" + i, getCookie("X" + (parseInt(sum) - 1)));
- setCookie("Y" + i, getCookie("Y" + (parseInt(sum) - 1)));
- setCookie("D" + i, getCookie("D" + (parseInt(sum) - 1)));
- setCookie("sum", parseInt(sum) - 1);
- }
- }
- function getDate(date) {
- var currDate = new Date();
- switch (date.slice(6, 11)) {
- case 'dnes ':
- currDate.setHours(parseInt(date.slice(13, 15)), parseInt(date.slice(16, 18)), parseInt(date.slice(19, 21)));
- break;
- case 'zítra':
- currDate.setHours(parseInt(date.slice(14, 16)), parseInt(date.slice(17, 19)), parseInt(date.slice(20, 22)));
- currDate.setDate(currDate.getDate() + 1);
- break;
- default:
- currDate.setHours(parseInt(date.slice(22, 24)), parseInt(date.slice(25, 27)), parseInt(date.slice(28, 30)));
- currDate.setDate(parseInt(date.slice(10, 12)));
- currDate.setMonth(parseInt(date.slice(13, 15)) - 1);
- }
- return currDate;
- }
- function parseDate(string) {
- var day = string.toString().split(" ")[2];
- var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
- var i = 0;
- while (true) {
- if (months[i] == string.toString().split(" ")[1]) { break; }
- i++;
- }
- var time = string.toString().split(" ")[4];
- return day + "." + parseInt(i + 1) + ". v/ve " + time + " hodin";
- }
- function rename(name) {
- if (name.indexOf('Beranidlo') != -1) { return 'ram'; }
- else if (name.indexOf('Špeh') != -1) { return 'spy'; }
- else if (name.indexOf('LK') != -1) { return 'light'; }
- else if (name.indexOf('TK') != -1) { return 'heavy'; }
- else if (name.indexOf('Sekera') != -1) { return 'axe'; }
- else if (name.indexOf('Šlechta') != -1) { return 'snob'; }
- else if (name.indexOf('Meč') != -1) { return 'sword'; }
- return false;
- }
- function shown(name) {
- if (name.indexOf('odhalen') != -1) { return true; }
- else { return false; }
- }
- function calculate() {
- $('#incomings_table th:last-child').after('<th><a>Bude odhalen</a></th>');
- $('#incomings_table td:last-child').after('<td class="watchtower" style="text-align:center"></td>');
- $("tr.nowrap").each(function () {
- var originCoords = $(this).find("td:eq(2)").text();
- originCoords = originCoords.trim();
- originCoords = originCoords.slice(originCoords.length - 12, originCoords.length - 5);
- var originAxis = originCoords.split('|');
- var targetCoords = $(this).find("td:eq(1)").text();
- targetCoords = targetCoords.trim();
- targetCoords = targetCoords.slice(targetCoords.length - 12, targetCoords.length - 5);
- var targetAxis = targetCoords.split('|');
- var date = $(this).find("td:eq(5)").text();
- var maxX = 0;
- var maxY = 0;
- var a = targetAxis[1] - originAxis[1];
- var b = originAxis[0] - targetAxis[0];
- var c = (-1) * (a * originAxis[0] + b * originAxis[1]);
- for (var i = 0; i < parseInt(getCookie("sum")); i++) {
- var m = parseInt(getCookie("X" + i));
- var n = parseInt(getCookie("Y" + i));
- var r = parseFloat(getCookie("D" + i));
- if (Math.sqrt(Math.pow(m - originAxis[0], 2) + Math.pow(n - originAxis[1], 2)) < r) {
- break;
- }
- else if (b == 0) {
- var x1 = targetAxis[0];
- var x2 = targetAxis[0];
- var temp = Math.sqrt((-1) * Math.pow(m, 2) + 2 * m * x1 + Math.pow(r, 2) - Math.pow(x1, 2));
- var y1 = n - temp;
- var y2 = n + temp;
- }
- else if (a == 0) {
- var y1 = targetAxis[1];
- var y2 = targetAxis[1];
- var temp = Math.sqrt((-1) * Math.pow(n, 2) + 2 * n * y1 + Math.pow(r, 2) - Math.pow(y1, 2));
- var x1 = m - temp;
- var x2 = m + temp;
- }
- else {
- var temp = Math.sqrt(Math.pow((-2) * Math.pow(a, 2) * n + 2 * a * b * m + 2 * b * c, 2) - 4 * (Math.pow(a, 2) + Math.pow(b, 2)) * (Math.pow(a, 2) * Math.pow(m, 2) + Math.pow(a, 2) * Math.pow(n, 2) - Math.pow(a, 2) * Math.pow(r, 2) + 2 * a * c * m + Math.pow(c, 2))) + 2 * Math.pow(a, 2) * n - 2 * a * b * m - 2 * b * c;
- var y1 = (1 / (2 * (Math.pow(a, 2) + Math.pow(b, 2)))) * temp;
- var y2 = (1 / (2 * (Math.pow(a, 2) + Math.pow(b, 2)))) * (-1) * temp;
- var x1 = ((-1) * (b * y1) - c) / a;
- var x2 = ((-1) * (b * y2) - c) / a;
- }
- if (Math.sqrt(Math.pow((x1 - originAxis[0]), 2) + Math.pow((y1 - originAxis[1]), 2)) < Math.sqrt(Math.pow((maxX - originAxis[0]), 2) + Math.pow((maxY - originAxis[1]), 2))) {
- maxX = x1;
- maxY = y1;
- }
- else if (Math.sqrt(Math.pow((x2 - originAxis[0]), 2) + Math.pow((y2 - originAxis[1]), 2)) < Math.sqrt(Math.pow((maxX - originAxis[0]), 2) + Math.pow((maxY - originAxis[1]), 2))) {
- maxX = x2;
- maxY = y2;
- }
- }
- var command = $(this).find("span.quickedit-label").text().trim();
- var distance = Math.sqrt(Math.pow((targetAxis[0] - maxX), 2) + Math.pow((targetAxis[1] - maxY), 2)) * getUnitSpeed(rename(command));
- if (i != parseInt(getCookie("sum"))) {
- $(this).find("td.watchtower").html(parseDate(new Date()));
- distance = r;
- }
- else if (maxX == 0 && maxY == 0) {
- $(this).find("td.watchtower").html("-----");
- return;
- }
- if (rename(command)) {
- if (distance > r) { var currDate = new Date(getDate(date) - new Date(Math.floor(distance))); }
- else { var currDate = new Date(); }
- $(this).find("td.watchtower").html(parseDate(currDate));
- if (!shown(command)) {
- $(this).find(".rename-icon").click();
- $(this).find("input[type=text]").val(command.trim() + " - odhalen dne " + parseDate(currDate));
- $(this).find("input[type=button]").click();
- }
- }
- else {
- $(this).find("td.watchtower").html("-----");
- }
- });
- }
- function main() {
- $('.dynamicallyCreated').html("");
- if (getCookie("sum") == "") {
- alert("Dle směrnice EU 2002/58/ES jsem povinen vás informovat, že tento script využívá soubory cookies. Používáním tohoto scriptu souhlasíte s používáním cookies.");
- setCookie("sum", 0);
- }
- var div = '<div class="dynamicallyCreated"><table align="center" style="text-align:center"><tr><th style="text-align:center">Vesnice</th><th style="text-align:center">Dosah</th><th></th></tr>';
- for (var i = 0; i < parseInt(getCookie("sum")); i++) {
- div += '<tr><td>' + getCookie("X" + i) + '|' + getCookie("Y" + i) + '</td><td>' + getCookie("D" + i) + '</td><td><input type="submit" class="btn" onClick="remove(' + i + '); main();" value="Odebrat"></td></tr>';
- }
- div += '<tr><td><input type="text" id="X" maxlength="3" size="3"> | <input type="text" id="Y" maxlength="3" size="3"></td><td><input type="text" id="D" maxlength="4" size="4"></td><td><input type="submit" onClick="add(); main();" class="btn" value="Přidat"></td></td></tr></table>';
- div += '<table align="center"><tr><td><input type="submit" class="btn" onClick="calculate();" value="Vypočítej"></td></tr></table></div>';
- $(div).insertBefore('#paged_view_content');
- }
- $(document).ready(main());
Advertisement
Add Comment
Please, Sign In to add comment