op8867555

rocas.moded

Apr 12th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //---------------------------------------------------------------------------
  2. // v1.0.3
  3. // 参考Bronie FPeD http://userscripts.org/scripts/review/70450
  4. //---------------------------------------------------------------------------
  5. var $j = jQuery.noConflict();
  6. var currURL = location.href;
  7. var rank = {
  8.     Recruit: 1,
  9.     Private: 2,
  10.     'Private *': 3,
  11.     'Private **': 4,
  12.     'Private ***': 5,
  13.     Corporal: 6,
  14.     'Corporal *': 7,
  15.     'Corporal **': 8,
  16.     'Corporal ***': 9,
  17.     Sergeant: 10,
  18.     'Sergeant *': 11,
  19.     'Sergeant **': 12,
  20.     'Sergeant ***': 13,
  21.     Lieutenant: 14,
  22.     'Lieutenant *': 15,
  23.     'Lieutenant **': 16,
  24.     'Lieutenant ***': 17,
  25.     Captain: 18,
  26.     'Captain *': 19,
  27.     'Captain **': 20,
  28.     'Captain ***': 21,
  29.     Major: 22,
  30.     'Major *': 23,
  31.     'Major **': 24,
  32.     'Major ***': 25,
  33.     Commander: 26,
  34.     'Commander *': 27,
  35.     'Commander **': 28,
  36.     'Commander ***': 29,
  37.     'Lt Colonel': 30,
  38.     'Lt Colonel *': 31,
  39.     'Lt Colonel **': 32,
  40.     'Lt Colonel ***': 33,
  41.     Colonel: 34,
  42.     'Colonel *': 35,
  43.     'Colonel **': 36,
  44.     'Colonel ***': 37,
  45.     General: 38,
  46.     'General *': 39,
  47.     'General **': 40,
  48.     'General ***': 41,
  49.     'Field Marshal': 42,
  50.     'Field Marshal *': 43,
  51.     'Field Marshal **': 44,
  52.     'Field Marshal ***': 45,
  53.     'Supreme Marshal': 46,
  54.     'Supreme Marshal *': 47,
  55.     'Supreme Marshal **': 48,
  56.     'Supreme Marshal ***': 49,
  57.     'National Force': 50,
  58.     'National Force *': 51,
  59.     'National Force **': 52,
  60.     'National Force ***': 53,
  61.     'World Class Force': 54,
  62.     'World Class Force *': 55,
  63.     'World Class Force **': 56,
  64.     'World Class Force ***': 57,
  65.     'Legendary Force': 58,
  66.     'Legendary Force *': 59,
  67.     'Legendary Force **': 60,
  68.     'Legendary Force ***': 61,
  69.     'God of War': 62,
  70.     'God of War *': 63,
  71.     'God of War **': 64,
  72.     'God of War ***': 65
  73. };
  74. var ccode = {
  75.     Argentina: 'ARG',
  76.     Venezuela: 'VEN',
  77.     'United Kingdom': 'UK',
  78.     Switzerland: 'CH',
  79.     Netherlands: 'NL',
  80.     'Czech Republic': 'Czech',
  81.     'South Korea': 'SK',
  82.     Indonesia: 'IND',
  83.     Australia: 'AUS',
  84.     'South Africa': 'ZA',
  85.     'Republic of Moldova': 'Moldova',
  86.     Philippines: 'PH',
  87.     Singapore: 'SGP',
  88.     'Bosnia and Herzegovina': 'BIH',
  89.     Lithuania: 'LT',
  90.     'North Korea': 'NK',
  91.     'Republic of Macedonia (FYROM)': 'MKD',
  92.     Montenegro: 'MNE',
  93.     'Republic of China (Taiwan)': 'ROC',
  94.     'New Zealand': 'NZ',
  95.     'Saudi Arabia': 'SA',
  96.     'United Arab Emirates': 'UAE'
  97. };
  98.  
  99. function dmgCalc(militaryRank, strength, weaponPower, fights, bonus) {
  100.     var damage = Math.floor((militaryRank + 5) * (strength + 400) * 0.005 * (1 + weaponPower * 0.01));
  101.     return Math.floor(damage * bonus) * fights;
  102. }
  103.  
  104. function str_replace(haystack, needle, replacement) {
  105.     var temp = haystack.split(needle);
  106.     return temp.join(replacement);
  107. }
  108.  
  109. function add_inf() {
  110.     var content = $j('#content'),
  111.         str,
  112.         mRank = content.find('div.citizen_military:eq(1)').find('a').text().trim();
  113.     str = content.find('div.citizen_military:eq(0)').find('h4').text().trim();
  114.     str = parseFloat(str_replace(str, ',', ''));
  115.  
  116.     content.find('div.citizen_military:last').after('<h3>Influence</h3><table border="0" width="100%" class="details"><thead><tr><th>Weapons</th><th>None</th><th>Q1</th><th>Q2</th><th>Q3</th><th>Q4</th><th>Q5</th><th>Q6</th></tr></thead><tbody><tr class="current"><td class="skill"><span class="skiller">Influence</span></td><td class="stat">' +
  117.         dmgCalc(rank[mRank], str, 0, 1, 1) + '</td><td class="stat">' +
  118.         dmgCalc(rank[mRank], str, 20, 1, 1) + '</td><td class="stat">' +
  119.         dmgCalc(rank[mRank], str, 40, 1, 1) + '</td><td class="stat">' +
  120.         dmgCalc(rank[mRank], str, 60, 1, 1) + '</td><td class="stat">' +
  121.         dmgCalc(rank[mRank], str, 80, 1, 1) + '</td><td class="stat">' +
  122.         dmgCalc(rank[mRank], str, 100, 1, 1) + '</td><td class="stat">' +
  123.         dmgCalc(rank[mRank], str, 120, 1, 1) + '</td></tr></tbody></table><div class="clear"></div><h3>Influence Calculator<span style="float:right">Weapons: <select id="dmgWeapon" size="1"><option value="0">None</option><option value="20">Q1</option><option value="40">Q2</option><option value="60">Q3</option><option value="80">Q4</option><option value="100">Q5</option><option value="120" selected="selected">Q6</option></select>&nbsp;&nbsp;&nbsp;&nbsp;Fights: <input id="dmgFights" name="dmgFights" value="65" size="4" maxlength="4" /></span></h3><div class="citizen_military" style="margin-bottom:2px"><div id="dmgResults"><strong>Total influence: </strong><h4 style="margin-left:10px">' +
  124.         dmgCalc(rank[mRank], str, 120, 65, 1) + '</h4><div class="stat"><small>With NE bonus: <strong><span style="font-size:12px">' +
  125.         dmgCalc(rank[mRank], str, 120, 65, 1.1) + '</span></strong></small></div></div></div>'
  126.         );
  127.  
  128.     $j('#dmgFights').keyup(function () {
  129.         var fights = $j('#dmgFights').val(),
  130.             weaponPower = $j('#dmgWeapon').val();
  131.         $j('#dmgResults').html('<strong>Total influence: </strong><h4 style="margin-left:10px">' +
  132.             dmgCalc(rank[mRank], str, weaponPower, fights, 1) + '</h4><div class="stat"><small>With NE bonus: <strong><span style="font-size:12px">' +
  133.             dmgCalc(rank[mRank], str, weaponPower, fights, 1.1) + '</span></strong></small></div>'
  134.             );
  135.     });
  136.  
  137.     $j('#dmgWeapon').change(function () {
  138.         $j('#dmgFights').keyup();
  139.     });
  140. }
  141.  
  142. function add_news() {
  143.     $j('#articles').find('a:first').before('<a href="/en/news/latest/all/China/1" class="mbutton"><img src="http://www.erepublik.com/images/flags/S/China.gif" alt="" /><span>Latest news of eChina</span></a>' +
  144.         '<a href="/en/newspaper/ministry-of-sinodefence-196717/1" class="mbutton"><img src="http://www.erepublik.com/images/flags/S/China.gif" alt="" /><span>Daily Order of SinoDefence</span></a>'
  145.         );
  146. }
  147.  
  148. function dmgMilitary(bonus) {
  149.     var str,
  150.         mRank = $j('#rank_icon').attr('title');
  151.     str = $j('#fighter_skill').text().trim();
  152.     str = parseFloat(str_replace(str, ',', ''));
  153.     if (typeof mRank == 'undefined' || mRank.length == 0) {
  154.         mRank = $j('#rank_icon').attr('original-title').substr(15).trim();
  155.     } else {
  156.         mRank = mRank.substr(15).trim();
  157.     }
  158.     return dmgCalc(rank[mRank], str, 120, 1, bonus);
  159. }
  160.  
  161. function sortStats(a, b) {
  162.     var ta = a.split('_'),
  163.         tb = b.split('_');
  164.     if (parseInt(ta[1], 10) == parseInt(tb[1], 10)) {
  165.         return parseInt(ta[2], 10) - parseInt(tb[2], 10);
  166.     } else {
  167.         return parseInt(ta[1], 10) - parseInt(tb[1], 10);
  168.     }
  169. }
  170.  
  171. function getKey() {
  172.     var i, len, tmp,
  173.         key = [];
  174.     for (i = 0, len = localStorage.length; i < len; i++) {
  175.         tmp = localStorage.key(i);
  176.         if (tmp.charAt(0) != '@') {
  177.             continue;
  178.         }
  179.         key.push(tmp);
  180.     }
  181.     key.sort(sortStats);
  182.     return key;
  183. }
  184.  
  185. function showStats() {
  186.     var tmp, value, i, len,
  187.         stats = [],
  188.         stats_table = $j('#stats_table'),
  189.         tstats = '',
  190.         cmcInf = 0,
  191.         cmcFight = 0,
  192.         eliteInf = 0,
  193.         eliteFight = 0,
  194.         key = getKey();
  195.     stats.push('<tr><th>戰場</th><th>總影響力</th><th></th></tr>');
  196.     for (i = 0, len = key.length; i < len; i++) {
  197.         value = localStorage.getItem(key[i]).split('_');
  198.         tmp = key[i].split('_');
  199.         if (tmp[0].length == 1) {
  200.             cmcFight += parseInt(value[0], 10);
  201.             cmcInf += parseInt(value[1], 10);
  202.             stats.push('<tr><td>' + tmp[1] + '_'  + tmp[2] + '_' + value[0] + '</td><td>' + value[1] + '</td><td><a href="javascript:;" class="delete_stat" id="' + key[i] + '">X</a></td></tr>');
  203.         } else {
  204.             eliteFight += parseInt(value[0], 10);
  205.             eliteInf += parseInt(value[1], 10);
  206.             stats.push('<tr style="background-color:LightGreen;"><td>' + tmp[1] + '_'  + tmp[2] + '_' + value[0] + '</td><td>' + value[1] + '</td><td><a href="javascript:;" class="delete_stat" id="' + key[i] + '">X</a></td></tr>');
  207.         }
  208.     }
  209.     if (stats.length == 1) {
  210.         stats = '';
  211.     } else {
  212.         stats = stats.join('');
  213.     }
  214.     stats_table.html(stats);
  215.     stats_table.find('th').css({'border': '1px solid gray', 'padding': '2px'});
  216.     stats_table.find('td').css({'border': '1px solid gray', 'padding': '1px'});
  217.     if (cmcInf > 0) {
  218.         tstats += '<tr><td>ROCAS 總影響力</td><td>' + cmcInf + '</td></tr><tr><td>ROCAS Q6攻擊次數</td><td>' + cmcFight + '</td></tr>';
  219.     }
  220.     if (eliteInf > 0) {
  221.         tstats += '<tr><td>Elite 總影響力</td><td>' + eliteInf + '</td></tr><tr><td>Elite Q6攻擊次數</td><td>' + eliteFight + '</td></tr>';
  222.     }
  223.     if (cmcInf == 0 && eliteInf == 0) {
  224.         tstats = '<tr><td style="text-align:center;font-weight:bold;"><a href="http://eroc.no-ip.org/php/upload/forum.php?mod=viewthread&tid=8#lastpost" target="_blank">ROCAS 申報插件 v1.0.0</a></td></tr>';
  225.     }
  226.     $j('#tstats_table').html(tstats);
  227.     stats_table.find('tr:gt(0)').click(function () {
  228.         var key = $j(this).find('a.delete_stat').attr('id'),
  229.             value = localStorage.getItem(key),
  230.             tmp = key.split('_');
  231.         localStorage.removeItem(key);
  232.         if (tmp[0].length == 1) {
  233.             localStorage.setItem('@' + key, value);
  234.         } else {
  235.             key = key.substr(1);
  236.             localStorage.setItem(key, value);
  237.         }
  238.         $j('#clear_btn').css('display', 'none');
  239.         $j('#gen_txt').css('display', 'none');
  240.         $j('#stats_report').html('');
  241.         showStats();
  242.     });
  243.     stats_table.find('a.delete_stat').click(function () {
  244.         localStorage.removeItem($j(this).attr('id'));
  245.         $j('#clear_btn').css('display', 'none');
  246.         $j('#gen_txt').css('display', 'none');
  247.         $j('#stats_report').html('');
  248.         showStats();
  249.     });
  250. }
  251.  
  252. function add_fight() {
  253.     var battleId = currURL.substr(49),
  254.         leftCrowns = $j('#popup_left_crowns').attr('crowns'),
  255.         rightCrowns = $j('#popup_right_crowns').attr('crowns'),
  256.         zoneId = parseInt(leftCrowns, 10) + parseInt(rightCrowns, 10) + 1,
  257.         leftSide = $j('#pvp_header').find('h3:first').html(),
  258.         totalDmg = parseInt($j('#total_damage').find('strong').text().replace(/\s/g, ''), 10),
  259.         dmg = dmgMilitary(1),
  260.         neDmg = dmgMilitary(1.1),
  261.         initFight,
  262.         scriptNode = document.createElement('script'),
  263.         text = [];
  264.     if (leftSide.indexOf('Resistance') != -1) {
  265.         leftSide = leftSide.substr(20);
  266.     }
  267.     if (leftSide.length > 8) {
  268.         leftSide = ccode[leftSide];
  269.     }
  270.     if (localStorage.getItem('ne') != null && localStorage.getItem('ne') == battleId) {
  271.         initFight = Math.round(totalDmg / neDmg);
  272.     } else if (totalDmg % dmg != 0 && totalDmg % neDmg == 0) {
  273.         initFight = Math.round(totalDmg / neDmg);
  274.     } else {
  275.         initFight = Math.round(totalDmg / dmg);
  276.     }
  277.     $j('#pvp_battle_area').find('table.damage_aligner').find('td').after(
  278.         '<td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><div id="total_f" style="width:auto;height:25px;display:block;cursor:default;"><small style="font-size:11px;color:#fff;float:left;text-shadow:#333 0px 1px 1px;display:block;height:25px;opacity:0.7;-moz-opacity:0.7;-ms-fiter:' + "'progid:DXImageTransform.Microsoft.Alpha(Opacity=70)'" + ';filter:alpha(opacity=70);line-height:25px;font-weight:bold;padding:0 5px;background-image:url(' + "'/images/modules/pvp/influence_left.png?1321873582'" + ');background-position:left;">' + battleId + '_' + zoneId + '_' + leftSide + '</small><strong style="color:#fff;text-shadow:#014471 0px 1px 0px;float:left;display:block;height:25px;font-size:12px;line-height:25px;padding:0 5px;background-image:url(' + "'/images/modules/pvp/influence_right.png?1321873582'" + ');background-position:right;">' + initFight + '</strong></div></td>'
  279.     );
  280.     function localMain() {
  281.         //remove ScrollToFixed
  282.         $j(document).ready(function () {
  283.             $j(window).load(function () {
  284.                 var tmp = $j('#large_sidebar').next();
  285.                 if (typeof tmp.attr('id') == 'undefined' || !tmp.attr('id').length) {
  286.                     tmp.remove();
  287.                 }
  288.                 $j('#large_sidebar').css({'width' : '', 'position' : '', 'left' : '', 'top' : ''});
  289.                 $j(window).unbind('resize');
  290.                 $j(window).unbind('scroll');
  291.             });
  292.         });
  293.         //update totalDmg
  294.         $j('#total_f').ajaxSuccess(function (e, xhr, settings) {
  295.             if (settings.url.indexOf('fight') == -1) {
  296.                 return;
  297.             }
  298.             var fight = parseInt($j(this).find('strong').html(), 10),
  299.                 key,
  300.                 response = JSON.parse(xhr.responseText),
  301.                 user = response.user;
  302.             if (response.error) {
  303.                 return;
  304.             }
  305.             if (response.message === 'ENEMY_KILLED') {
  306.                 totalDmg += user.givenDamage;
  307.                 if (response.oldEnemy.isNatural === true) {
  308.                     localStorage.setItem('ne', location.href.substr(49));
  309.                     totalDmg += Math.floor(user.givenDamage * 0.1);
  310.                     fight = Math.round(totalDmg / dmgMilitary(1.1));
  311.                 } else {
  312.                     fight = Math.round(totalDmg / dmgMilitary(1));
  313.                 }
  314.                 $j(this).find('strong').html(fight);
  315.                 key = $j(this).find('small').text().trim().split('_', 2);
  316.                 key = '@_' + key[0] + '_' + key[1];
  317.                 if (localStorage.getItem(key) == null) {
  318.                     key = '@' + key;
  319.                     if (localStorage.getItem(key) == null) {
  320.                         return;
  321.                     }
  322.                 }
  323.                 localStorage.setItem(key, fight + '_' + totalDmg);
  324.                 showStats();
  325.             }
  326.         });
  327.     }
  328.     text.push('(function () {');
  329.     text.push("var rank = {Recruit: 1, Private: 2, 'Private *': 3, 'Private **': 4, 'Private ***': 5, Corporal: 6, 'Corporal *': 7, 'Corporal **': 8, 'Corporal ***': 9, Sergeant: 10, 'Sergeant *': 11, 'Sergeant **': 12, 'Sergeant ***': 13, Lieutenant: 14, 'Lieutenant *': 15, 'Lieutenant **': 16, 'Lieutenant ***': 17, Captain: 18, 'Captain *': 19, 'Captain **': 20, 'Captain ***': 21, Major: 22, 'Major *': 23, 'Major **': 24, 'Major ***': 25, Commander: 26, 'Commander *': 27, 'Commander **': 28, 'Commander ***': 29, 'Lt Colonel': 30, 'Lt Colonel *': 31, 'Lt Colonel **': 32, 'Lt Colonel ***': 33, Colonel: 34, 'Colonel *': 35, 'Colonel **': 36, 'Colonel ***': 37, General: 38, 'General *': 39, 'General **': 40, 'General ***': 41, 'Field Marshal': 42, 'Field Marshal *': 43, 'Field Marshal **': 44, 'Field Marshal ***': 45, 'Supreme Marshal': 46, 'Supreme Marshal *': 47, 'Supreme Marshal **': 48, 'Supreme Marshal ***': 49, 'National Force': 50, 'National Force *': 51, 'National Force **': 52, 'National Force ***': 53, 'World Class Force': 54, 'World Class Force *': 55, 'World Class Force **': 56, 'World Class Force ***': 57, 'Legendary Force': 58, 'Legendary Force *': 59, 'Legendary Force **': 60, 'Legendary Force ***': 61, 'God of War': 62, 'God of War *': 63, 'God of War **': 64, 'God of War ***': 65};");
  330.     text.push('var totalDmg = ' + totalDmg + ';');
  331.     text.push(str_replace.toString());
  332.     text.push(dmgCalc.toString());
  333.     text.push(dmgMilitary.toString());
  334.     text.push(sortStats.toString());
  335.     text.push(getKey.toString());
  336.     text.push(showStats.toString());
  337.     text.push(localMain.toString());
  338.     text.push('localMain();');
  339.     text.push('})();');
  340.     scriptNode.textContent = text.join('\n');
  341.     document.head.appendChild(scriptNode);
  342. }
  343.  
  344. function addBtnHandler() {
  345.     $j('#stats_btn').unbind('click');
  346.     $j('#addstats_btn').unbind('click');
  347.     $j('#gen_btn').unbind('click');
  348.     $j('#clear_btn').unbind('click');
  349.     $j('#submit_btn').unbind('click');
  350.     $j('#stats_btn').click(function () {
  351.         $j('#my_stats').toggle();
  352.         $j('#addstats_btn').toggle();
  353.         $j('#help_btn').toggle();
  354.         $j('#clear_btn').css('display', 'none');
  355.         $j('#gen_txt').css('display', 'none');
  356.         $j('#stats_report').html('');
  357.         showStats();
  358.     });
  359.     $j('#addstats_btn').click(function () {
  360.         var myInf = $j('#total_damage').find('strong').text().replace(/\s/g, ''),
  361.             fight = $j('#total_f').find('strong').text().trim(),
  362.             key;
  363.         key = $j('#total_f').find('small').text().trim().split('_', 2);
  364.         key = '@_' + key[0] + '_' + key[1];
  365.         if (localStorage.getItem(key) != null) {
  366.             localStorage.setItem(key, fight + '_' + myInf);
  367.             showStats();
  368.             return;
  369.         }
  370.         if (localStorage.getItem('@' + key) != null) {
  371.             localStorage.setItem('@' + key, fight + '_' + myInf);
  372.         } else { //add @_battleId_zondId
  373.             localStorage.setItem(key, fight + '_' + myInf);
  374.         }
  375.         showStats();
  376.     });
  377.     $j('#gen_btn').click(function () {
  378.         showStats();
  379.         if ($j('#stats_report').html() != '') {
  380.             $j('#clear_btn').css('display', 'none');
  381.             $j('#gen_txt').css('display', 'none').val('');
  382.             $j('#stats_report').html('');
  383.             return;
  384.         }
  385.         var tmp, value, i, len, stats,
  386.             cmcs = [],
  387.             elites = [],
  388.             key = getKey();
  389.         for (i = 0, len = key.length; i < len; i++) {
  390.             value = localStorage.getItem(key[i]).split('_');
  391.             tmp = key[i].split('_');
  392.             if (tmp[0].length == 1) {
  393.                 cmcs.push(tmp[1] + '_'  + tmp[2] + '_' + value[0]);
  394.             } else {
  395.                 elites.push(tmp[1] + '_'  + tmp[2] + '_' + value[0]);
  396.             }
  397.         }
  398.         if (cmcs.length == 0 && elites.length == 0) {
  399.             $j('#stats_report').html('');
  400.             $j('#gen_txt').css('display', 'none');
  401.             return;
  402.         }
  403.         stats = '';
  404.         if (cmcs.length > 0) {
  405.             stats += 'ROCAS: [' + cmcs.join('] [') + ']<br/>';
  406.         }
  407.         if (elites.length > 0) {
  408.             stats += 'ELITE: [' + elites.join('] [') + ']';
  409.         }
  410.         $j('#stats_report').html(stats);
  411.         $j('#gen_txt').css('display', 'block');
  412.     });
  413.     $j('#clear_btn').click(function () {
  414.         var r, key, i, len;
  415.         r = confirm('確定要清除插件上的資料嘛?');
  416.         if (r == true) {
  417.             key = getKey();
  418.             for (i = 0, len = key.length; i < len; i++) {
  419.                 localStorage.removeItem(key[i]);
  420.             }
  421.             $j('#clear_btn').css('display', 'none');
  422.             $j('#stats_report').html('');
  423.             showStats();
  424.         }
  425.     });
  426.     $j('#submit_btn').click(function () {
  427.         var r, cmcs, elites, cmcInf, cmcFight, eliteInf, tmp, value, key, i, len, comment, cmsg, emsg, citizenId, others;
  428.         r = confirm('已自行確認數據資料正確,發送給ROCAS嗎?');
  429.         if (r == true) {
  430.             showStats();
  431.             cmcs = [];
  432.             elites = [];
  433.             cmcInf = 0;
  434.             cmcFight = 0;
  435.             eliteInf = 0;
  436.             key = getKey();
  437.             for (i = 0, len = key.length; i < len; i++) {
  438.                 value = localStorage.getItem(key[i]).split('_');
  439.                 tmp = key[i].split('_');
  440.                 if (tmp[0].length == 1) {
  441.                     cmcFight += parseInt(value[0], 10);
  442.                     cmcInf += parseInt(value[1], 10);
  443.                     cmcs.push(tmp[1] + '_'  + tmp[2] + '_' + value[0]);
  444.                 } else {
  445.                     eliteInf += parseInt(value[1], 10);
  446.                     elites.push(tmp[1] + '_'  + tmp[2] + '_' + value[0]);
  447.                 }
  448.             }
  449.             if (cmcs.length == 0 && elites.length == 0) {
  450.                 $j('#clear_btn').css('display', 'none');
  451.                 $j('#gen_txt').css('display', 'none');
  452.                 $j('#stats_report').html('');
  453.                 return;
  454.             }
  455.             $j('#stats_report').html('30% - Wait a mo...');
  456.             citizenId = $j('#financier').attr('href').substr(20);
  457.             others = '';
  458.             if ($j('#gen_txt').val() != '') {
  459.                 others = ' ' + $j('#gen_txt').val();
  460.             }
  461.             $j('#clear_btn').css('display', 'block');
  462.             $j('#gen_txt').css('display', 'none');
  463.             if (cmcs.length > 0 && elites.length > 0) {
  464.                 comment = 'ROCAS: [' + cmcs.join('] [') + ']' + others;
  465.                 cmsg = 'battleid=9999&uid=' + citizenId + '&fight=' + cmcFight + '&damage=' + cmcInf + '&others=' + comment;
  466.                 comment = 'ELITE: [' + elites.join('] [') + ']' + others;
  467.                 emsg = 'battleid=9999&elite=1&uid=' + citizenId + '&fight=' + dmgMilitary(1) + '&damage=' + eliteInf + '&others=' + comment;
  468.                 $j.post('http://eroc.no-ip.org/rocas/addapi.php', cmsg, function (data) {
  469.                     if (data.message == 'success') {
  470.                         $j('#stats_report').html('70% - Wait a mo...');
  471.                         $j.post('http://eroc.no-ip.org/rocas/addapi.php', emsg, function (data) {
  472.                             if (data.message == 'success') {
  473.                                 $j('#stats_report').html('<span style="color:green;">Submitted. <br/>Check: </span><a href="http://eroc.no-ip.org/rocas/list.php" target="_blank">ROCAS list</a>');
  474.                             } else if (data.message == 'error') {
  475.                                 $j('#stats_report').html('<span style="color:red;">' + data.errmsg + ' Try to submit again or access: <br/></span><a href="http://eroc.no-ip.org/rocas/formElite.php" target="_blank">ROCAS formElite</a>');
  476.                             }
  477.                         }, 'json');
  478.                     } else if (data.message == 'error') {
  479.                         $j('#stats_report').html('<span style="color:red;">' + data.errmsg + ' Try to submit again or access: <br/></span><a href="http://eroc.no-ip.org/rocas/form.php" target="_blank">ROCAS form</a>');
  480.                     }
  481.                 }, 'json');
  482.                 return;
  483.             }
  484.             if (cmcs.length > 0) {
  485.                 comment = 'ROCAS: [' + cmcs.join('] [') + ']' + others;
  486.                 cmsg = 'battleid=9999&uid=' + citizenId + '&fight=' + cmcFight + '&damage=' + cmcInf + '&others=' + comment;
  487.                 $j.post('http://eroc.no-ip.org/rocas/addapi.php', cmsg, function (data) {
  488.                     if (data.message == 'success') {
  489.                         $j('#stats_report').html('<span style="color:green;">上傳成功. <br/>網頁確認: </span><a href="http://eroc.no-ip.org/rocas/list.php" target="_blank">ROCAS list</a>');
  490.                     } else if (data.message == 'error') {
  491.                         $j('#stats_report').html('<span style="color:red;">' + data.errmsg + ' Try to submit again or access: <br/></span><a href="http://eroc.no-ip.org/rocas/form.php" target="_blank">RCOAS form</a>');
  492.                     }
  493.                 }, 'json');
  494.             }
  495.             if (elites.length > 0) {
  496.                 comment = 'ELITE: [' + elites.join('] [') + ']' + others;
  497.                 emsg = 'battleid=9999&elite=1&uid=' + citizenId + '&fight=' + dmgMilitary(1) + '&damage=' + eliteInf + '&others=' + comment;
  498.                 $j.post('http://eroc.no-ip.org/rocas/addapi.php', emsg, function (data) {
  499.                     if (data.message == 'success') {
  500.                         $j('#stats_report').html('<span style="color:green;">上傳成功. <br/>網頁確認: </span><a href="http://eroc.no-ip.org/rocas/list.php" target="_blank">ROCAS list</a>');
  501.                     } else if (data.message == 'error') {
  502.                         $j('#stats_report').html('<span style="color:red;">' + data.errmsg + ' Try to submit again or access: <br/></span><a href="http://eroc.no-ip.org/rocas/formElite.php" target="_blank">ROCAS formElite</a>');
  503.                     }
  504.                 }, 'json');
  505.             }
  506.         }
  507.     });
  508. }
  509.  
  510. function add_stats() {
  511.     $j('#experienceTooltip').before(
  512.         '<div style="float:left;width:153px;margin-bottom:7px;"><a href="javascript:;" id="stats_btn" style="margin-top:10px;float:left;"><strong>隱藏/顯示</strong></a><a href="javascript:;" id="addstats_btn" style="margin-top:10px;float:right;"><strong>加入</strong></a><a href="http://battlepupil.diandian.com" target="_blank" id="help_btn" style="margin-top:10px;float:right;display:none;"><strong>Help</strong></a><br/><div id="my_stats"><table id="stats_table" style="width:100%;"></table><hr/><table id="tstats_table" style="width:100%;"></table><hr/><a href="javascript:;" id="submit_btn" style="float:left;"><strong>送出</strong></a><a href="javascript:;" id="gen_btn" style="float:right;"><strong>備註</strong></a><br/><div id="stats_report" style="width:100%;"></div><textarea id="gen_txt" style="width:100%;display:none;"></textarea><a href="javascript:;" id="clear_btn" style="float:left;display:none;"><strong>清除資料</strong></a></div></div>'
  513.     );
  514.     var key, myInf, fight;
  515.     key = $j('#total_f').find('small').text().trim().split('_', 2);
  516.     key = '@_' + key[0] + '_' + key[1];
  517.     if (localStorage.getItem(key) != null) {
  518.         myInf = $j('#total_damage').find('strong').text().replace(/\s/g, '');
  519.         fight = $j('#total_f').find('strong').text().trim();
  520.         localStorage.setItem(key, fight + '_' + myInf);
  521.     }
  522.     key = '@' + key;
  523.     if (localStorage.getItem(key) != null) {
  524.         myInf = $j('#total_damage').find('strong').text().replace(/\s/g, '');
  525.         fight = $j('#total_f').find('strong').text().trim();
  526.         localStorage.setItem(key, fight + '_' + myInf);
  527.     }
  528.     showStats();
  529.     addBtnHandler();
  530.     $j(document).ready(function () {
  531.         showStats();
  532.         addBtnHandler();
  533.     });
  534. }
  535.  
  536. function add_region() {
  537.     var rh = $j('#pvp_header').find('h2'),
  538.         region = rh.text(),
  539.         regionurl;
  540.     if (region == 'Federation of BiH') {
  541.         regionurl = 'Federation+of+BiH';
  542.     } else if (region == 'Lika and Gorski Kotar') {
  543.         regionurl = 'Lika-Gorski-Kotar';
  544.     } else if (region == 'Istria and Kvarner') {
  545.         regionurl = 'Istria-Kvarner';
  546.     } else if (region == 'Styria and Carinthia') {
  547.         regionurl = 'Styria-Carinthia';
  548.     } else if (region == 'Jammu and Kashmir') {
  549.         regionurl = 'Jammu-Kashmir';
  550.     } else if (region == 'Svalbard & Jan Mayen') {
  551.         regionurl = 'Svalbard-Jan-Mayen';
  552.     } else if (region == 'North-West Frontier Province') {
  553.         regionurl = 'North-West-Frontier';
  554.     } else if (region == 'Sistan and Baluchistan') {
  555.         regionurl = 'Sistan-Baluchistan';
  556.     } else if (region == 'Norrland and Sameland') {
  557.         regionurl = 'Norrland-Sameland';
  558.     } else if (region == 'Yorkshire & Humberside') {
  559.         regionurl = 'Yorkshire-Humberside';
  560.     } else if (region == 'Lika and Gorski Kotar') {
  561.         regionurl = 'Lika-Gorski-Kotar';
  562.     } else if (region == 'Castilla y Leon') {
  563.         regionurl = 'Castilla-Leon';
  564.     } else if (region == 'Newfoundland and Labrador') {
  565.         regionurl = 'Newfoundland';
  566.     } else if (region == 'Chungcheongnam-do') {
  567.         regionurl = 'Chungcheongnam';
  568.     } else if (region == 'Gyeongsangbuk-do') {
  569.         regionurl = 'Gyeongsangbuk';
  570.     } else if (region == 'Gyeongsangnam-do') {
  571.         regionurl = 'Gyeongsangnam';
  572.     } else if (region == 'Gyeonggi-do') {
  573.         regionurl = 'Gyeonggi';
  574.     } else if (region == 'Gangwon-do') {
  575.         regionurl = 'Gangwon';
  576.     } else if (region == 'Chungcheongbuk-do') {
  577.         regionurl = 'Chungcheongbuk';
  578.     } else if (region == 'Jeollabuk-do') {
  579.         regionurl = 'Jeollabuk';
  580.     } else if (region == 'Jeollanam-do') {
  581.         regionurl = 'Jeollanam';
  582.     } else if (region == 'Ha\'il') {
  583.         regionurl = 'Ha-il';
  584.     } else {
  585.         regionurl = region.replace(/ /g, '-');
  586.     }
  587.     rh.html('<a target="_blank" href="http://www.erepublik.com/en/region/' + regionurl + '">' + region + '</a>');
  588. }
  589.  
  590. function add_moveb() {
  591.     var data = JSON.parse($j('#content').html().split('regionsInvolved = ')[1].split(';\n</script>')[0]),
  592.         countryId = $j('#country_list').val();
  593.     $j('#region_list').find('option:gt(0)').each(function () {
  594.         $j(this).text('[' + data[countryId][$j(this).val()].distance + '] ' + $j(this).text());
  595.     });
  596.     $j('#country_list').change(function () {
  597.         var countryId = $j('#country_list').val();
  598.         $j('#region_list').find('option:gt(0)').each(function () {
  599.             $j(this).text('[' + data[countryId][$j(this).val()].distance + '] ' + $j(this).text());
  600.         });
  601.     });
  602. }
  603.  
  604. function add_movec() {
  605.     var region, src, srcx, srcy;
  606.     region = JSON.parse('{"111":13,"110":13,"113":13,"112":13,"114":13,"109":13,"108":13,"183":23,"146":32,"497":43,"500":43,"147":32,"148":32,"504":43,"686":31,"150":32,"653":32,"149":32,"505":43,"186":13,"198":13,"11":13,"39":13,"514":23,"36":13,"3":13,"515":23,"38":13,"37":13,"5":13,"9":13,"35":13,"246":13,"256":13,"258":13,"167":23,"168":23,"169":23,"184":23,"170":23,"171":23,"181":23,"173":23,"174":23,"175":23,"176":23,"179":23,"166":23,"177":23,"178":23,"180":23,"152":42,"678":32,"676":42,"685":31,"155":42,"688":31,"154":42,"151":42,"681":32,"675":42,"156":42,"679":32,"153":42,"41":11,"42":21,"43":21,"44":21,"45":21,"47":21,"50":21,"51":21,"52":21,"54":21,"61":21,"62":21,"65":21,"66":21,"67":21,"70":21,"72":21,"73":21,"76":21,"80":21,"82":21,"83":21,"86":21,"88":21,"89":21,"361":24,"395":24,"396":24,"522":25,"362":24,"520":25,"363":24,"364":24,"390":24,"384":24,"519":25,"525":25,"385":24,"368":24,"386":24,"370":24,"371":24,"670":25,"391":24,"372":24,"373":24,"387":24,"671":25,"375":24,"392":24,"459":24,"493":24,"494":24,"669":25,"389":24,"377":24,"378":24,"397":24,"379":24,"380":24,"495":24,"394":24,"393":24,"381":24,"382":24,"97":11,"103":11,"105":11,"98":12,"102":12,"106":11,"99":12,"107":12,"95":12,"96":12,"100":12,"101":11,"221":13,"104":11,"208":13,"222":13,"224":13,"216":13,"215":13,"212":13,"226":13,"227":13,"219":13,"217":13,"210":13,"220":13,"218":13,"223":13,"213":13,"225":13,"531":13,"529":13,"228":13,"229":13,"230":13,"341":13,"342":13,"344":13,"437":13,"346":13,"343":13,"347":13,"291":13,"295":13,"292":13,"562":13,"294":13,"185":13,"187":13,"243":13,"244":13,"188":13,"189":13,"191":13,"46":21,"530":13,"193":13,"426":13,"249":13,"53":21,"55":21,"195":13,"425":13,"190":13,"196":13,"197":13,"251":13,"58":21,"60":21,"424":13,"423":13,"250":13,"64":21,"68":21,"69":21,"71":21,"207":13,"252":13,"74":21,"75":21,"199":13,"200":13,"77":21,"201":13,"202":13,"306":13,"253":13,"78":21,"204":13,"254":13,"255":13,"257":13,"307":13,"205":13,"84":21,"85":21,"528":13,"323":13,"325":13,"549":13,"231":13,"322":13,"232":13,"321":13,"324":13,"235":13,"326":13,"320":13,"236":13,"293":13,"312":13,"340":13,"316":13,"319":13,"440":13,"442":13,"345":13,"315":13,"242":13,"241":13,"240":13,"237":13,"238":13,"140":13,"137":13,"349":23,"537":13,"353":23,"135":13,"358":23,"355":23,"132":13,"144":13,"356":23,"352":23,"512":23,"513":23,"516":23,"517":23,"518":23,"414":23,"533":13,"138":13,"143":13,"133":13,"136":13,"142":13,"134":13,"141":13,"534":14,"535":15,"543":13,"660":13,"538":13,"532":13,"536":13,"139":13,"540":13,"659":13,"544":13,"541":13,"542":14,"661":13,"487":25,"489":25,"484":25,"486":25,"488":25,"491":25,"490":25,"485":25,"526":25,"527":25,"461":35,"462":35,"463":35,"465":35,"646":25,"328":45,"334":35,"647":25,"466":35,"329":35,"641":35,"330":45,"464":35,"460":35,"332":45,"333":45,"450":24,"458":24,"455":24,"448":24,"561":24,"456":24,"451":24,"453":24,"447":24,"449":24,"443":24,"454":24,"446":24,"452":24,"445":24,"457":24,"498":43,"499":43,"501":43,"502":43,"503":43,"92":13,"91":13,"93":13,"94":13,"209":13,"233":13,"736":24,"739":24,"717":24,"725":24,"478":24,"479":24,"742":24,"723":24,"480":24,"472":24,"483":24,"719":24,"482":24,"740":24,"475":24,"477":24,"473":24,"474":24,"481":24,"726":23,"741":24,"476":24,"492":24,"471":23,"469":32,"467":23,"468":23,"470":23,"507":24,"509":24,"511":24,"508":24,"510":24,"260":23,"336":13,"265":23,"266":23,"339":13,"581":13,"268":23,"269":23,"611":13,"270":23,"272":23,"621":13,"337":13,"571":13,"601":13,"338":13,"275":23,"591":13,"278":23,"690":31,"116":21,"691":31,"120":21,"122":21,"117":21,"119":21,"118":21,"693":31,"121":21,"115":21,"160":23,"161":23,"162":23,"125":32,"126":32,"159":23,"127":32,"157":23,"129":32,"163":23,"158":23,"130":32,"123":32,"124":32,"131":32,"259":23,"40":21,"261":23,"262":23,"635":23,"263":23,"264":23,"623":23,"192":13,"90":21,"637":23,"48":21,"49":21,"626":23,"56":21,"743":23,"194":13,"267":23,"625":23,"57":21,"59":21,"63":21,"271":23,"627":23,"624":23,"203":13,"639":23,"273":23,"274":23,"622":23,"79":21,"628":23,"640":23,"636":23,"81":21,"276":23,"277":23,"634":23,"87":21,"638":23,"682":31,"684":31,"683":31,"630":42,"629":42,"687":31,"633":42,"631":42,"632":42,"644":25,"645":25,"643":34,"642":35,"648":34,"239":13,"656":13,"655":13,"657":13,"658":13,"654":13,"662":13,"651":23,"650":23,"652":23,"649":23,"707":13,"666":13,"708":13,"709":13,"663":13,"665":13,"711":13,"710":13,"664":13,"667":13,"712":13,"674":42,"668":25,"672":25,"673":25,"680":32,"677":32,"689":31,"694":31,"692":31,"699":23,"700":23,"698":23,"702":24,"521":25,"703":24,"523":25,"524":25,"701":24,"704":24,"420":23,"718":23,"721":23,"724":23,"418":23,"417":23,"422":23,"697":23,"416":23,"421":23,"731":23,"728":23,"727":24,"419":23,"695":23,"735":23,"415":23,"413":23,"696":23,"706":23,"705":23,"713":35,"715":35,"716":35,"331":45,"714":35,"733":23,"730":23,"734":23,"732":23,"737":24,"738":24,"745":23,"746":23,"744":23,"720":23,"722":24,"729":23}');
  607.     src = $j('#content').find('div.zone:first').find('big').text();
  608.     src = src.replace('A', '1');
  609.     src = src.replace('B', '2');
  610.     src = src.replace('C', '3');
  611.     src = src.replace('D', '4');
  612.     srcx = Math.floor(src / 10);
  613.     srcy = src % 10;
  614.     $j('#country_list').change(function () {
  615.         $j('#region_list').one('click', function () {
  616.             $j(this).find('option:gt(0)').each(function () {
  617.                 var ta, tb, dx, dy, move,
  618.                     dest = region[$j(this).val()],
  619.                     destx = Math.floor(dest / 10),
  620.                     desty = dest % 10;
  621.                 ta = srcx < destx ? srcx : destx;
  622.                 tb = srcx > destx ? srcx : destx;
  623.                 dx = tb - ta < ta + 4 - tb ? tb - ta : ta + 4 - tb;
  624.                 ta = srcy < desty ? srcy : desty;
  625.                 tb = srcy > desty ? srcy : desty;
  626.                 dy = tb - ta < ta + 5 - tb ? tb - ta : ta + 5 - tb;
  627.                 move = 1 + dx + dy;
  628.                 $j(this).text('[' + move + '] ' + $j(this).text());
  629.             });
  630.         });
  631.     });
  632. }
  633.  
  634. if (currURL == 'http://www.erepublik.com/en') {
  635.     add_news();
  636. } else if (currURL.charAt(36) == 'p') {
  637.     add_inf();
  638. } else if (currURL.charAt(28) == 'm') {
  639.     add_moveb();
  640.     add_region();
  641.     add_fight();
  642.     add_stats();
  643. } else {
  644.     add_movec();
  645. }
Add Comment
Please, Sign In to add comment