spaghetti's fixes
This commit is contained in:
parent
6aaf98a693
commit
10270d0af9
|
@ -8,22 +8,20 @@ let lastClaimTime = Date.now();
|
|||
|
||||
let injectionPort;
|
||||
|
||||
chrome.runtime.onConnectExternal.addListener(function(port) {
|
||||
chrome.runtime.onConnectExternal.addListener(port => {
|
||||
injectionPort = port;
|
||||
|
||||
injectionPort.onMessage.addListener(function(message) {
|
||||
injectionPort.onMessage.addListener(message => {
|
||||
if (message.action == 'endClaimAll') {
|
||||
onEndClaimAll();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function getClaimOptionLength(option) {
|
||||
return [0, 10, 40, 3 * 60, 8 * 60][option] * 60 * 1000;
|
||||
}
|
||||
let getClaimOptionLength = option => [0, 10, 40, 3 * 60, 8 * 60][option] * 60 * 1000;
|
||||
|
||||
function updateBrowserActionStatus() {
|
||||
chrome.tabs.query({ url: '*://*.grepolis.com/game/index*' }, function(tabs) {
|
||||
chrome.tabs.query({ url: '*://*.grepolis.com/game/index*' }, tabs => {
|
||||
if (tabs.length == 0) {
|
||||
chrome.browserAction.disable();
|
||||
|
||||
|
@ -39,8 +37,8 @@ chrome.tabs.onCreated.addListener(updateBrowserActionStatus);
|
|||
chrome.tabs.onUpdated.addListener(updateBrowserActionStatus);
|
||||
chrome.tabs.onRemoved.addListener(updateBrowserActionStatus);
|
||||
|
||||
chrome.browserAction.onClicked.addListener(function() {
|
||||
chrome.tabs.query({ url: '*://*.grepolis.com/game/index*' }, function(tabs) {
|
||||
chrome.browserAction.onClicked.addListener(() => {
|
||||
chrome.tabs.query({ url: '*://*.grepolis.com/game/index*' }, tabs => {
|
||||
if (tabs.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -68,7 +66,10 @@ function onEndClaimAll() {
|
|||
|
||||
lastClaimTime = Date.now();
|
||||
if (state == 'automatic') {
|
||||
autoClaimTimeout = setTimeout(function() { claimAll(autoClaimOption); }, getClaimOptionLength(autoClaimOption));
|
||||
autoClaimTimeout = setTimeout(
|
||||
() => claimAll(autoClaimOption),
|
||||
getClaimOptionLength(autoClaimOption)
|
||||
);
|
||||
}
|
||||
|
||||
updateBadgeText();
|
||||
|
@ -105,7 +106,7 @@ function claimAllWhenReady(option) {
|
|||
let lastClaimLength = getClaimOptionLength(lastClaimOption);
|
||||
let timeLeft = lastClaimLength - timeSinceClaim;
|
||||
|
||||
setTimeout(function() { claimAll(option); }, timeLeft);
|
||||
setTimeout(() => claimAll(option), timeLeft);
|
||||
}
|
||||
|
||||
function updateState(newState) {
|
||||
|
@ -115,9 +116,7 @@ function updateState(newState) {
|
|||
let timeSinceClaim = Date.now() - lastClaimTime;
|
||||
let lastClaimLength = getClaimOptionLength(lastClaimOption);
|
||||
let timeLeft = lastClaimLength - timeSinceClaim;
|
||||
setTimeout(function() {
|
||||
claimAll(autoClaimOption);
|
||||
}, timeLeft);
|
||||
setTimeout(() => claimAll(autoClaimOption), timeLeft);
|
||||
|
||||
chrome.browserAction.setBadgeBackgroundColor({ color: 'green' });
|
||||
} else if (newState == 'manual') {
|
||||
|
@ -135,7 +134,7 @@ chrome.contextMenus.create({
|
|||
type: 'radio',
|
||||
title: 'Automatic',
|
||||
contexts: ['browser_action'],
|
||||
onclick: function() { updateState('automatic'); }
|
||||
onclick: () => updateState('automatic')
|
||||
});
|
||||
|
||||
chrome.contextMenus.create({
|
||||
|
@ -143,35 +142,35 @@ chrome.contextMenus.create({
|
|||
type: 'radio',
|
||||
title: 'Manual',
|
||||
contexts: ['browser_action'],
|
||||
onclick: function() { updateState('manual'); }
|
||||
onclick: () => updateState('manual')
|
||||
});
|
||||
|
||||
chrome.contextMenus.create({
|
||||
type: 'normal',
|
||||
title: 'Claim for 10m',
|
||||
contexts: ['browser_action'],
|
||||
onclick: function() { updateState('manual'); claimAllWhenReady(1); }
|
||||
onclick: () => { updateState('manual'); claimAllWhenReady(1); }
|
||||
});
|
||||
|
||||
chrome.contextMenus.create({
|
||||
type: 'normal',
|
||||
title: 'Claim for 40m',
|
||||
contexts: ['browser_action'],
|
||||
onclick: function() { updateState('manual'); claimAllWhenReady(2); }
|
||||
onclick: () => { updateState('manual'); claimAllWhenReady(2); }
|
||||
});
|
||||
|
||||
chrome.contextMenus.create({
|
||||
type: 'normal',
|
||||
title: 'Claim for 3h',
|
||||
contexts: ['browser_action'],
|
||||
onclick: function() { updateState('manual'); claimAllWhenReady(3); }
|
||||
onclick: () => { updateState('manual'); claimAllWhenReady(3); }
|
||||
});
|
||||
|
||||
chrome.contextMenus.create({
|
||||
type: 'normal',
|
||||
title: 'Claim for 8h',
|
||||
contexts: ['browser_action'],
|
||||
onclick: function() { updateState('manual'); claimAllWhenReady(4); }
|
||||
onclick: () => { updateState('manual'); claimAllWhenReady(4); }
|
||||
});
|
||||
|
||||
updateBrowserActionStatus();
|
||||
|
|
30
injection.js
30
injection.js
|
@ -1,8 +1,6 @@
|
|||
let extensionPort;
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms + (Math.random() * 2.5 * 1000)));
|
||||
}
|
||||
let sleep = ms => new Promise(resolve => setTimeout(resolve, ms + (Math.random() * 2.5 * 1000)));
|
||||
|
||||
function townSwitch(townId) {
|
||||
let TownSwitch = require('helpers/town_switch');
|
||||
|
@ -18,17 +16,11 @@ function toCityOverview() {
|
|||
$.Observer(GameEvents.ui.bull_eye.radiobutton.city_overview.click).publish();
|
||||
}
|
||||
|
||||
function getCurrentTown() {
|
||||
return MM.getCollections().Town[0].getCurrentTown();
|
||||
}
|
||||
let getCurrentTown = () => MM.getCollections().Town[0].getCurrentTown();
|
||||
|
||||
function getAllTownIds() {
|
||||
return MM.getCollections().Town[0].models.map(m => m.id);
|
||||
}
|
||||
let getAllTownIds = () => MM.getCollections().Town[0].models.map(m => m.id);
|
||||
|
||||
function getPlayerGods() {
|
||||
return MM.getModels().PlayerGods[Game.player_id];
|
||||
}
|
||||
let getPlayerGods = () => MM.getModels().PlayerGods[Game.player_id];
|
||||
|
||||
//example: getTownResource.call(getCurrentTown(), 'stone')
|
||||
//NOTE: Unused function
|
||||
|
@ -36,13 +28,9 @@ function getTownResource(resource) {
|
|||
return this.resources.getResource(resource);
|
||||
}
|
||||
|
||||
function getFarmTownPlayerRelation(farmTownId) {
|
||||
return MM.getCollections().FarmTownPlayerRelation[0].getRelationForFarmTown(farmTownId);
|
||||
}
|
||||
let getFarmTownPlayerRelation = farmTownId => MM.getCollections().FarmTownPlayerRelation[0].getRelationForFarmTown(farmTownId);
|
||||
|
||||
function getCurrentTownFarmTownIds() {
|
||||
return MM.getCollections().FarmTown[0].getAllForIslandViaXY(getCurrentTown().getIslandX(), getCurrentTown().getIslandY()).map(f => f.id);
|
||||
}
|
||||
let getCurrentTownFarmTownIds = () => MM.getCollections().FarmTown[0].getAllForIslandViaXY(getCurrentTown().getIslandX(), getCurrentTown().getIslandY()).map(f => f.id);
|
||||
|
||||
function claimResources(farmTownId, option, success, error) {
|
||||
let farmTownPlayerRelation = getFarmTownPlayerRelation(farmTownId);
|
||||
|
@ -95,8 +83,8 @@ async function claimAll(option) {
|
|||
claimResources(
|
||||
farmTownId,
|
||||
option,
|
||||
function() { },
|
||||
function() { console.log('Couldn\'t claim farm town ' + farmTownId + ' for town ' + townId + '!') }
|
||||
() => { },
|
||||
() => console.log(`Couldn't claim farm town ${farmTownId} for town ${townId} !`)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +98,7 @@ async function claimAll(option) {
|
|||
}
|
||||
|
||||
extensionPort = chrome.runtime.connect(extensionId);
|
||||
extensionPort.onMessage.addListener(function(message) {
|
||||
extensionPort.onMessage.addListener(message => {
|
||||
if (message.action == 'claimAll') {
|
||||
claimAll(message.args[0]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue