// ==UserScript==
// @name Sect Misc
// @namespace http://userscripts.org/users/splurov/
// @include http://sect.com/*
// ==/UserScript==
(function(){
var HEAL_ID = '4c158b114ba633b74d2611b1e065da48',
HIDE_ID = '9c51f68bff01b494a2ca894c73c606ac';
var $ = unsafeWindow.$;
if (!$) {
return;
}
var Game = unsafeWindow.Game,
game = unsafeWindow.game,
$url = unsafeWindow.location.toString();
/* Resources Manager */
var rm = {
getCoins: function () {
return parseInt($('#chr_con').text().replace(/,/, ''));
},
getHealth: function () {
return parseInt($('#chr_prp_health_val_cur').text());
},
getMaxHealth: function () {
return parseInt($('#chr_prp_health_val').text());
},
getPhy: function () {
return parseInt($('#chr_prp_physical_val_cur').text());
},
getPsy: function () {
return parseInt($('#chr_prp_psychical_val_cur').text());
},
getRatio: function() {
return parseFloat(
game.char.prp_fights_won
/ game.char.prp_fights_lost
);
},
getLevel: function() {
return parseInt($('#chr_prp_level_val').text());
},
getSectants: function() {
var sectants = parseInt($('#chr_prp_sectants_val').text());
return sectants > 500 ? 500 : sectants;
},
getRank: function() {
return parseInt(game.char.prp_rank);
},
getExp: function() {
return parseInt($('#chr_exp').text());
},
getExpNextLevel: function() {
return parseInt($('#chr_exp_lm').text());
},
doHeal: function() {
Game.HPT_setAction(HEAL_ID, 'heal');
},
doHide: function(number) {
if (!$('#hide_coins').length) {
$(document.body).append(
$(document.createElement('input'))
.attr({id: 'hide_coins', type: 'text'})
.css({position: 'absolute', top: '-999px', left: '-999px'})
);
}
$('#hide_coins').val(number);
Game.STH_setAction(HIDE_ID, 'hide');
},
doRetrieve: function(number) {
if (!$('#retrieve_coins').length) {
$(document.body).append(
$(document.createElement('input'))
.attr({id: 'retrieve_coins', type: 'text'})
.css({position: 'absolute', top: '-999px', left: '-999px'})
);
}
$('#retrieve_coins').val(number);
Game.STH_setAction(HIDE_ID, 'retrieve');
},
}
/* Menu Items */
if ($('.menu').length) {
/* Heal & Hide Button */
$('.menu .last').removeClass('last');
$('.menu').append(
$(document.createElement('a'))
.text('Heal & Hide')
.attr('href', '#')
.addClass('last')
.click(function(e){
var coins = rm.getCoins(),
health = rm.getHealth(),
healthMax = rm.getMaxHealth();
if (health < healthMax) {
var healPrice = (healthMax - health) * 2;
if (coins < healPrice) {
rm.doRetrieve(healPrice - coins);
var healInterval = setInterval(function(){
if (rm.getCoins() >= coins) {
clearInterval(healInterval);
healInterval = null;
rm.doHeal();
}
}, 500);
setTimeout(function(){
if (healInterval != null) {
clearInterval(healInterval);
}
}, 10000);
}
else {
rm.doHeal();
rm.doHide(coins - healPrice);
}
}
else if (coins >= 1) {
rm.doHide(coins);
}
e.preventDefault();
})
);
/* Exp to Next Level */
$('#chr_exp_lm').after(
'('
+ (rm.getExpNextLevel() - rm.getExp()).toString()
+ ')'
);
}
/* Missions Checker */
if ($url.indexOf('missions') != -1) {
var mc = {
phy: rm.getPhy(),
psy: rm.getPsy(),
run: function () {
$('.stats4 tr').each(function(){
var td = $('td:eq(1)', this),
q = $('td:eq(0) p:eq(2)', this).text(),
qDelim = q.indexOf('/');
if (
mc.phy >= mc.get('phy', td)
&& mc.psy >= mc.get('psy', td)
&& parseInt(q.slice(0, qDelim)) != parseInt(q.slice(qDelim + 1, q.length))
) {
$(this).addClass('highlighted');
}
else {
$(this).removeClass('highlighted');
}
$('td:eq(5) img:eq(0)', this).click(function () {
var td = $(this).parent().parent().parent().children('td:eq(1)'),
phy = mc.get('phy', td),
psy = mc.get('psy', td);
if (phy <= mc.phy && psy <= mc.psy) {
mc.phy -= phy;
mc.psy -= psy;
mc.run();
}
});
});
},
get: function (what, where) {
var value = parseInt($('p span:contains(' + what + ')', where).prev().text());
if (value) {
return parseInt(value);
}
return 0;
}
};
mc.run();
}
var getPower = function (ratio, level, sectants, rank) {
ratio = parseFloat(ratio);
sectants = parseInt(sectants);
level = parseInt(level);
rank = parseInt(rank);
return (
(ratio + parseFloat(sectants / 1000))
/ (level + rank) * (ratio * level * sectants * rank / 100)
).toFixed(0);
}
/* Fights Helper */
if ($url.indexOf('fight') != -1) {
var ownPower = getPower(rm.getRatio(), rm.getLevel(), rm.getSectants(), rm.getRank()),
ownPowerRatio = ownPower * 0.5;
$('.ten tr').each(function(){
var ratio = parseFloat($('td:eq(0) span:eq(0)', this).text().replace(/[^\d.]+/, '')),
level = $('td:eq(2) span:eq(0)', this).text(),
sectants = $('td:eq(4) span:eq(0)', this).text(),
rank = {
'Private': 1,
'Private First Class': 2,
'Corporal': 3,
'Sergeant': 4,
'Staff Sergeant': 5,
'Sergeant First Class': 6,
'Master Sergeant': 7,
'First Sergeant': 8,
'Sergeant Major': 9,
'Second Lieutenant': 10,
'First Lieutenant': 11,
'Captain': 12,
'Major': 13,
'Lieutenant Colonel': 14,
'Colonel': 15,
'Brigadier General': 16,
'Major General': 17,
'Lieutenant General': 18,
}[$('td:eq(0) p:eq(0)', this).text()],
power = getPower(ratio, level, sectants, rank),
span = $(document.createElement('span')).text(power),
spanColor,
spanFontSize;
if (power < (ownPowerRatio / 3)) {
spanColor = '#e70';
spanFontSize = '17px';
}
else if (power < (ownPowerRatio / 1.5)) {
spanColor = '#be6c0f';
spanFontSize = '15px';
}
else if (power < ownPowerRatio) {
spanColor = '#9b6518';
spanFontSize = '13px';
}
else {
spanColor = 'inherit';
spanFontSize = '11px';
}
$('td:eq(5)', this)
.css({whiteSpace: 'nowrap', fontWeight: 'bold', color: spanColor, fontSize: spanFontSize})
.append(span);
$('td:eq(0) p:eq(0)', this).prepend(
$(document.createElement('span'))
.text(ratio.toFixed(1) + ' ')
.css({fontSize: '13px', fontWeight: 'bold', color: '#EFEB77'})
);
$('td:eq(0) p.knopa', this).remove();
var code = $('td:eq(5)', this).html().match(/(\d+), '([\da-f]{32})/);
$(this)
.css('cursor', 'pointer')
.attr({userId: code[1], fightId: code[2], 'userPower': power})
.removeClass('one')
.click(function(){
Game.FTH_setAttack($(this).attr('userId'), $(this).attr('fightId'));
$('td:eq(5) span', this).css('textDecoration', 'line-through');
});
$('td:eq(5) a', this).remove();
$('.stats2').css('display', 'none');
});
var rows = $('.ten').find('tbody > tr').get();
rows.sort(function(a, b) {
var first = parseInt($(a).attr('userPower')),
second = parseInt($(b).attr('userPower'));
if (first < second) {
return -1;
}
if (second < first) {
return 1;
}
return 0;
});
$(rows[0]).addClass('one');
$.each(rows, function(index, row) {
$('.ten tbody').append(row);
});
$('.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>');
}
/* Buildings Helper */
if ($url.indexOf('buildings') != -1) {
var foundations = {};
$('.stats6:eq(0) tr').each(function(){
foundations[$('td:eq(1) strong', this).text()] = parseInt($('td:eq(3) p.tx24 font', this).text().replace(/,/g, ''));
});
$('.stats6 tr').each(function(){
var reqText = $('td:eq(1) p:eq(1) span:eq(1) strong', this).text(),
req = 0;
if (reqText) {
req = foundations[reqText];
}
$('td:eq(2)', this).append('<p>' + (
(parseInt($('td:eq(3) p.tx24 font', this).text().replace(/,/g, '')) + req)
/ $('td:eq(2) span', this).text().replace(/[^\d]+/g, '')
).toFixed(2) + '</p>');
});
}
/* Profile Helper */
if ($url.indexOf('profile') != -1) {
var ratio = rm.getRatio();
$('.stat6 tbody').append(
'<tr><td>Ratio</td><td><span>'
+ ratio.toFixed(2)
+ '</span></td></tr>'
);
$('.stat6 tbody').append(
'<tr><td>Power</td><td><span>'
+ getPower(ratio, rm.getLevel(), rm.getSectants(), rm.getRank())
+ '</span></td></tr>'
);
$('.bord5').css('height', 'auto');
}
})();