Updated functions related to tab-bar

This commit is contained in:
Daniel van Noord
2020-12-03 13:05:22 +01:00
parent 28ab2eab22
commit 06c7f59cd6
2 changed files with 54 additions and 62 deletions

View File

@@ -1062,6 +1062,9 @@ CM.Disp.Notification = function(notifyConfig, title, message) {
* Section: Functions related to updating the tab in the browser's tab-bar
* TODO: Annotate functions */
/**
* This function creates the Favicon, it is called by CM.DelayInit()
*/
CM.Disp.CreateFavicon = function() {
CM.Disp.Favicon = document.createElement('link');
CM.Disp.Favicon.id = 'CMFavicon';
@@ -1070,20 +1073,23 @@ CM.Disp.CreateFavicon = function() {
document.getElementsByTagName('head')[0].appendChild(CM.Disp.Favicon);
}
/**
* This function updates the Favicon depending on whether a Golden Cookie has spawned
* It is called on every loop by CM.Disp.CheckGoldenCookie() or by a change in CM.Config.Favicon
* By relying on CM.Disp.spawnedGoldenShimmer it only changes for non-user spawned cookie
*/
CM.Disp.UpdateFavicon = function() {
if (CM.Config.Favicon == 1) {
if (CM.Disp.spawnedGoldenShimmer.wrath) {
CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico';
}
else {
CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico';
}
}
else {
CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico';
if (CM.Disp.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico';
else CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico';
}
else CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico';
}
/**
* This function updates the tab title
* It is called on every loop by Game.Logic() which also sets CM.Cache.Title to Game.cookies
*/
CM.Disp.UpdateTitle = function() {
if (Game.OnAscend || CM.Config.Title == 0) {
document.title = CM.Cache.Title;
@@ -1091,56 +1097,46 @@ CM.Disp.UpdateTitle = function() {
else if (CM.Config.Title == 1) {
var addFC = false;
var addSP = false;
var titleGC;
var titleFC;
var titleSP;
if (CM.Disp.lastGoldenCookieState) {
if (CM.Disp.spawnedGoldenShimmer.wrath) {
titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
}
else {
titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
}
if (CM.Disp.spawnedGoldenShimmer) {
if (CM.Disp.spawnedGoldenShimmer.wrath) titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
else titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
}
else if (!Game.Has('Golden switch [off]')) {
titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']';
}
else {
titleGC = '[GS]'
}
else titleGC = '[GS]'
if (CM.Disp.lastTickerFortuneState) {
addFC = true;
titleFC = '[F]';
}
if (Game.season == 'christmas') {
addSP = true;
if (CM.Disp.lastSeasonPopupState) {
titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']';
}
if (CM.Disp.lastSeasonPopupState) titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']';
else {
titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']';
}
}
// Remove previous timers and add current cookies
var str = CM.Cache.Title;
if (str.charAt(0) == '[') {
str = str.substring(str.lastIndexOf(']') + 1);
}
document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str;
}
else if (CM.Config.Title == 2) {
var str = '';
var spawn = false;
if (CM.Disp.lastGoldenCookieState) {
if (CM.Disp.spawnedGoldenShimmer) {
spawn = true;
if (CM.Disp.spawnedGoldenShimmer.wrath) {
str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
}
else {
str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
}
if (CM.Disp.spawnedGoldenShimmer.wrath) str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
else str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
}
if (CM.Disp.lastTickerFortuneState) {
spawn = true;