Skip to content
This repository has been archived by the owner on May 14, 2023. It is now read-only.

Commit

Permalink
Merge branch 'next-version' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
j0Shi82 committed Nov 13, 2020
2 parents d4ebc8e + 37f0ed7 commit 82d7340
Show file tree
Hide file tree
Showing 25 changed files with 1,277 additions and 525 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
dist/statistics.html
*.map
*.log
.sentryclirc
.sentryclirc
.vscode
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## v1.2.0 - 1.2.1

- **FEATURES**
- New optional addon to replace the native resource tick timer. The LWM one works more accurately in most situations and stays activated in inactive browser windows.
- Non-premium users now have access to the Save-All button, but it does not auto-fill res any longer, just provides the other values for LWM saves.
- Show custom coords for premium users on new trade page
- Disable items in the main menu if player hasn't build the corresponding buildings yet
- Change drone fleet type to be able to distinguish between colonization flights
- **BUGFIX**
- Fixed a bug that caused fleets from trade post to not get properly parsed for the calendar addon
- Fixed a bug that caused click handlers designed for inbox to fire on other pages as well
- Fixed a bug that caused the gm config to throw errors on save

## v1.1.0
- In the LWM menu there's now a button to delete the data set by the script. This can be used to wipe old data and is especially useful at the start of new rounds
- **OVERVIEW**
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ A German feedback thread can be found on the [official message board](http://for
- Security confirmations for buildings, researches, and production pages (optional)
- All arrow keys that add or remove ships or defense bulk add them when you hold the mouse button
- Resources on the main page get highlighted when running trade would exceed their storage capacity and feature a hover tooltip with additional information
- Replace native resource tick interval with one that works in inactive browser windows
- Settings page that lets you control what the script should do
- **OVERVIEW**
- Resources get added to the planets on the overview
Expand Down
4 changes: 2 additions & 2 deletions dist/last-war-manager.user.js

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "last-war-manager",
"version": "1.2.0",
"version": "1.2.1",
"description": "Some tweaking to the Last War UI and environment",
"repository": "https://github.com/j0Shi82/last-war-manager.git",
"author": "j0Shi82 <janosch.ferda@e-domizil.de>",
Expand All @@ -15,28 +15,28 @@
"@babel/core": "^7.12.3",
"@babel/plugin-transform-runtime": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"babel-loader": "^8.1.0",
"css-loader": "^5.0.0",
"eslint": "^7.12.0",
"eslint-config-airbnb-base": "^14.2.0",
"babel-loader": "^8.2.1",
"css-loader": "^5.0.1",
"eslint": "^7.13.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1",
"node-sass": "^4.14.1",
"npm-check-updates": "^9.2.2",
"sass-loader": "^10.0.4",
"node-sass": "^5.0.0",
"npm-check-updates": "^10.0.0",
"sass-loader": "^10.1.0",
"style-loader": "^2.0.0",
"webpack-cli": "^4.1.0"
"webpack-cli": "^4.2.0"
},
"dependencies": {
"@babel/runtime": "^7.12.1",
"@sentry/browser": "^5.27.1",
"dayjs": "^1.9.4",
"@babel/runtime": "^7.12.5",
"@sentry/browser": "^5.27.4",
"dayjs": "^1.9.6",
"hotkeys-js": "^3.8.1",
"jquery": "^3.5.1",
"moment": "^2.29.1",
"moment-duration-format": "^2.3.2",
"numeral": "^2.0.6",
"webpack": "^5.2.0",
"webpack-sources": "^2.0.1"
"webpack": "^5.4.0",
"worker-timers": "^7.0.5"
},
"resolutions": {
"serialize-javascript": "^3.1.0",
Expand Down
20 changes: 15 additions & 5 deletions src/addons/fleetActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@ import config from 'config/lwmConfig';
import { getActiveObs, setDataForClocks } from 'utils/helper';
import { createElementFromHTML, docQuery } from 'utils/domHelper';
import { convertSecondsToHHMMSS, dayjs } from 'utils/dateHelper';
import * as workerTimers from 'worker-timers';
// import moment from 'moment';

const { document } = siteWindow;

let fleetRefreshInterval = null;

const killFleetActivityTimer = () => {
if (fleetRefreshInterval !== null) {
workerTimers.clearInterval(fleetRefreshInterval);
fleetRefreshInterval = null;
}
};

export { killFleetActivityTimer };

export default async (page) => {
// no fleet config set, return
if (
Expand Down Expand Up @@ -56,7 +66,7 @@ export default async (page) => {
&& (elementStatusValue === statusFilterValue || statusFilterValue === '');
if (showRow) el.classList.remove('lwm-hide');
// hide drones if excluded and not directly selected
if (gmConfig.get('addon_fleet_exclude_drones') && typeFilterValue !== '4' && elementTypeValue === '4') {
if (gmConfig.get('addon_fleet_exclude_drones') && typeFilterValue !== '6' && elementTypeValue === '6') {
el.classList.add('lwm-hide');
}
});
Expand Down Expand Up @@ -221,19 +231,19 @@ export default async (page) => {

config.gameData.fleetInfo.all_informations.forEach((fleetData) => {
// add missing info for drones
fleetData.Type = '4'; fleetData.Status = '1';
fleetData.Type = '6'; fleetData.Status = '1';
filter.add(fleetData);
fleetRowElements.push(createElementFromHTML(`<tr class="lwm-hideable lwm-fleet" data-type="${fleetData.Type || ''}" data-status="${fleetData.Status || ''}" data-coords="${fleetData.homePlanet}"><td>${iconDrone}Eigene ${fleetData.name} von Planet <b>${fleetData.homePlanet}</b> ist unterwegs nach ( <b>${fleetData.galaxy}x${fleetData.system}</b> )</td><td>${fleetData.time}</td><td id='clock_${fleetData.clock_id}'>${getFleetTimerString(fleetData.time)}</td></tr>`));
});

config.gameData.fleetInfo.dron_observationens.forEach((fleetData) => {
fleetData.Type = '4'; fleetData.Status = '1';
fleetData.Type = '6'; fleetData.Status = '1';
filter.add(fleetData);
fleetRowElements.push(createElementFromHTML(`<tr class="lwm-hideable lwm-fleet" data-type="${fleetData.Type || ''}" data-status="${fleetData.Status || ''}" data-coords="${fleetData.homePlanet}"><td>${iconDrone}Eigene ${fleetData.name} von Planet <b>${fleetData.homePlanet}</b> ist unterwegs nach ( <b>${fleetData.galaxy}x${fleetData.system}x${fleetData.planet}</b> )</td><td>${fleetData.time}</td><td id='clock_${fleetData.clock_id}'>${getFleetTimerString(fleetData.time)}</td></tr>`));
});

config.gameData.fleetInfo.dron_planetenscanners.forEach((fleetData) => {
fleetData.Type = '4'; fleetData.Status = '1';
fleetData.Type = '6'; fleetData.Status = '1';
filter.add(fleetData);
fleetRowElements.push(createElementFromHTML(`<tr class="lwm-hideable lwm-fleet" data-type="${fleetData.Type || ''}" data-status="${fleetData.Status || ''}" data-coords="${fleetData.homePlanet}"><td>${iconDrone}Eigene ${fleetData.name} von Planet <b>${fleetData.homePlanet}</b> ist unterwegs nach ( <b>${fleetData.galaxy}x${fleetData.system}x${fleetData.planet}</b> )</td><td>${fleetData.time}</td><td id='clock_${fleetData.clock_id}'>${getFleetTimerString(fleetData.time)}</td></tr>`));
});
Expand Down Expand Up @@ -376,7 +386,7 @@ export default async (page) => {

// add refresh interval
if (fleetRefreshInterval === null) {
fleetRefreshInterval = setInterval(() => {
fleetRefreshInterval = workerTimers.setInterval(() => {
getFlottenbewegungenInfo();
}, 30000);
}
Expand Down
71 changes: 34 additions & 37 deletions src/addons/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import {
gmConfig, siteWindow, lwmJQ, gmSetValue, gmGetValue,
} from 'config/globals';
import { getObsInfo, getSpionageInfo, getFlottenbewegungenInfo } from 'utils/requests';
import config from 'config/lwmConfig';
import {
throwError, getIncomingResArray,
} from 'utils/helper';
getObsInfo, getSpionageInfo, getFlottenbewegungenInfo, getTradeOffers,
} from 'utils/requests';
import config from 'config/lwmConfig';
import { getIncomingResArray } from 'utils/helper';
import moment from 'moment';
import momentDurationFormatSetup from 'moment-duration-format';
import driveManager from 'plugins/driveManager';
import * as workerTimers from 'worker-timers';

import showFleetActivityGlobally from 'addons/fleetActivity';
import showFleetActivityGlobally, { killFleetActivityTimer } from 'addons/fleetActivity';
import addCustomResourceCounter from 'addons/resourceTicks';

momentDurationFormatSetup(moment);

Expand All @@ -21,6 +23,8 @@ const addOns = {
tradeRefreshInterval: null,
capacityRefreshInterval: null,
clockInterval: null,
resourceIntervals: null,
clockIntervalTime: new Date(),
},
load() {
if (gmConfig.get('addon_fleet') && config.loadStates.lastLoadedPage !== 'flottenbewegungen') {
Expand All @@ -35,43 +39,31 @@ const addOns = {

addOns.refreshTrades();
if (gmConfig.get('addon_clock')) addOns.addClockInterval();
if (gmConfig.get('res_updates') && addOns.config.resourceIntervals === null) {
addOns.config.resourceIntervals = addOns.addCustomResourceCounter();
}
},
unload() {
killFleetActivityTimer();
if (addOns.config.capacityRefreshInterval !== null) {
clearInterval(addOns.config.capacityRefreshInterval);
workerTimers.clearInterval(addOns.config.capacityRefreshInterval);
addOns.config.capacityRefreshInterval = null;
}
if (addOns.config.clockInterval !== null) { clearInterval(addOns.config.clockInterval); addOns.config.clockInterval = null; }
if (addOns.config.clockInterval !== null) { workerTimers.clearInterval(addOns.config.clockInterval); addOns.config.clockInterval = null; }
if (addOns.config.resourceIntervals !== null) {
addOns.config.resourceIntervals();
addOns.config.resourceCounter = null;
}
},
// refresh trades every minute to make it unnecessary to visit the trade page for trade to go through
refreshTrades() {
const requestTrades = () => {
const uriData = `galaxy_check=${config.gameData.planetCoords.galaxy}&system_check=${config.gameData.planetCoords.system}&planet_check=${config.gameData.planetCoords.planet}`;
siteWindow.jQuery.ajax({
url: `/ajax_request/get_trade_offers.php?${uriData}`,
data: { lwm_ignoreProcess: 1 },
timeout: config.promises.interval.ajaxTimeout,
success: (data) => {
if (data === '500' || typeof data.resource === 'undefined') return;
siteWindow.Roheisen = parseInt(data.resource.Roheisen, 10);
siteWindow.Kristall = parseInt(data.resource.Kristall, 10);
siteWindow.Frubin = parseInt(data.resource.Frubin, 10);
siteWindow.Orizin = parseInt(data.resource.Orizin, 10);
siteWindow.Frurozin = parseInt(data.resource.Frurozin, 10);
siteWindow.Gold = parseInt(data.resource.Gold, 10);
},
error() { throwError(); },
dataType: 'json',
});
};

// always refresh trades once after login or planet change
if (config.firstLoad) requestTrades();
if (config.firstLoad) getTradeOffers();

// refresh interval
if (addOns.config.tradeRefreshInterval !== null) return; // allready installed
addOns.config.tradeRefreshInterval = setInterval(() => {
requestTrades();
addOns.config.tradeRefreshInterval = workerTimers.setInterval(() => {
getTradeOffers();
}, 60000);
},
// checks whether trades would surpass resource capacities and highlights a warning
Expand All @@ -89,27 +81,31 @@ const addOns = {

// add invterval
if (addOns.config.capacityRefreshInterval === null) {
addOns.config.capacityRefreshInterval = setInterval(() => {
addOns.config.capacityRefreshInterval = workerTimers.setInterval(() => {
addOns.checkCapacities();
}, 10000);
}
},
addClockInterval() {
if (addOns.config.clockInterval !== null) return;
addOns.config.clockInterval = setInterval(() => {
addOns.config.clockIntervalTime = new Date();
addOns.config.clockInterval = workerTimers.setInterval(() => {
const now = new Date();
const deltaTime = (now - addOns.config.clockIntervalTime) / 1000;
addOns.config.clockIntervalTime = now;
lwmJQ('[id*=\'clock\'],[id*=\'Clock\']').each((i, el) => {
const self = lwmJQ(el);
// skip elements that don't have data attribute
if (typeof self.data('clock_seconds') === 'undefined') return true;

const data = parseInt(self.data('clock_seconds'), 10) - 1;
const data = parseFloat(self.data('clock_seconds')) - deltaTime;
self.data('clock_seconds', data);
if (data < 0) {
self.html('--:--:--');
} else {
const md = moment.duration(data, 'seconds');
const md = moment.duration(parseInt(data, 10), 'seconds');
self
.attr('title', moment().add(data, 'seconds').format('YYYY-MM-DD HH:mm:ss'))
.attr('title', moment().add(parseInt(data, 10), 'seconds').format('YYYY-MM-DD HH:mm:ss'))
.addClass('popover')
.html(md.format('HH:mm:ss', {
trim: false,
Expand All @@ -122,6 +118,7 @@ const addOns = {
}, 1000);
},
showFleetActivityGlobally,
addCustomResourceCounter,
calendar: {
storeOverview(data) {
const dataBuildingBefore = JSON.stringify(addOns.calendar.getData('building', config.gameData.playerID));
Expand Down Expand Up @@ -173,7 +170,7 @@ const addOns = {
const dataResearchAfter = JSON.stringify(addOns.calendar.getData('research', config.gameData.playerID));

gmSetValue('lwm_calendar', JSON.stringify(config.lwm.calendar));
if (gmConfig.get('confirm_drive_sync') && (!addOns.calendar.truncateData() || dataResearchBefore !== dataResearchAfter || dataBuildingBefore !== dataBuildingAfter)) driveManager.save();
if ((!addOns.calendar.truncateData() || dataResearchBefore !== dataResearchAfter || dataBuildingBefore !== dataBuildingAfter) && gmConfig.get('confirm_drive_sync')) driveManager.save();
},
storeFleets(data) {
const lang = config.const.lang.fleet;
Expand All @@ -197,7 +194,7 @@ const addOns = {
type: 'fleet',
name: fleetData.id || 0,
duration: 0,
text: `Flotte Typ ${lang.types[fleetData.Type] || fleetData.name} mit Status ${lang.status[fleetData.Status || 1]} und Coords ${fleetData.Galaxy_send || fleetData.galaxy}x${fleetData.System_send || fleetData.system}x${fleetData.Planet_send || fleetData.planet}`,
text: `Flotte Typ ${lang.types[fleetData.Type] || fleetData.name || 'Handelsposten'} mit Status ${lang.status[fleetData.Status || 1]} und Coords ${fleetData.Galaxy_send || fleetData.galaxy || siteWindow.my_galaxy}x${fleetData.System_send || fleetData.system || siteWindow.my_system}x${fleetData.Planet_send || fleetData.planet || siteWindow.my_planet}`,
ts: moment(time).valueOf(),
});
return true;
Expand Down

0 comments on commit 82d7340

Please sign in to comment.