Airlines Manager
unknown
javascript
4 years ago
11 kB
7
Indexable
// ==UserScript==
// @name Airline Manager
// @namespace http://tampermonkey.net/
// @version 2.1
// @description try to take over the world!
// @author You
// @match *://tycoon.airlines-manager.com/network/planning
// @grant unsafeWindow
// ==/UserScript==
(function() {
'use strict';
unsafeWindow.on = true;
const inputFields = document.createElement('div');
document.getElementById('pageContent').appendChild(inputFields);
inputFields.style.backgroundColor = 'white';
inputFields.style.position = 'fixed';
inputFields.style.top = '100px';
inputFields.style.left = '20px';
inputFields.style.boxShadow = '1px 1px 5px #111';
const ecoMinDemandLabel = document.createElement('label');
ecoMinDemandLabel.innerHTML = 'Min Economy Demand:';
ecoMinDemandLabel.style.margin = '3px 4px 3px';
ecoMinDemandLabel.width = '76px';
ecoMinDemandLabel.height = '35px';
ecoMinDemandLabel.style.fontFamily = 'Arial,Helvetica,sans-serif;';
ecoMinDemandLabel.style.fontSize = '12px';
inputFields.appendChild(ecoMinDemandLabel);
const ecoMinDemand = document.createElement('input');
ecoMinDemand.type = 'text';
ecoMinDemand.style.margin = '3px 4px 3px';
ecoMinDemand.width = '50px';
ecoMinDemand.defaultValue = 0;
inputFields.appendChild(ecoMinDemand);
ecoMinDemandLabel.setAttribute('for', ecoMinDemand);
const lb1 = document.createElement("br");
inputFields.appendChild(lb1);
const busMinDemandLabel = document.createElement('label');
busMinDemandLabel.innerHTML = 'Min Business Demand:';
busMinDemandLabel.style.margin = '3px 4px 3px';
busMinDemandLabel.width = '76px';
busMinDemandLabel.height = '35px';
busMinDemandLabel.style.fontFamily = 'Arial,Helvetica,sans-serif;';
busMinDemandLabel.style.fontSize = '12px';
inputFields.appendChild(busMinDemandLabel);
const busMinDemand = document.createElement('input');
busMinDemand.type = 'text';
busMinDemand.style.margin = '3px 4px 3px 6px';
busMinDemand.width = '50px';
busMinDemand.defaultValue = 0;
inputFields.appendChild(busMinDemand);
busMinDemandLabel.setAttribute('for', busMinDemand);
const lb2 = document.createElement("br");
inputFields.appendChild(lb2);
const firstMinDemandLabel = document.createElement('label');
firstMinDemandLabel.innerHTML = 'Min First Demand:';
firstMinDemandLabel.style.margin = '3px 4px 3px 31px';
firstMinDemandLabel.width = '76px';
firstMinDemandLabel.height = '35px';
firstMinDemandLabel.style.fontFamily = 'Arial,Helvetica,sans-serif;';
firstMinDemandLabel.style.fontSize = '12px';
inputFields.appendChild(firstMinDemandLabel);
const firstMinDemand = document.createElement('input');
firstMinDemand.type = 'text';
firstMinDemand.style.margin = '3px 4px 3px';
firstMinDemand.width = '50px';
firstMinDemand.defaultValue = 0;
inputFields.appendChild(firstMinDemand);
firstMinDemandLabel.setAttribute('for', firstMinDemand);
const lb3 = document.createElement('br');
inputFields.appendChild(lb3);
const cargoDemandLabel = document.createElement('label');
cargoDemandLabel.innerHTML = 'Min Cargo Demand:';
cargoDemandLabel.style.margin = '3px 4px 3px 22px';
cargoDemandLabel.width = '76px';
cargoDemandLabel.height = '35px';
cargoDemandLabel.style.fontFamily = 'Arial,Helvetica,sans-serif;';
cargoDemandLabel.style.fontSize = '12px';
inputFields.appendChild(cargoDemandLabel);
const cargoMinDemand = document.createElement('input');
cargoMinDemand.type = 'text';
cargoMinDemand.style.margin = '3px 4px 3px';
cargoMinDemand.width = '50px';
cargoMinDemand.defaultValue = 0;
inputFields.appendChild(cargoMinDemand);
cargoDemandLabel.setAttribute('for', cargoMinDemand);
const lb4 = document.createElement('br');
inputFields.appendChild(lb4);
const checkBox = document.createElement('input')
checkBox.type = 'checkbox';
checkBox.id = 'cargoOnly';
checkBox.style.margin = '10px 3px 2px 30px';
inputFields.appendChild(checkBox);
const label = document.createElement('label')
label.htmlFor = 'cargoOnly';
label.appendChild(document.createTextNode('Cargo Only'));
label.style.verticalAlign = 'middle';
inputFields.appendChild(label);
const setMinDemandBtn = document.createElement('button');
setMinDemandBtn.innerHTML = 'OK';
setMinDemandBtn.width = '36px';
setMinDemandBtn.style.margin = '3px 4px 3px 99px';
inputFields.appendChild(setMinDemandBtn);
setMinDemandBtn.addEventListener('click', function(e) {
const minEco = ecoMinDemand.value;
const minBus = busMinDemand.value;
const minFirst = firstMinDemand.value;
const minCargo = cargoMinDemand.value;
filterLineList(minEco, minBus, minFirst, minCargo);
});
// planning
const table = document.getElementById('demand');
table.style.width = '460px';
table.style.marginTop = '-750px';
table.style.marginRight = '0px';
table.style.backgroundColor = 'white';
table.style.position = 'fixed';
table.style.right = '10px';
table.style.bottom = '250px';
table.style.zIndex = '999';
table.style.boxShadow = '1px 1px 5px #111';
const planning = document.getElementById('planning');
planning.style.height = '290px';
planning.style.marginTop = '-300px';
planning.style.marginRight = '0px';
planning.style.backgroundColor = 'white';
planning.style.position = 'fixed';
planning.style.right = '10px';
planning.style.top = '300px';
planning.style.zIndex = '999';
planning.style.boxShadow = '1px 1px 5px #111';
const planDivToggle = document.createElement('button');
planDivToggle.innerHTML = '-';
planDivToggle.width = '15px';
planDivToggle.style.marginLeft = '5px';
planDivToggle.style.bottom = '20px';
planDivToggle.onclick = function(e) {
toggle('planning');
};
planning.insertBefore(planDivToggle, document.getElementById('planningSubmit'));
const fastScheduleBtn = document.createElement('button');
fastScheduleBtn.innerHTML = 'Deploy Planning';
fastScheduleBtn.width = '25px';
fastScheduleBtn.style.margin = '3px 8px 3px 185px';
fastScheduleBtn.style.bottom = '20px';
fastScheduleBtn.onclick = function(e) {
const currentPlane = unsafeWindow.globalThis.currentAircraft;
if (currentPlane) {
const pl = currentPlane.planningList;
const sortedPlannings = pl.sort((a, b) => a.takeOffTime - b.takeOffTime);
unsafeWindow.globalThis.oneClickPlanning.enableLineListEdition();
let lineTags = '';
unsafeWindow.globalThis.oneClickPlanning.setState('pick');
for (let m = 0; m < sortedPlannings.length; m++) {
const line = sortedPlannings[m].line;
unsafeWindow.globalThis.oneClickPlanning.addLine(line, currentPlane, 0);
lineTags += unsafeWindow.globalThis.oneClickPlanning.generateLineTag(line, m);
// unsafeWindow.globalThis.oneClickPlanning.lineList.push(line);
}
unsafeWindow.globalThis.oneClickPlanning.setState('planning');
unsafeWindow.globalThis.oneClickPlanning.disableLineListEdition();
unsafeWindow.globalThis.oneClickPlanning.refreshLineListHTML();
const fastScheduleInfo = document.getElementById('fastSchedulingInfo');
fastScheduleInfo.innerHTML = lineTags;
}
};
planning.appendChild(fastScheduleBtn);
const filterLineList = function(minEco=0, minBus=0, minFirst=0, minCargo=0) {
const allLineLists = document.getElementById('lineList').getElementsByClassName('lineId hidden');
const listManager = unsafeWindow.globalThis.lineListManager;
const lines = listManager.getFullLineList();
const filteredList = [];
for (let i = 0; i < lines.length; i++) {
const cLine = lines[i];
for (let day = 0; day < 7; day++) {
const demand = cLine.usedPaxByDay[day];
const ecoSatisfied = checkBox.checked? true : demand.eco >= minEco;
const busSatisfied = demand.bus >= minBus;
const firstSatisfied = demand.first >= minFirst;
const cargoSatisfied = demand.cargo >= minCargo;
if ( ecoSatisfied && busSatisfied && firstSatisfied && cargoSatisfied) {
// Save all green bonus eco
if (!filteredList.includes(i)) {
filteredList.push(i);
}
}
}
}
// de-opacify routes not meeting the demand requirements
for (let m = 0; m < lines.length; m++) {
const cLine = lines[m];
const id = cLine.id;
for ( let n = 0; n < allLineLists.length; n++) {
const lineBox = allLineLists[n];
const text = lineBox.textContent;
if (text === '' + id) {
const colorBox = lineBox.nextElementSibling;
colorBox.style.fontFamily = 'sans-serif';
colorBox.style.fontSize = '8px';
colorBox.style.color = 'white';
colorBox.style.display = 'flex';
colorBox.style.justifyContent = 'center';
colorBox.style.alignItems = 'center';
colorBox.innerHTML = lines[m].category; // display category name
const parentSpan = colorBox.parentNode; // for prettify purpose
parentSpan.style.display = 'inline-flex';
parentSpan.style.justifyContent = 'center';
parentSpan.style.alignItems = 'center';
if (!filteredList.includes(m)) {
allLineLists[n].parentNode.style.opacity = '0.3';
} else {
allLineLists[n].parentNode.style.opacity = '1';
}
}
}
}
}
const toggle = function(elementId) {
var ele = document.getElementById(elementId);
if(ele.style.right === '10px') {
ele.style.right = "-710px";
planDivToggle.innerHTML = '+';
}
else {
ele.style.right = "10px";
planDivToggle.innerHTML = '-';
}
}
setTimeout(function() {
let currentId = -1;
document.addEventListener('click', function(e) {
if (unsafeWindow.globalThis.currentAircraft) {
if (currentId !== unsafeWindow.globalThis.currentAircraft.id) {
currentId = unsafeWindow.globalThis.currentAircraft.id;
ecoMinDemand.value = 0;
filterLineList();
}
}
});
filterLineList();
},1400);
})();Editor is loading...