From 43238e26c96f3d2474018319f027be821c69f83f Mon Sep 17 00:00:00 2001 From: Andrea Reina Date: Sat, 15 Sep 2018 15:06:02 +0800 Subject: [PATCH 1/8] Don't rerender infinite turkimp time --- main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 6a95dad0..128218b5 100644 --- a/main.js +++ b/main.js @@ -12339,7 +12339,8 @@ function updateTurkimpTime() { var timeRemaining = game.global.turkimpTimer; var elem = document.getElementById("turkimpTime"); if (game.talents.turkimp4.purchased){ - elem.innerHTML = ""; + if (!elem.querySelector('.icomoon.icon-infinity')) + elem.innerHTML = ""; return; } if (timeRemaining <= 0) { From e58d06bdefaa95cb53fb13a98b70205d4a2ed631 Mon Sep 17 00:00:00 2001 From: Andrea Reina Date: Sat, 15 Sep 2018 15:15:39 +0800 Subject: [PATCH 2/8] Change .innerHTML -> .textContent where HTML isn't needed --- main.js | 2 +- updates.js | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/main.js b/main.js index 128218b5..6e8e7c75 100644 --- a/main.js +++ b/main.js @@ -3662,7 +3662,7 @@ function breed() { if (remainingTime == 0.0) updateGenes = true; } - document.getElementById("trimpsTimeToFill").innerHTML = (fullBreed) ? fullBreed : ""; + document.getElementById("trimpsTimeToFill").textContent = (fullBreed) ? fullBreed : ""; if (updateGenes || (!game.global.fighting && totalTimeText == "0.0")){ updateStoredGenInfo(breeding.toNumber()); } diff --git a/updates.js b/updates.js index f605f371..fbe61943 100644 --- a/updates.js +++ b/updates.js @@ -3503,13 +3503,13 @@ function updateLabels() { //Tried just updating as something changes, but seems toUpdate.owned = parseFloat(toUpdate.owned); if (!(toUpdate.owned > 0)) toUpdate.owned = 0; } - document.getElementById(item + "Owned").innerHTML = prettify(Math.floor(toUpdate.owned)); + document.getElementById(item + "Owned").textContent = prettify(Math.floor(toUpdate.owned)); if (toUpdate.max == -1 || document.getElementById(item + "Max") === null) continue; var newMax = toUpdate.max; if (item != "trimps") newMax = calcHeirloomBonus("Shield", "storageSize", (newMax * (game.portal.Packrat.modifier * game.portal.Packrat.level + 1))); else if (item == "trimps") newMax = toUpdate.realMax(); - document.getElementById(item + "Max").innerHTML = prettify(newMax); + document.getElementById(item + "Max").textContent = prettify(newMax); var bar = document.getElementById(item + "Bar"); if (game.options.menu.progressBars.enabled){ var percentToMax = ((toUpdate.owned / newMax) * 100); @@ -3527,12 +3527,12 @@ function updateLabels() { //Tried just updating as something changes, but seems unlockBuilding(itemA); elem = document.getElementById(itemA + "Owned"); } - elem.innerHTML = (game.options.menu.menuFormatting.enabled) ? prettify(toUpdate.owned) : toUpdate.owned; + elem.textContent = (game.options.menu.menuFormatting.enabled) ? prettify(toUpdate.owned) : toUpdate.owned; if (itemA == "Trap") { var trap1 = document.getElementById("trimpTrapText") - if (trap1) trap1.innerHTML = prettify(toUpdate.owned); + if (trap1) trap1.textContent = prettify(toUpdate.owned); var trap2 = document.getElementById("trimpTrapText2") - if (trap2) trap2.innerHTML = prettify(toUpdate.owned); + if (trap2) trap2.textContent = prettify(toUpdate.owned); } } //Jobs, check PS here and stuff. Trimps per second is handled by breed() function @@ -3545,7 +3545,7 @@ function updateLabels() { //Tried just updating as something changes, but seems continue; } if (document.getElementById(itemB) === null) unlockJob(itemB); - document.getElementById(itemB + "Owned").innerHTML = (game.options.menu.menuFormatting.enabled) ? prettify(toUpdate.owned) : toUpdate.owned; + document.getElementById(itemB + "Owned").textContent = (game.options.menu.menuFormatting.enabled) ? prettify(toUpdate.owned) : toUpdate.owned; var perSec = (toUpdate.owned * toUpdate.modifier); updatePs(toUpdate, false, itemB); } @@ -3565,7 +3565,7 @@ function updateLabels() { //Tried just updating as something changes, but seems var toUpdate = game.equipment[itemD]; if (toUpdate.locked == 1) continue; if (document.getElementById(itemD) === null) drawAllEquipment(); - document.getElementById(itemD + "Owned").innerHTML = toUpdate.level; + document.getElementById(itemD + "Owned").textContent = toUpdate.level; } } @@ -3642,14 +3642,14 @@ function updatePs(jobObj, trimps, jobName){ //trimps is true/false, send PS as f function updateSideTrimps(){ var trimps = game.resources.trimps; - document.getElementById("trimpsEmployed").innerHTML = prettify(trimps.employed); + document.getElementById("trimpsEmployed").textContent = prettify(trimps.employed); var breedCount = (trimps.owned - trimps.employed > 2) ? prettify(Math.floor(trimps.owned - trimps.employed)) : 0; - document.getElementById("trimpsUnemployed").innerHTML = breedCount; - document.getElementById("maxEmployed").innerHTML = prettify(Math.ceil(trimps.realMax() / 2)); + document.getElementById("trimpsUnemployed").textContent = breedCount; + document.getElementById("maxEmployed").textContent = prettify(Math.ceil(trimps.realMax() / 2)); var free = (Math.ceil(trimps.realMax() / 2) - trimps.employed); if (free < 0) free = 0; var s = (free > 1) ? "s" : ""; - document.getElementById("jobsTitleUnemployed").innerHTML = prettify(free) + " workspace" + s; + document.getElementById("jobsTitleUnemployed").textContent = prettify(free) + " workspace" + s; } function unlockBuilding(what) { From 21c1526b6991e8489aca7224cf4e18a9df8686b2 Mon Sep 17 00:00:00 2001 From: Andrea Reina Date: Sat, 15 Sep 2018 15:29:40 +0800 Subject: [PATCH 3/8] Speedify updateAllBattleNumbers --- main.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 6e8e7c75..0807fe69 100644 --- a/main.js +++ b/main.js @@ -8377,11 +8377,11 @@ function updateAllBattleNumbers (skipNum) { document.getElementById("goodGuyHealthMax").innerHTML = prettify(game.global.soldierHealthMax); updateGoodBar(); updateBadBar(cell); - document.getElementById("badGuyHealthMax").innerHTML = prettify(cell.maxHealth); - if (!skipNum && game.global.challengeActive == "Trimp" && game.jobs.Amalgamator.owned > 0) document.getElementById("trimpsFighting").innerHTML = toZalgo(prettify(game.resources.trimps.getCurrentSend()), game.global.world); - else if (!skipNum) document.getElementById("trimpsFighting").innerHTML = prettify(game.resources.trimps.getCurrentSend()); - document.getElementById("goodGuyBlock").innerHTML = prettify(game.global.soldierCurrentBlock); - document.getElementById("goodGuyAttack").innerHTML = calculateDamage(game.global.soldierCurrentAttack, true, true); + document.getElementById("badGuyHealthMax").textContent = prettify(cell.maxHealth); + if (!skipNum && game.global.challengeActive == "Trimp" && game.jobs.Amalgamator.owned > 0) document.getElementById("trimpsFighting").textContent = toZalgo(prettify(game.resources.trimps.getCurrentSend()), game.global.world); + else if (!skipNum) document.getElementById("trimpsFighting").textContent = prettify(game.resources.trimps.getCurrentSend()); + document.getElementById("goodGuyBlock").textContent = prettify(game.global.soldierCurrentBlock); + document.getElementById("goodGuyAttack").textContent = calculateDamage(game.global.soldierCurrentAttack, true, true); var badAttackElem = document.getElementById("badGuyAttack"); badAttackElem.innerHTML = calculateDamage(cell.attack, true, false, false, cell); if (game.global.usingShriek) { From b103fecd646d4613e3122d78b4e35747fbc20e9b Mon Sep 17 00:00:00 2001 From: Andrea Reina Date: Sat, 15 Sep 2018 16:42:57 +0800 Subject: [PATCH 4/8] Speedify updateAntiStacks --- main.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 0807fe69..95394167 100644 --- a/main.js +++ b/main.js @@ -11347,7 +11347,17 @@ function updateAntiStacks(){ number = Math.floor(number * 100); var verb = game.jobs.Amalgamator.owned > 0 ? "prepare" : "populate"; var s = game.global.antiStacks == 1 ? '' : 's'; - elem.innerHTML = '' + game.global.antiStacks + ''; + var span = elem.querySelector('span.badge.antiBadge'); + var antiTooltip = function(event){tooltip('Anticipation', 'customText', event, 'Your Trimps are dealing ' + number + '% extra damage for taking ' + game.global.antiStacks + ' second' + s + ' to ' + verb + '.');}; + var hideTooltip = function() {tooltip('hid');}; + if (span) { + span.onmouseover = antiTooltip; + span.onmouseout = hideTooltip; + if (game.global.antistacks) + span.childNodes[0].textContent = game.global.antistacks.toString(); + } else { + elem.innerHTML = '' + game.global.antiStacks + ''; + } } else elem.innerHTML = ""; } From 481be82b11466ba160f76717ca5b8ce93c06e7a3 Mon Sep 17 00:00:00 2001 From: Andrea Reina Date: Sat, 15 Sep 2018 18:04:28 +0800 Subject: [PATCH 5/8] Speedify drawAllUpgrades Appending to .innerHTML in a loop causes a parse every loop iteration, which is slow. Instead we accumulate the HTML strings and assign it to .innerHTML in one go so that parsing just happens once. This replaces the need for drawUpgrade(), so I've removed it as well. --- updates.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/updates.js b/updates.js index fbe61943..ed01e18c 100644 --- a/updates.js +++ b/updates.js @@ -3810,22 +3810,24 @@ function unlockUpgrade(what, displayOnly) { function drawAllUpgrades(){ var elem = document.getElementById("upgradesHere"); - elem.innerHTML = ""; + // Batch all HTML manipulation into one operation to save on the parsing + elem.innerHTML = Object.keys(game.upgrades) + .filter(what => game.upgrades[what].locked != 1) + .map(upgradeDivHTML) + .join(''); for (var item in game.upgrades){ if (game.upgrades[item].locked == 1) continue; - drawUpgrade(item, elem); if (game.upgrades[item].alert && game.options.menu.showAlerts.enabled){ - document.getElementById("upgradesAlert").innerHTML = "!"; - if (document.getElementById(item + "Alert")) document.getElementById(item + "Alert").innerHTML = "!"; + document.getElementById("upgradesAlert").textContent = "!"; + if (document.getElementById(item + "Alert")) document.getElementById(item + "Alert").textContent = "!"; } } goldenUpgradesShown = false; displayGoldenUpgrades(); } - - -function drawUpgrade(what, where){ +function upgradeDivHTML(what) { + div = document.createElement('div'); var upgrade = game.upgrades[what]; if (upgrade.prestiges && (!upgrade.cost.resources[metal] || !upgrade.cost.resources[wood])){ var resName = (what == "Supershield") ? "wood" : "metal"; @@ -3834,10 +3836,11 @@ function drawUpgrade(what, where){ var done = upgrade.done; var dif = upgrade.allowed - done; if (dif >= 1) dif -= 1; - where.innerHTML += '
' + what + '
' + done + '
'; - if (dif >= 1) document.getElementById(what + "Owned").innerHTML = upgrade.done + "(+" + dif + ")"; + return '
' + what + '
' + done + ((dif >= 1) ? ('(+' + dif + ')') : '') + '
'; + return div; } + function checkButtons(what) { var where = game[what]; if (what == "jobs") { From 62b7656f1f04545edf67556f899dd85cf8615085 Mon Sep 17 00:00:00 2001 From: Andrea Reina Date: Sat, 15 Sep 2018 19:30:56 +0800 Subject: [PATCH 6/8] Speedify drawGrid() Aggregating the style change is a minor speedup, most of the time is spent assigning the cell's `.innerHTML`. --- main.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 95394167..5144b85a 100644 --- a/main.js +++ b/main.js @@ -7322,10 +7322,12 @@ function drawGrid(maps) { //maps t or f. This function overwrites the current gr var cell = document.createElement("li"); cell.setAttribute("id", idText + counter); row.appendChild(cell); - cell.style.width = (100 / cols) + "%"; - cell.style.paddingTop = ((100 / cols) / 19)+ "vh"; - cell.style.paddingBottom = ((100 / cols) / 19) + "vh"; - cell.style.fontSize = ((cols / 14) + 1) + "vh"; + Object.assign(cell.style, { + width: 100 / cols + "%", + paddingTop: 100 / cols / 19 + "vh", + paddingBottom: 100 / cols / 19 + "vh", + fontSize: cols / 14 + 1 + "vh" + }); var className = "battleCell cellColorNotBeaten" if (maps && game.global.mapGridArray[counter].name == "Pumpkimp") className += " mapPumpkimp"; if (maps && map.location == "Void") className += " voidCell"; From d14013dcdf3a88f2af55461ec536e802bcf77d86 Mon Sep 17 00:00:00 2001 From: Andrea Reina Date: Sat, 15 Sep 2018 21:42:08 +0800 Subject: [PATCH 7/8] Batch drawGrid() HTML parsing to once per row --- main.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/main.js b/main.js index 5144b85a..d2dfe6f7 100644 --- a/main.js +++ b/main.js @@ -7317,17 +7317,12 @@ function drawGrid(maps) { //maps t or f. This function overwrites the current gr grid.insertBefore(row, grid.childNodes[0]); row.setAttribute("id", "row" + i); row.className = "battleRow"; + var cellHTMLs = []; for (var x = 0; x < cols; x++) { + + var title, onclick; + if (maps && counter >= size) return; - var cell = document.createElement("li"); - cell.setAttribute("id", idText + counter); - row.appendChild(cell); - Object.assign(cell.style, { - width: 100 / cols + "%", - paddingTop: 100 / cols / 19 + "vh", - paddingBottom: 100 / cols / 19 + "vh", - fontSize: cols / 14 + 1 + "vh" - }); var className = "battleCell cellColorNotBeaten" if (maps && game.global.mapGridArray[counter].name == "Pumpkimp") className += " mapPumpkimp"; if (maps && map.location == "Void") className += " voidCell"; @@ -7340,19 +7335,28 @@ function drawGrid(maps) { //maps t or f. This function overwrites the current gr } if (!maps && game.global.gridArray[counter].empowerment){ className += " empoweredCell" + game.global.gridArray[counter].empowerment; - cell.title = "Token of " + game.global.gridArray[counter].empowerment; + title = "Token of " + game.global.gridArray[counter].empowerment; } else if (!maps && checkIfSpireWorld() && game.global.spireActive) className += " spireCell"; - cell.className = className; - cell.innerHTML = (maps) ? game.global.mapGridArray[counter].text : game.global.gridArray[counter].text; - if (cell.innerHTML === "") cell.innerHTML = " "; + if (!maps && game.global.gridArray[counter].special == "easterEgg"){ - cell.onclick = function () { easterEggClicked(); }; + onclick = ' onclick="easterEggClicked();"'; game.global.eggLoc = counter; - cell.className += " eggCell"; + className += " eggCell"; } + var cell = "
  • " + ((maps ? game.global.mapGridArray[counter].text : game.global.gridArray[counter].text) || " ") + "
  • "; + cellHTMLs.push(cell); counter++; } + row.innerHTML = cellHTMLs.join(''); + Array.from(row.children).forEach(function(cell) { + Object.assign(cell.style, { + width: 100 / cols + "%", + paddingTop: 100 / cols / 19 + "vh", + paddingBottom: 100 / cols / 19 + "vh", + fontSize: cols / 14 + 1 + "vh" + }); + }); } } From 3891de5f5ac62b98fccb8861a52b05544f45f0a1 Mon Sep 17 00:00:00 2001 From: Andrea Reina Date: Sat, 15 Sep 2018 22:16:22 +0800 Subject: [PATCH 8/8] Batch drawGrid() HTML parsing to once per call --- main.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/main.js b/main.js index d2dfe6f7..3269d73e 100644 --- a/main.js +++ b/main.js @@ -7311,12 +7311,9 @@ function drawGrid(maps) { //maps t or f. This function overwrites the current gr var idText = (maps) ? "mapCell" : "cell"; var size = 0; if (maps) size = game.global.mapGridArray.length; + var rowHTMLs = []; for (var i = 0; i < rows; i++) { if (maps && counter >= size) return; - var row = document.createElement("ul"); - grid.insertBefore(row, grid.childNodes[0]); - row.setAttribute("id", "row" + i); - row.className = "battleRow"; var cellHTMLs = []; for (var x = 0; x < cols; x++) { @@ -7348,8 +7345,16 @@ function drawGrid(maps) { //maps t or f. This function overwrites the current gr cellHTMLs.push(cell); counter++; } - row.innerHTML = cellHTMLs.join(''); - Array.from(row.children).forEach(function(cell) { + rowHTMLs.push( + '
      ' + + cellHTMLs.join('') + + '
    ' + ); + } + // The grid has row 0 at the bottom, so reverse + grid.innerHTML = rowHTMLs.reverse().join(''); + Array.from(document.querySelectorAll(".battleCell")) + .forEach(function(cell) { Object.assign(cell.style, { width: 100 / cols + "%", paddingTop: 100 / cols / 19 + "vh", @@ -7357,7 +7362,6 @@ function drawGrid(maps) { //maps t or f. This function overwrites the current gr fontSize: cols / 14 + 1 + "vh" }); }); - } } function easterEggClicked(){