NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name wofh report (streams) // @namespace https://*.waysofhistory.com/game // @include https://*.waysofhistory.com/gen/html* // @version 1.03 // @description City's streams report. Not approved by wofh admins. // @grant none // @license MIT // @updateURL https://openuserjs.org/meta/ArtanoMayarov/wofh_report_(streams).meta.js // @downloadURL https://openuserjs.org/install/ArtanoMayarov/wofh_report_(streams).user.js // @copyright 2019, ArtanoMayarov (https://openuserjs.org/users/ArtanoMayarov) // ==/UserScript== const changeBg = () => { const bg = localStorage.getItem('bg'); if (bg) document.body.style.background = `url(${bg}) no-repeat`; }; document.addEventListener('dragover', evt => { evt.preventDefault(); }); document.addEventListener('drop', evt => { evt.preventDefault(); const file = evt.dataTransfer.files[0]; const reader = new FileReader(); reader.addEventListener('load', () => { localStorage.setItem('bg', reader.result); changeBg(); }); if (file) reader.readAsDataURL(file); }); changeBg(); function createReport() { var bonus = wofh.town.getLuckBonus(3).level; document.querySelector('.messages-write-text').value += ` *** City's report [t${wofh.town.id}] *** Streams: \r\n${Object.values(wofh.streams.getTownStreams().getList()) .map(el => ` [t${el.town1}] -> [t${el.town2}]: ${el.count_} ${Resource.lib[el.res].name} traders ${el.traders} acceleration ${Resource.lib[el.fuel].name} ${el.traders*(el.path | 0)}`) .join('\r\n')} Population: ${wofh.town.pop.has | 0}/${wofh.town.pop.culture} ${wofh.town.pop .incReal >= 0 ? '+' : '-'} ${Math.abs(Math.round(wofh.town.pop.incReal))} Workers distribution: ${Object.values(wofh.town.calcPopOnRes().list) .sort((a, b) => b.count - a.count) .map(el => `${Resource.lib[el.id].name} - ${el.count}`) .join(', ')}, Unemployed - ${(wofh.town.pop.has - wofh.town.calcPopOnRes().calcSum()) | 0} Resource production: ${Object.values(wofh.town.stock.list) .filter(el => el.incom > 0 && el.id !== 2) .sort((a, b) => b.incom - a.incom) .map(el => `${Resource.lib[el.id].name} - ${el.incom | 0}`) .join(', ')} Resource consumption: ${Object.values(wofh.town.stock.getConsBinList().list) .map(el => Resource.lib[el.id].name) .join(', ')} Industry LC bonus: ${bonus * 10} % [Buildings] ${Object.values(wofh.town.buildings) .filter(el => el[0] !== 500) .map(el => `[b${el[0]}] lvl ${el[1]}`) .join('\n')} `; document.querySelector('.messages-write-text').value = JSON.stringify(document.querySelector('.messages-write-text').value); } function calcCost() { alert( `Destruction durability: ${Object.values(wofh.town.slots.list) .filter(el => el.build.cost && !Build.isWonder(el.id)) .map(el => el.calcTotalCost().list) .reduce( (acc, el) => acc + Object.values(el) .map(el => el.count) .reduce((total, num) => num + total, 0), 0 ) .toLocaleString('ru-RU')}` ); } function StreamsReport() { var PlayerData = new Array( {Streams: wofh.streams.getTownStreams().getList()}, // {Buildings: wofh.town.buildings}, // {Population: wofh.town.pop}, // {WorkersDistribution: wofh.town.calcPopOnRes().list}, ); //document.querySelector('.messages-write-text').value = JSON.stringify(PlayerData); window.open("", wofh.town.name).document.write(JSON.stringify(PlayerData)) } var bReport = document.createElement('button'); bReport.className = "button1 btn-Report"; bReport.setAttribute('style', 'position: absolute; top: 0; right: 110px'); bReport.textContent = "City's report"; bReport.addEventListener('click', createReport); var bCalc = document.createElement('button'); bCalc.className = "button1 btn-Calc"; bCalc.setAttribute('style', 'position: absolute; top: 0; right: 220px'); bCalc.textContent = "Durability"; bCalc.addEventListener('click', calcCost); var bStreams = document.createElement('button'); bStreams.className = "button1 btn-Streams"; bStreams.setAttribute('style', 'position: absolute; top: 0; right: 330px'); bStreams.textContent = "Streams"; bStreams.addEventListener('click', StreamsReport); document.addEventListener('click', evt => { if (document.querySelector('.messages-write-form') !== null && document.querySelector('.messages-write-form').length > 0) { if (document.querySelector('.btn-Streams') === null) { document.querySelector('.messages-write-footer').insertBefore(bStreams, document.querySelector('.messages-write-chrCount')); } if (document.querySelector('.btn-Report') === null) { document.querySelector('.messages-write-footer').insertBefore(bReport, document.querySelector('.messages-write-chrCount')); } if (document.querySelector('.btn-Calc') === null) { document.querySelector('.messages-write-footer').insertBefore(bCalc, document.querySelector('.messages-write-chrCount')); } } }); document.addEventListener('keydown', evt => { if (evt.keyCode === 49 && evt.ctrlKey && evt.altKey) { createReport(); } if (evt.keyCode === 48 && evt.ctrlKey && evt.altKey) { calcCost(); } });