Got an iPhone or iPad? We have a brand new Pastebin App for both devices, and it's totally free! Click here to download the new Pastebin App for iOS.
Guest

Untitled

By: a guest on Sep 7th, 2009  |  syntax: JavaScript  |  size: 8.51 KB  |  hits: 32  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. // ==UserScript==
  2. // @name           Sect Misc
  3. // @namespace      http://userscripts.org/users/splurov/
  4. // @include        http://sect.com/*
  5. // ==/UserScript==
  6.  
  7. (function(){
  8.  
  9. var HEAL_ID = '4c158b114ba633b74d2611b1e065da48',
  10.                 HIDE_ID = '9c51f68bff01b494a2ca894c73c606ac';
  11.  
  12. var $ = unsafeWindow.$;
  13. if (!$) {
  14.         return;
  15. }
  16. var Game = unsafeWindow.Game,
  17.                 game = unsafeWindow.game,
  18.                 $url = unsafeWindow.location.toString();
  19.  
  20. /* Resources Manager */
  21. var rm = {
  22.         getCoins: function () {
  23.                 return parseInt($('#chr_con').text().replace(/,/, ''));
  24.         },
  25.         getHealth: function () {
  26.                 return parseInt($('#chr_prp_health_val_cur').text());
  27.         },
  28.         getMaxHealth: function () {
  29.                 return parseInt($('#chr_prp_health_val').text());
  30.         },
  31.         getPhy: function () {
  32.                 return parseInt($('#chr_prp_physical_val_cur').text());
  33.         },
  34.         getPsy: function () {
  35.                 return parseInt($('#chr_prp_psychical_val_cur').text());
  36.         },
  37.         getRatio: function() {
  38.                 return parseFloat(
  39.                         game.char.prp_fights_won
  40.                         / game.char.prp_fights_lost
  41.                 );
  42.         },
  43.         getLevel: function() {
  44.                 return parseInt($('#chr_prp_level_val').text());
  45.         },
  46.         getSectants: function() {
  47.                 var sectants = parseInt($('#chr_prp_sectants_val').text());
  48.                 return sectants > 500 ? 500 : sectants;
  49.         },
  50.         getRank: function() {
  51.                 return parseInt(game.char.prp_rank);
  52.         },
  53.         getExp: function() {
  54.                 return parseInt($('#chr_exp').text());
  55.         },
  56.         getExpNextLevel: function() {
  57.                 return parseInt($('#chr_exp_lm').text());
  58.         },
  59.         doHeal: function() {
  60.                 Game.HPT_setAction(HEAL_ID, 'heal');
  61.         },
  62.         doHide: function(number) {
  63.                 if (!$('#hide_coins').length) {
  64.                         $(document.body).append(
  65.                                 $(document.createElement('input'))
  66.                                 .attr({id: 'hide_coins', type: 'text'})
  67.                                 .css({position: 'absolute', top: '-999px', left: '-999px'})
  68.                         );
  69.                 }
  70.                 $('#hide_coins').val(number);
  71.                 Game.STH_setAction(HIDE_ID, 'hide');
  72.         },
  73.         doRetrieve: function(number) {
  74.                 if (!$('#retrieve_coins').length) {
  75.                         $(document.body).append(
  76.                                 $(document.createElement('input'))
  77.                                 .attr({id: 'retrieve_coins', type: 'text'})
  78.                                 .css({position: 'absolute', top: '-999px', left: '-999px'})
  79.                         );
  80.                 }
  81.                 $('#retrieve_coins').val(number);
  82.                 Game.STH_setAction(HIDE_ID, 'retrieve');
  83.         },
  84. }
  85.  
  86. /* Menu Items */
  87. if ($('.menu').length) {
  88.         /* Heal & Hide Button */
  89.         $('.menu .last').removeClass('last');
  90.         $('.menu').append(
  91.                 $(document.createElement('a'))
  92.                 .text('Heal & Hide')
  93.                 .attr('href', '#')
  94.                 .addClass('last')
  95.                 .click(function(e){
  96.                         var coins = rm.getCoins(),
  97.                                         health = rm.getHealth(),
  98.                                         healthMax = rm.getMaxHealth();
  99.                         if (health < healthMax) {
  100.                                 var healPrice = (healthMax - health) * 2;
  101.                                 if (coins < healPrice) {
  102.                                         rm.doRetrieve(healPrice - coins);
  103.                                         var healInterval = setInterval(function(){
  104.                                                 if (rm.getCoins() >= coins) {
  105.                                                         clearInterval(healInterval);
  106.                                                         healInterval = null;
  107.                                                         rm.doHeal();
  108.                                                 }
  109.                                         }, 500);
  110.                                         setTimeout(function(){
  111.                                                 if (healInterval != null) {
  112.                                                         clearInterval(healInterval);
  113.                                                 }
  114.                                         }, 10000);
  115.                                 }
  116.                                 else {
  117.                                         rm.doHeal();
  118.                                         rm.doHide(coins - healPrice);
  119.                                 }
  120.                         }
  121.                         else if (coins >= 1) {
  122.                                 rm.doHide(coins);
  123.                         }
  124.                         e.preventDefault();
  125.                 })
  126.         );
  127.  
  128.         /* Exp to Next Level */
  129.         $('#chr_exp_lm').after(
  130.                 '('
  131.                 + (rm.getExpNextLevel() - rm.getExp()).toString()
  132.                 + ')'
  133.         );
  134. }
  135.  
  136. /* Missions Checker */
  137. if ($url.indexOf('missions') != -1) {
  138.         var mc = {
  139.                 phy: rm.getPhy(),
  140.                 psy: rm.getPsy(),
  141.                 run: function () {
  142.                         $('.stats4 tr').each(function(){
  143.                                 var td = $('td:eq(1)', this),
  144.                                                 q = $('td:eq(0) p:eq(2)', this).text(),
  145.                                                 qDelim = q.indexOf('/');
  146.                                 if (
  147.                                         mc.phy >= mc.get('phy', td)
  148.                                         && mc.psy >= mc.get('psy', td)
  149.                                         && parseInt(q.slice(0, qDelim)) != parseInt(q.slice(qDelim + 1, q.length))
  150.                                 ) {
  151.                                         $(this).addClass('highlighted');
  152.                                 }
  153.                                 else {
  154.                                         $(this).removeClass('highlighted');
  155.                                 }
  156.                                 $('td:eq(5) img:eq(0)', this).click(function () {
  157.                                         var td = $(this).parent().parent().parent().children('td:eq(1)'),
  158.                                                         phy = mc.get('phy', td),
  159.                                                         psy = mc.get('psy', td);
  160.                                         if (phy <= mc.phy && psy <= mc.psy) {
  161.                                                 mc.phy -= phy;
  162.                                                 mc.psy -= psy;
  163.                                                 mc.run();
  164.                                         }
  165.                                 });
  166.                         });
  167.                 },
  168.                 get: function (what, where) {
  169.                         var value = parseInt($('p span:contains(' + what + ')', where).prev().text());
  170.                         if (value) {
  171.                                 return parseInt(value);
  172.                         }
  173.                         return 0;
  174.                 }
  175.         };
  176.         mc.run();
  177. }
  178.  
  179. var getPower = function (ratio, level, sectants, rank) {
  180.         ratio = parseFloat(ratio);
  181.         sectants = parseInt(sectants);
  182.         level = parseInt(level);
  183.         rank = parseInt(rank);
  184.         return (
  185.                 (ratio + parseFloat(sectants / 1000))
  186.                 / (level + rank) * (ratio * level * sectants * rank / 100)
  187.         ).toFixed(0);
  188. }
  189.  
  190. /* Fights Helper */
  191. if ($url.indexOf('fight') != -1) {
  192.         var ownPower = getPower(rm.getRatio(), rm.getLevel(), rm.getSectants(), rm.getRank()),
  193.                         ownPowerRatio = ownPower * 0.5;
  194.         $('.ten tr').each(function(){
  195.                 var ratio = parseFloat($('td:eq(0) span:eq(0)', this).text().replace(/[^\d.]+/, '')),
  196.                                 level = $('td:eq(2) span:eq(0)', this).text(),
  197.                                 sectants = $('td:eq(4) span:eq(0)', this).text(),
  198.                                 rank = {
  199.                                         'Private': 1,
  200.                                         'Private First Class': 2,
  201.                                         'Corporal': 3,
  202.                                         'Sergeant': 4,
  203.                                         'Staff Sergeant': 5,
  204.                                         'Sergeant First Class': 6,
  205.                                         'Master Sergeant': 7,
  206.                                         'First Sergeant': 8,
  207.                                         'Sergeant Major': 9,
  208.                                         'Second Lieutenant': 10,
  209.                                         'First Lieutenant': 11,
  210.                                         'Captain': 12,
  211.                                         'Major': 13,
  212.                                         'Lieutenant Colonel': 14,
  213.                                         'Colonel': 15,
  214.                                         'Brigadier General': 16,
  215.                                         'Major General': 17,
  216.                                         'Lieutenant General': 18,
  217.                                 }[$('td:eq(0) p:eq(0)', this).text()],
  218.                                 power = getPower(ratio, level, sectants, rank),
  219.                                 span = $(document.createElement('span')).text(power),
  220.                                 spanColor,
  221.                                 spanFontSize;
  222.                 if (power < (ownPowerRatio / 3)) {
  223.                         spanColor = '#e70';
  224.                         spanFontSize = '17px';
  225.                 }
  226.                 else if (power < (ownPowerRatio / 1.5)) {
  227.                         spanColor = '#be6c0f';
  228.                         spanFontSize = '15px';
  229.                 }
  230.                 else if (power < ownPowerRatio) {
  231.                         spanColor = '#9b6518';
  232.                         spanFontSize = '13px';
  233.                 }
  234.                 else {
  235.                         spanColor = 'inherit';
  236.                         spanFontSize = '11px';
  237.                 }
  238.                 $('td:eq(5)', this)
  239.                         .css({whiteSpace: 'nowrap', fontWeight: 'bold', color: spanColor, fontSize: spanFontSize})
  240.                         .append(span);
  241.                 $('td:eq(0) p:eq(0)', this).prepend(
  242.                         $(document.createElement('span'))
  243.                         .text(ratio.toFixed(1) + ' ')
  244.                         .css({fontSize: '13px', fontWeight: 'bold', color: '#EFEB77'})
  245.                 );
  246.                 $('td:eq(0) p.knopa', this).remove();
  247.                 var code = $('td:eq(5)', this).html().match(/(\d+), '([\da-f]{32})/);
  248.                 $(this)
  249.                         .css('cursor', 'pointer')
  250.                         .attr({userId: code[1], fightId: code[2], 'userPower': power})
  251.                         .removeClass('one')
  252.                         .click(function(){
  253.                                 Game.FTH_setAttack($(this).attr('userId'), $(this).attr('fightId'));
  254.                                 $('td:eq(5) span', this).css('textDecoration', 'line-through');
  255.                         });
  256.                 $('td:eq(5) a', this).remove();
  257.                 $('.stats2').css('display', 'none');
  258.         });
  259.         var rows = $('.ten').find('tbody > tr').get();
  260.         rows.sort(function(a, b) {
  261.                 var first = parseInt($(a).attr('userPower')),
  262.                                 second = parseInt($(b).attr('userPower'));
  263.                 if (first < second) {
  264.                         return -1;
  265.                 }
  266.                 if (second < first) {
  267.                         return 1;
  268.                 }
  269.                 return 0;
  270.         });
  271.         $(rows[0]).addClass('one');
  272.         $.each(rows, function(index, row) {
  273.                 $('.ten tbody').append(row);
  274.         });
  275.         $('.inf').css({background: 'transparent'}).prepend('<div style="float: right; font-weight: bold; margin: 3px 50px 0 0;">Your Power: <span class="col">' + ownPower + '</span></div>');
  276. }
  277.  
  278. /* Buildings Helper */
  279. if ($url.indexOf('buildings') != -1) {
  280.         var foundations = {};
  281.         $('.stats6:eq(0) tr').each(function(){
  282.                 foundations[$('td:eq(1) strong', this).text()] = parseInt($('td:eq(3) p.tx24 font', this).text().replace(/,/g, ''));
  283.         });
  284.         $('.stats6 tr').each(function(){
  285.                 var reqText = $('td:eq(1) p:eq(1) span:eq(1) strong', this).text(),
  286.                                 req = 0;
  287.                 if (reqText) {
  288.                         req = foundations[reqText];
  289.                 }
  290.                 $('td:eq(2)', this).append('<p>' + (
  291.                         (parseInt($('td:eq(3) p.tx24 font', this).text().replace(/,/g, '')) + req)
  292.                         / $('td:eq(2) span', this).text().replace(/[^\d]+/g, '')
  293.                 ).toFixed(2) + '</p>');
  294.         });
  295. }
  296.  
  297. /* Profile Helper */
  298. if ($url.indexOf('profile') != -1) {
  299.         var ratio = rm.getRatio();
  300.         $('.stat6 tbody').append(
  301.                 '<tr><td>Ratio</td><td><span>'
  302.                 + ratio.toFixed(2)
  303.                 + '</span></td></tr>'
  304.         );
  305.         $('.stat6 tbody').append(
  306.                 '<tr><td>Power</td><td><span>'
  307.                 + getPower(ratio, rm.getLevel(), rm.getSectants(), rm.getRank())
  308.                 + '</span></td></tr>'
  309.         );
  310.         $('.bord5').css('height', 'auto');
  311. }
  312.  
  313. })();