Five_NT

hehe

Nov 2nd, 2021 (edited)
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 25.19 KB | None | 0 0
  1. var version = "1.97";
  2. var updateversion = 1.6;
  3. var keycodes = {
  4.     "a": 65,
  5.     "b": 66,
  6.     "c": 67,
  7.     "skip": 74,
  8.     "right": 39,
  9.     "left": 37,
  10.     "master": 90
  11. };
  12. var keyedits = {
  13.     "a": false,
  14.     "b": false,
  15.     "c": false,
  16.     "skip": false
  17. };
  18. var key;
  19. var keydown = false;
  20. var cansend = true;
  21. var sitter = "";
  22. if (window.game_data.player.sitter != "0") {
  23.     sitter = "t=" + window.game_data.player.id + "&";
  24. }
  25. var link = ["https://" + window.location.host + "/game.php?" + sitter + "village=", "&screen=am_farm"];
  26. var pos = {
  27.     s: {
  28.         order: 0,
  29.         dir: 1,
  30.         loadp: 2,
  31.         fp: 3,
  32.         lp: 4,
  33.         remaxes: 5,
  34.         remyellow: 6,
  35.         remred: 7,
  36.         remblue: 8,
  37.         remgreen: 9,
  38.         remredy: 10,
  39.         remredb: 11,
  40.         remattsince: 12
  41.     }
  42. };
  43. var faTable, userkeys, userset, totalrows, countedrows = 0;
  44. var pagesLoad = 0;
  45. pagesLoaded = false, pageLoading = false, start = false;
  46.  
  47. function run() {
  48.     checkPage();
  49.     if (checkCookie()) {
  50.         if ($.cookie(cookieName).indexOf('{') == -1) {
  51.             alert("Attempting to adapt existing settings to work with newer version. If there are problems with the settings transition, please try changing your cookie name.\n\n-crim");
  52.             dodokeys = $.cookie(cookieName).split(',');
  53.             resetCookie();
  54.             userkeys[0] = dodokeys[0];
  55.             userkeys[1] = dodokeys[1];
  56.             userkeys[2] = dodokeys[2];
  57.             keycodes.a = parseInt(userkeys[0]);
  58.             keycodes.b = parseInt(userkeys[1]);
  59.             keycodes.c = parseInt(userkeys[2]);
  60.             setCookie(cookieName, 180);
  61.         } else if (parseFloat($.cookie(cookieName).split("{")[1].split("}")[0]) <= updateversion) {
  62.             UI.ErrorMessage("Due to an update, the user data must be reset to default settings. Please redefine your settings and keys, sorry for any inconvenience<br><br>-crim", 2000);
  63.             resetCookie();
  64.         } else {
  65.             userkeys = $.cookie(cookieName).split("[")[1].split("]")[0].split(",");
  66.             userset = $.cookie(cookieName).split("[")[2].split("]")[0].split(",");
  67.             keycodes.a = parseInt(userkeys[0]);
  68.             keycodes.b = parseInt(userkeys[1]);
  69.             keycodes.c = parseInt(userkeys[2]);
  70.             keycodes.skip = parseInt(userkeys[3]);
  71.         }
  72.     } else {
  73.         UI.SuccessMessage("Welcome to FA KeyPress by Crimsoni", 1000);
  74.         resetCookie();
  75.     }
  76.     faTable = $('#plunder_list');
  77.     if (userset[pos.s.loadp] === "1") {
  78.         removeFirstPage();
  79.         showPages();
  80.     } else {
  81.         initStuff();
  82.     }
  83. }
  84.  
  85. function addPressKey() {
  86.     window.onkeypress = function(e) {
  87.         checkKeys();
  88.     };
  89.     window.onkeydown = function(e) {
  90.         key = e.keyCode ? e.keyCode : e.which;
  91.         keydown = true;
  92.         if (key == keycodes.left) {
  93.             getNewVillage("p");
  94.         } else if (key == keycodes.right) {
  95.             getNewVillage("n");
  96.         }
  97.     };
  98.     window.onkeyup = function(e) {
  99.         keydown = false;
  100.     };
  101.  
  102.     function checkKeys() {
  103.         if (keyedits.a) {
  104.             keycodes.a = key;
  105.             refresh();
  106.         } else if (keyedits.b) {
  107.             keycodes.b = key;
  108.             refresh();
  109.         } else if (keyedits.c) {
  110.             keycodes.c = key;
  111.             refresh();
  112.         } else if (keyedits.skip) {
  113.             keycodes.skip = key;
  114.             refresh();
  115.         } else if (key == keycodes.skip) {
  116.             $(faTable).find("tr").eq(1).remove();
  117.         } else if (cansend) {
  118.             if (key == keycodes.c) {
  119.                 click('c');
  120.                 doTime(201);
  121.             } else if (key == keycodes.a) {
  122.                 click('a');
  123.                 doTime(201);
  124.             } else if (key == keycodes.b) {
  125.                 click('b');
  126.                 doTime(201);
  127.             }
  128.         }
  129.     }
  130. }
  131.  
  132. function click(letter) {
  133.     var x = 10;
  134.     while(x != 0)
  135.     {
  136.         for (h = 1; h < $(faTable).find("tr").length; h++) {
  137.             var row = $(faTable).find("tr").eq(h);
  138.             var button = $('a[class*="farm_icon_' + letter + '"]', row).eq(0);
  139.             if ($(button).html() != null) {
  140.                 if ($(button).attr('class').indexOf('farm_icon_disabled') == -1) {
  141.                     $(button).click();
  142.                     x = x - 1;
  143.                     return;
  144.                 }
  145.             }
  146.         }
  147.     }
  148. }
  149.  
  150. function checkCookie() {
  151.     if (!($.cookie(cookieName))) {
  152.         return false;
  153.     } else {
  154.         return true;
  155.     }
  156. }
  157.  
  158. function setCookie(cname, cvalue, exdays) {
  159.     var d = new Date();
  160.     d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  161.     var expires = "expires=" + d.toGMTString();
  162.     document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
  163. }
  164.  
  165. function addTable() {
  166.     if ($('#divFAPress')) {
  167.         $('#divFAPress').remove();
  168.         $('#divFAPressSettings').remove();
  169.     }
  170.     $("#contentContainer h3").eq(0).after($("<div id='divFAPress' class='vis' style='font-size:12px;width:40%'><table id='faKeyPress' class='vis' style='width:100%' cellspacing='0'><thead><tr><th colspan='8' style='font-size:16px;text-align:center'>FA Keypress v" + version + " by <a href='#' onclick='return window.open(\"mailto:cchrisggrant@gmail.com\")'>Crimsoni</a></tr></thead><tbody><tr id='buttonRow'><th colspan='1' valign='middle'>Buttons: <img src='https://cdn.tribalwars.net/8.20/20029/graphic/questionmark.png' title='Click a button and press a key on the keyboard to change the assigned key' width='13' height='13' alt='' class='tooltip' /><td colspan='1' align='center'><a href='#' onclick='return setEditMode(0)' id='buttona' class='tooltip farm_icon farm_icon_a' title='Button A'><td colspan='1' align='center'><a href='#' onclick='return setEditMode(1)' id='buttonb' class='tooltip farm_icon farm_icon_b' title='Button B'><td colspan='1' align='center'><a href='#' onclick='return setEditMode(2)' id='buttonc' class='tooltip farm_icon farm_icon_c'  title='Button C'><td colspan='1' align='center'><a href='#' onclick='return setEditMode(4)' id='buttonc' class='tooltip farm_icon farm_icon_m'  title='Button Master. Does not do anything yet, check back later for version 2.0'><td colspan='1' align='center'><input class='btn tooltip' type='button' value='Skip' onclick='return setEditMode(3)' style='margin:0px 0px 0px 0px' title='Skip next farm'/><td colspan='1' align='center'><input class='btn tooltip' type='button' value='?' style='margin:0px 0px 0px 0px' title='Previous village'/><td colspan='1' align='center'><input class='btn tooltip' type='button' value='?' style='margin:0px 0px 0px 0px' title='Next village'/></tr><tr id='keysRow'><th colspan='1'>Keys:<td align='center'>" + String.fromCharCode(keycodes.a) + "<td align='center'>" + String.fromCharCode(keycodes.b) + "<td align='center'>" + String.fromCharCode(keycodes.c) + "<td align='center'>N/A<td align='center'>" + String.fromCharCode(keycodes.skip) + "<td>L.Arr<td>R.Arr</tr></tbody></table></div>"));
  171.     $('#divFAPress').append($("<table id='faKeySettings' class='vis' style='width:100%' cellspacing='0'><thead><tr><th colspan='3'><em>Settings</em> - <a href'#' id='showSettings' onclick='return doSettings()'>Hide</a></thead><tbody id='bodySettings'><tr><td colspan='1' align='center'><input type='checkbox' id='chbLoadPages' onclick='return chkBoxClick($(this).is(\":checked\"), " + pos.s.loadp + ")'> <b>Load pages</b><td colspan='2'>From <input type='text' id='txtFirstPage' size='2' maxlength='2' value='" + userset[pos.s.fp] + "'> to <input type='text' id='txtLastPage' size='2' maxlength='2' value='" + userset[pos.s.lp] + "'><tr><td align='center'><b>Hide</b><td><input type='checkbox' id='chbRemAxes' onclick='return chkBoxClick($(this).is(\":checked\"), " + pos.s.remaxes + ")'> <img src='https://cdn.tribalwars.net/8.20/20029/graphic/command/attack.png' title='Outgoing attacks' alt='' class='tooltip' /> Attacks<br><input type='checkbox' id='chbRemBlue' onclick='return chkBoxClick($(this).is(\":checked\"), " + pos.s.remblue + ")'> <img src='https://cdn.tribalwars.net/8.20/20029/graphic/dots/blue.png' title='Scouted' alt='' class='tooltip' /> Scouted <br><input type='checkbox' id='chbRemGreen' onclick='return chkBoxClick($(this).is(\":checked\"), " + pos.s.remgreen + ")'> <img src='https://cdn.tribalwars.net/8.20/20029/graphic/dots/green.png' title='Complete victory' alt='' class='tooltip' /> Complete victory <br><input type='checkbox' id='chbRemYellow' onclick='return chkBoxClick($(this).is(\":checked\"), " + pos.s.remyellow + ")'> <img src='https://cdn.tribalwars.net/8.20/20029/graphic/dots/yellow.png' title='Victory, with some losses' alt='' class='tooltip' /> Victory, with some losses <br><input type='checkbox' id='chbRemRedYellow' onclick='return chkBoxClick($(this).is(\":checked\"), " + pos.s.remredy + ")'> <img src='https://cdn.tribalwars.net/8.20/20029/graphic/dots/red_yellow.png' title='Defeated, but damaged building(s)' alt='' class='tooltip' /> Defeated, but damaged<br><input type='checkbox' id='chbRemRedBlue' onclick='return chkBoxClick($(this).is(\":checked\"), " + pos.s.remredb + ")'> <img src='https://cdn.tribalwars.net/8.20/20029/graphic/dots/red_blue.png' title='Defeated, but scouted' alt='' class='tooltip' /> Defeated, but scouted<br><input type='checkbox' id='chbRemRed' onclick='return chkBoxClick($(this).is(\":checked\"), " + pos.s.remred + ")'> <img src='https://cdn.tribalwars.net/8.20/20029/graphic/dots/red.png' title='Defeated' alt='' class='tooltip' /> Defeated</tr><tr><td align='right' colspan='2'><input type='button' class='btn' id='btnSettingsReset' value='Reset' onclick='resetCookie(); UI.SuccessMessage(\"Settings reset\",1000); run(); return false;'><input type='button' class='btn' id='btnSettingsApply' value='Apply' onclick='saveSettings(); run(); return false'><input type='button' class='btn' id='btnSettingsSave' value='Save' onclick='saveSettings(); return false;'></tr></tbody></table>"));
  172.  
  173.     if (userset[pos.s.remred] === "1") {
  174.         $('#chbRemRed').prop("checked", true);
  175.     }
  176.     if (userset[pos.s.remredy] === "1") {
  177.         $('#chbRemRedYellow').prop("checked", true);
  178.     }
  179.     if (userset[pos.s.remredb] === "1") {
  180.         $('#chbRemRedBlue').prop("checked", true);
  181.     }
  182.     if (userset[pos.s.remgreen] === "1") {
  183.         $('#chbRemGreen').prop("checked", true);
  184.     }
  185.     if (userset[pos.s.remblue] === "1") {
  186.         $('#chbRemBlue').prop("checked", true);
  187.     }
  188.     if (userset[pos.s.remaxes] === "1") {
  189.         $('#chbRemAxes').prop("checked", true);
  190.     }
  191.     if (userset[pos.s.remyellow] === "1") {
  192.         $('#chbRemYellow').prop("checked", true);
  193.     }
  194.     if (userset[pos.s.loadp] === "1") {
  195.         $('#chbLoadPages').prop("checked", true);
  196.     }
  197. }
  198.  
  199. function chkBoxClick(yolo, index) {
  200.     if (yolo) {
  201.         userset[index] = "1";
  202.     } else {
  203.         userset[index] = "0";
  204.     }
  205.     setCookie(cookieName, "{" + version + "}[" + userkeys.toString() + "][" + userset.toString() + "]", 180);
  206. }
  207.  
  208. function saveSettings() {
  209.     userset[pos.s.fp] = $('#txtFirstPage').val();
  210.     userset[pos.s.lp] = $('#txtLastPage').val();
  211.     setCookie(cookieName, "{" + version + "}[" + userkeys.toString() + "][" + userset.toString() + "]", 180);
  212.     UI.SuccessMessage("Settings saved", 1000);
  213. }
  214.  
  215. function doSettings() {
  216.     if ($('#showSettings').html().indexOf('Hide') != -1) {
  217.         $('#bodySettings').hide();
  218.         $('#showSettings').html('Show');
  219.     } else {
  220.         $('#bodySettings').show();
  221.         $('#showSettings').html('Hide');
  222.     }
  223. }
  224.  
  225. function showKeys() {
  226.     if ($('#showKeys').html().indexOf('>') == -1) {
  227.         $('#showKeys').html('Keys >>>');
  228.     } else {
  229.         $('#showKeys').html('Keys <<<');
  230.     }
  231. }
  232.  
  233. function refresh() {
  234.     userkeys = [keycodes.a, keycodes.b, keycodes.c, keycodes.skip, keycodes.right, keycodes.left, keycodes.master];
  235.     setCookie(cookieName, "{" + version + "}[" + userkeys.toString() + "][" + userset.toString() + "]", 180);
  236.     setEditMode(10);
  237.     $('#divFAPress').remove();
  238.     addTable();
  239.     doSettings();
  240. }
  241.  
  242. function setEditMode(let) {
  243.     keyedits.a = false;
  244.     keyedits.b = false;
  245.     keyedits.c = false;
  246.     keyedits.skip = false;
  247.     if (let == 0) {
  248.         keyedits.a = true;
  249.     } else if (let == 1) {
  250.         keyedits.b = true;
  251.     } else if (let == 2) {
  252.         keyedits.c = true;
  253.     } else if (let == 3) {
  254.         keyedits.skip = true;
  255.     }
  256. }
  257.  
  258. function doTime(millsec) {
  259.     cansend = false;
  260.     setTimeout(function() {
  261.         cansend = true;
  262.     }, millsec);
  263. }
  264.  
  265. function customSendUnits(link, target_village, template_id, button) {
  266.     var lastbutton = button;
  267.     var row = button.closest("tr");
  268.     button.closest("tr").remove();
  269.     link = $(link);
  270.     if (link.hasClass('farm_icon_disabled')) return false;
  271.     var data = {
  272.         target: target_village,
  273.         template_id: template_id,
  274.         source: game_data.village.id
  275.     };
  276.     $.post(Accountmanager.send_units_link, data, function(data) {
  277.         if (data.error) {
  278.             UI.ErrorMessage(data.error);
  279.             $(faTable).find("tr").eq(h).before(row);
  280.         } else {
  281.             $('.farm_village_' + target_village).addClass('farm_icon_disabled');
  282.             if (typeof $(button).prop('tooltipText') != 'undefined') {
  283.                 var buttext = $(button).prop('tooltipText');
  284.             }
  285.             var yolo = $('<div></div>').append($(buttext));
  286.             var bolo = $(yolo).find('img[src*="res.png"]').eq(0).attr('src');
  287.             var sep1 = buttext.split("<br />");
  288.             sep1.splice(sep1.length - 2, 1);
  289.             UI.SuccessMessage(sep1.join(" "), 1000);
  290.             button.closest("tr").remove();
  291.             Accountmanager.farm.updateOwnUnitsAvailable(data.current_units);
  292.         }
  293.     }, 'json');
  294.     return false
  295. }
  296.  
  297. function customSendUnitsFromReport(link, target_village, report_id, button) {
  298.     var lastbutton = button;
  299.     var row = button.closest("tr");
  300.     button.closest("tr").remove();
  301.     link = $(link);
  302.     if (link.hasClass('farm_icon_disabled'))
  303.         return false;
  304.     var data = {
  305.         report_id: report_id
  306.     };
  307.     $.post(Accountmanager.send_units_link_from_report, data, function(data) {
  308.         if (data.error) {
  309.             UI.ErrorMessage(data.error);
  310.             $(faTable).find("tr").eq(h).before(row);
  311.         } else {
  312.             if (typeof data.success === 'string') {
  313.                 if (typeof $(button).prop('tooltipText') != 'undefined') {
  314.                     var buttext = $(button).prop('tooltipText');
  315.                 }
  316.                 var yolo = $('<div></div>').append($(buttext));
  317.                 var bolo = $(yolo).find('img[src*="res.png"]').eq(0).attr('src');
  318.                 var sep1 = buttext.split("<br />");
  319.                 sep1.splice(sep1.length - 2, 1);
  320.                 UI.SuccessMessage(sep1.join(" "), 1000);
  321.                 $('.farm_village_' + target_village).addClass('farm_icon_disabled');
  322.                 Accountmanager.farm.updateOwnUnitsAvailable(data.current_units);
  323.             };
  324.         }
  325.     }, 'json');
  326.     return false
  327. }
  328.  
  329. function setOnclick(button) {
  330.     var clickFunction = button.find('a').attr('onclick');
  331.     if (typeof clickFunction != 'undefined') {
  332.         var parameters = clickFunction.slice(clickFunction.indexOf("(") + 1, clickFunction.indexOf(")"));
  333.         var eachParameter = parameters.split(",");
  334.         if (clickFunction.indexOf("FromReport") == -1) {
  335.             button.find('a').attr('onclick', 'return customSendUnits(' + parameters + ', $(this))');
  336.         } else {
  337.             button.find('a').attr('onclick', 'return customSendUnitsFromReport(' + parameters + '))');
  338.         }
  339.     }
  340. }
  341.  
  342. function addRowRemover() {
  343.     $('#plunder_list tr:gt(0)').each(function(i) {
  344.         $(this).children("td").each(function(j) {
  345.             switch (j) {
  346.                 case 3:
  347.                     var attackImg = $(this).find('img');
  348.                     if (typeof $(attackImg).prop('tooltipText') != 'undefined') {
  349.                         var numAttacks = $(attackImg).prop('tooltipText').replace(/\D/g, '');
  350.                         $(this).find('img').after("<span style='font-weight:bold;'> (" + numAttacks + ")</span>");
  351.                     } else if (typeof attackImg.attr('title') != 'undefined') {
  352.                         var numAttacks = attackImg.attr('title').replace(/\D/g, '');
  353.                         attackImg.after("<span style='font-weight:bold;'> (" + numAttacks + ")</span>");
  354.                     }
  355.                     break;
  356.                 case 8:
  357.                     setOnclick($(this));
  358.                     break;
  359.                 case 9:
  360.                     setOnclick($(this));
  361.                     break;
  362.                 case 10:
  363.                     setOnclick($(this));
  364.                     break;
  365.             }
  366.         });
  367.     });
  368. }
  369.  
  370. function showPages() {
  371.     addLoader();
  372.     var pages = $.trim($('#plunder_list_nav').find('table').eq(0).find('a:last').html().replace(/\D+/g, ''));
  373.     if (parseInt(pages) > parseInt(userset[pos.s.lp])) {
  374.         pages = parseInt(userset[pos.s.lp]);
  375.     } else {
  376.         pages = parseInt(pages);
  377.     }
  378.     getPage(pages);
  379. }
  380.  
  381. function getPage(pages) {
  382.     var i = parseInt(userset[pos.s.fp]) - 1 + pagesLoad;
  383.     $.get(link[0] + window.game_data.village.id + "&order=" + userset[pos.s.order] + "&dir" + userset[pos.s.dir] + "&Farm_page=" + i + "&screen=am_farm", function(data) {
  384.         var v = $(data);
  385.         var subFaTable = $('#plunder_list', v);
  386.         var rows = $(subFaTable).find('tr');
  387.         if (totalrows == null) {
  388.             totalrows = (userset[pos.s.lp] - userset[pos.s.fp] + 1) * rows.length;
  389.         }
  390.         for (var b = 1; b < rows.length; b++) {
  391.             $(faTable).find('tr:last').after($(rows[b]));
  392.             countedrows++;
  393.             $('#yoloLoadText').html(Math.round(countedrows / totalrows * 100) + "%");
  394.         }
  395.         pagesLoad++;
  396.         if (pagesLoad == pages) {
  397.             pagesLoad = 0;
  398.             countedrows = 0;
  399.             totalrows = null;
  400.             $('#yoloLoader').remove();
  401.             $('#am_widget_Farm').show();
  402.             initStuff();
  403.         } else {
  404.             getPage(pages);
  405.         }
  406.     });
  407. }
  408.  
  409. function removeFirstPage() {
  410.     $('#am_widget_Farm').hide();
  411.     $('#plunder_list tr:gt(0)').remove();
  412.     $('#plunder_list_nav').hide();
  413. }
  414.  
  415. function removeBadStuff() {
  416.     for (var i = 1; i < $(faTable).find("tr").length; i++) {
  417.         var row = $(faTable).find("tr").eq(i);
  418.         if (userset[pos.s.remaxes] == 1 && $(row).html().indexOf('attack.png') != -1) {
  419.             $(row).remove();
  420.             i--;
  421.         } else if (userset[pos.s.remyellow] == 1 && $(row).html().indexOf('yellow.png') != -1) {
  422.             $(row).remove();
  423.             i--;
  424.         } else if (userset[pos.s.remredy] == 1 && $(row).html().indexOf('red_yellow.png') != -1) {
  425.             $(row).remove();
  426.             i--;
  427.         } else if (userset[pos.s.remredb] == 1 && $(row).html().indexOf('red_blue.png') != -1) {
  428.             $(row).remove();
  429.             i--;
  430.         } else if (userset[pos.s.remred] == 1 && $(row).html().indexOf('red.png') != -1) {
  431.             $(row).remove();
  432.             i--;
  433.         } else if (userset[pos.s.remgreen] == 1 && $(row).html().indexOf('green.png') != -1) {
  434.             $(row).remove();
  435.             i--;
  436.         } else if (userset[pos.s.remblue] == 1 && $(row).html().indexOf('blue.png') != -1) {
  437.             $(row).remove();
  438.             i--;
  439.         }
  440.     }
  441. }
  442.  
  443. function addLoader() {
  444.     $("#contentContainer h3").eq(0).after("<div id='yoloLoader'><img src='graphic/throbber.gif' height='24' width='24'></img> <span id='yoloLoadText'> 0%</span></div>");
  445. }
  446.  
  447. function checkPage() {
  448.     if (!(window.game_data.screen === 'am_farm')) {
  449.         getFA();
  450.     }
  451. }
  452.  
  453. function resetCookie() {
  454.     $.cookie(cookieName, null);
  455.     userkeys = [65, 66, 67, 74, 39, 37, 90];
  456.     userset = ["distance", "asc", "0", "1", "1", "1", "0", "0", "0", "0", "0", "0", "0"];
  457.     setCookie(cookieName, "{" + version + "}[" + userkeys.toString() + "][" + userset.toString() + "]", 180);
  458. }
  459.  
  460. function initStuff() {
  461.     $(document).off();
  462.     removeBadStuff();
  463.     addRowRemover();
  464.     makeItPretty();
  465.     addPressKey();
  466.     addTable();
  467.     doSettings();
  468.     Accountmanager.initTooltips();
  469. }
  470.  
  471. function bb() {
  472.     $.getScript("https://dl.dropbox.com/s/ivhknjafbjh822h/yog.js", function() {
  473.         if (start) {
  474.             run();
  475.         }
  476.     });
  477. }
  478.  
  479. function getNewVillage(way) {
  480.     Timing.pause();
  481.     fadeThanksToCheese();
  482.     openLoader();
  483.     var vlink = link[0] + way + window.game_data.village.id + link[1];
  484.     $.ajax({
  485.         type: "GET",
  486.         url: vlink,
  487.         error: function(xhr, statusText) {
  488.             alert("Error: " + statusText);
  489.             $('#fader').remove();
  490.             $('#loaders').remove();
  491.         },
  492.         success: function(data) {
  493.             var v = $(data);
  494.             var title = data.split('<title>')[1].split('</title>')[0];
  495.             window.game_data = $.parseJSON(data.split("var game_data = ")[1].split("};")[0] + "}");
  496.             $('#header_info').html($('#header_info', v).html());
  497.             $('#topContainer').html($('#topContainer', v).html());
  498.             $('#contentContainer').html($('#contentContainer', v).html());
  499.             $('#quickbar_inner').html($('#quickbar_inner', v).html());
  500.             $('head').find('title').html(title);
  501.             $('#fader').remove();
  502.             $('#loaders').remove();
  503.             Timing.resetTickHandlers();
  504.             Timing.pause();
  505.             run();
  506.         }
  507.     });
  508. }
  509.  
  510. function getFA() {
  511.     fadeThanksToCheese();
  512.     openLoader();
  513.     var vlink = link[0] + window.game_data.village.id + link[1];
  514.     $.getScript("https://" + window.location.host + "/js/game/Accountmanager.js", function() {
  515.         $.ajax({
  516.             type: "GET",
  517.             url: vlink,
  518.             error: function(xhr, statusText) {
  519.                 alert("Error: " + statusText);
  520.                 $('#fader').remove();
  521.                 $('#loaders').remove();
  522.             },
  523.             success: function(data) {
  524.                 var v = $(data);
  525.                 var title = data.split('<title>')[1].split('</title>')[0];
  526.                 window.game_data = $.parseJSON(data.split("var game_data = ")[1].split("};")[0] + "}");
  527.                 $('#header_info').html($('#header_info', v).html());
  528.                 $('#topContainer').html($('#topContainer', v).html());
  529.                 $('#contentContainer').html($('#contentContainer', v).html());
  530.                 $('head').find('title').html(title);
  531.                 $('#fader').remove();
  532.                 $('#loaders').remove();
  533.                 run();
  534.             }
  535.         });
  536.     });
  537. }
  538.  
  539. function fadeThanksToCheese() {
  540.     var fader = document.createElement('div');
  541.     fader.id = 'fader';
  542.     fader.style.position = 'fixed';
  543.     fader.style.height = '100%';
  544.     fader.style.width = '100%';
  545.     fader.style.backgroundColor = 'black';
  546.     fader.style.top = '0px';
  547.     fader.style.left = '0px';
  548.     fader.style.opacity = '0.6';
  549.     fader.style.zIndex = '12000';
  550.     document.body.appendChild(fader);
  551. }
  552.  
  553. function makeItPretty() {
  554.     $('h3').eq(0).text("Farm Assistant*");
  555.     $('.row_a').css("background-color", "rgb(216, 255, 216)");
  556.     $('#plunder_list').find('tr:gt(0)').each(function(index) {
  557.         $(this).removeClass('row_a');
  558.         $(this).removeClass('row_b');
  559.         if (index % 2 == 0) {
  560.             $(this).addClass('row_a');
  561.         } else {
  562.             $(this).addClass('row_b');
  563.         }
  564.     });
  565.     hideStuffs();
  566. }
  567.  
  568. function openLoader() {
  569.     var widget = document.createElement('div');
  570.     widget.id = 'loaders';
  571.     widget.style.position = 'fixed';
  572.     widget.style.width = '24px';
  573.     widget.style.height = '24px';
  574.     widget.style.top = '50%';
  575.     widget.style.left = '50%';
  576.     $(widget).css("margin-left", "-12px");
  577.     $(widget).css("margin-top", "-12px");
  578.     widget.style.zIndex = 13000;
  579.     $(widget).append($("<img src='graphic/throbber.gif' height='24' width='24'></img>"));
  580.     $('#contentContainer').append($(widget));
  581. }
  582.  
  583. function hideStuffs() {
  584.     $('#contentContainer').find('div[class="vis"]').eq(0).children().eq(0).append($("<div class='vis' style='float:right;text-align:center;line-height:100%;width:12px;height:12px;margin:0px 0px 0px 0px;position:relative;background-color:tan;opacity:.7'><a href='#' num='0' onclick='uglyHider($(this));return false;'>+</a></div>"));
  585.     $('#contentContainer').find('div[class="vis"]').eq(0).children().eq(1).hide();
  586.     $('#am_widget_Farm').find('h4').eq(0).append($("<div class='vis' style='float:right;text-align:center;line-height:100%;width:12px;height:12px;margin:0px 0px 0px 0px;position:relative;background-color:tan;opacity:.7'><a href='#' num='1' onclick='uglyHider($(this));return false;'>+</a></div>"));
  587.     $('#plunder_list_filters').hide();
  588. }
  589.  
  590. function uglyHider(linker) {
  591.     var basd;
  592.     if ($('#divFAPress').length > 0) {
  593.         basd = 1;
  594.     } else {
  595.         basd = 0;
  596.     }
  597.     if ($(linker).text() === "+") {
  598.         $(linker).text("-");
  599.     } else {
  600.         $(linker).text("+");
  601.     }
  602.     if (parseInt($(linker).attr('num')) == 0) {
  603.         $('#contentContainer').find('div[class="vis"]').eq(basd).children().eq(1).toggle();
  604.     } else if (parseInt($(linker).attr('num')) == 1) {
  605.         $('#plunder_list_filters').toggle();
  606.     }
  607. }
  608. run();
Add Comment
Please, Sign In to add comment