// ==UserScript== // @name StarRepublik Tools // @name:bg StarRepublik Инструменти // @name:ro Unelte StarRepublik // @description Various enhancements and tools for StarRepublik // @description:bg Различни подобрения и инструменти за StarRepublik // @description:ro Diverse îmbunătățiri și unelte pentru StarRepublik // @namespace http://www.linuxmint.ro/ // @version 1.2 // @license CC BY 4.0 // @author Nicolae Crefelean // @include https://www.starrepublik.com/* // @grant none // @downloadURL none // ==/UserScript== $(function() { var letters = [ 'α', 'β', 'γ', 'Δ', 'Ω' ]; var congressCandidatesArticle = ''; var effectDelay = 150; function clearTopMedals() { medals = [ '.defender-ds', '.attacker-ds', '.defender-bh', '.attacker-bh', '.defender-ace', '.attacker-ace' ]; for (i = 0; i < 7; i++) { medal = medals[i]; $(medal + ' a').removeAttr('href'); $(medal + ' a img').removeAttr('src'); $(medal + ' div.username').text(''); $(medal + ' span.damage').text(''); $(medal + ' span.shoots').text(''); } } function addSquadronSwitcher() { $('.close-statistics:eq(1)').attr('class',$('.close-statistics:eq(1)').attr('class').replace(/4/g, '1')); squads = []; for (i = 1; i < 6; i++) { sclass = 'squadSwitch' + ($('.statistics:eq(1)').data('squadron') == i ? ' btn-primary' : ''); squads.push("" + letters[i - 1] + ""); } $('.close-statistics:eq(1)').before("
" + squads.join('') + "
"); } if (/^\/military\/battle\//.test(document.location.pathname)) { $('.battle-statistics').css('width', '100%'); addSquadronSwitcher(); } $('.squadSwitch').on("click", function() { clearTopMedals(); $('.squadSwitch').removeClass('btn-primary'); squad = letters.indexOf($(this).text()); $('.squadSwitch:eq(' + squad + ')').addClass('btn-primary'); $('.statistics:eq(1)').data('squadron', squad + 1).click(); }); if (/^\/country\/society\//.test(document.location.pathname)) { getCountryDetails(); } function getCountryDetails() { sectors = $('.country-content .society-list:eq(1) li').length; $('.country-content .society-list:eq(1) > div').append(' (' + sectors + ')'); } if (/^\/storage\/$/.test(document.location.pathname)) { minParts = Math.min(itemsCount('ion_ammo'), itemsCount('ion_stock'), itemsCount('ion_chip')); setCannonPartBalance(minParts); setWeaponBalance(minParts); } function itemsCount(img) { return Number($('.storage-list:eq(0) li img[src="/media/images/products/' + img + '.jpg"]').parent().next().text().trim()) || 0; } function setBalance(num) { return (num === 0 ? '' : (num > 0 ? '-' : '+')) + Math.abs(num).toString(); } function weaponMultiplier(quality) { return {'q1': 10, 'q2': 8, 'q3': 6, 'q4': 4, 'q5': 2}[quality]; } function setWeaponBalance(cannons) { for (i = 1; i < 6; i++) { quality = 'q' + i.toString(); balance = setBalance(cannons * weaponMultiplier(quality) - itemsCount('weapon_' + quality)); $('.item-creation-list li img[src="/media/images/products/weapon_' + quality + '.jpg"]').attr('alt', quality).parent().next().text(balance); } } function setCannonPartBalance(count) { $('.item-creation-list:eq(1) .item-to-create .quantity').text(count).prev().find('img').attr('alt', 'cannons'); cannonParts = {1: 'ammo', 2: 'stock', 3: 'chip'}; for (i = 1; i < 4; i++) { balance = setBalance(count - itemsCount('ion_' + cannonParts[i])); $('.item-creation-list:eq(1) img[src="/media/images/products/ion_' + cannonParts[i] + '.jpg"]').attr('alt', cannonParts[i]).parent().next().text(balance); } } if (/^\/politics\/congress-candidates\//.test(document.location.pathname)) { buildCongressCandidatesArticle(); } function getCongressCandidatesList() { if ($('.citizens-list li').length > 0) { congressCandidatesList = {}; $('.citizens-list li').each(function() { cit = {}; cit.cname = $(this).find('.name').text().trim(); cit.curl = $(this).find('.name a').attr('href').trim(); cit.sector = '[b]' + $(this).find('.sector').text().trim() + '[/b]'; cit.pname = $(this).find('.party').text().trim(); cit.purl = $(this).find('.party a').attr('href').trim(); if (!(cit.sector in congressCandidatesList)) { congressCandidatesList[cit.sector] = {}; } cit.bbcit = '[url=https://www.starrepublik.com' + cit.curl + ']' + cit.cname + '[/url]'; cit.bbprt = '[url=https://www.starrepublik.com' + cit.purl + ']' + cit.pname + '[/url]'; congressCandidatesList[cit.sector][cit.bbcit] = cit.bbprt; }); return congressCandidatesList; } } function buildCongressCandidatesArticle() { list = getCongressCandidatesList(); if (list) { $.each(list, function(index, value) { congressCandidatesArticle += "\n" + index + "\n"; $.each(value, function(idx, val) { congressCandidatesArticle += idx + ' - ' + val + "\n"; }); }); congressCandidatesArticle = "[center]" + congressCandidatesArticle.trim() + "[/center]"; $('.party-content > .section-header.politics').append(' [+]'); $('.citizens-list').before(""); } } $('#toggleArticle').click(function () { if ($('#congressCandidatesArticle').css('display') === 'none') { $('#congressCandidatesArticle').show(effectDelay); $('#toggleArticle').html('—'); } else { $('#congressCandidatesArticle').hide(effectDelay); $('#toggleArticle').html('+'); } }); });