Option for notifications for Golden/Fortunes/Season Cookies & full Magic Bar (#341)

This commit is contained in:
DanielNoord
2020-11-24 23:32:35 +01:00
committed by GitHub
parent d40f90d233
commit 6922dd0465
4 changed files with 108 additions and 6 deletions

View File

@@ -114,6 +114,35 @@ CM.ToggleStatsConfig = function(config) {
CM.SaveConfig(CM.Config);
}
// Checks if the browsers has permissions to produce notifications
// Should be triggered when Config related to Notifications is toggled on
CM.CheckNotificationPermissions = function(ToggleOnOff) {
if (ToggleOnOff == 1) {
// Check if browser support Promise version of Notification Permissions
function checkNotificationPromise() {
try {
Notification.requestPermission().then();
} catch(e) {
return false;
}
return true;
}
// Check if the browser supports notifications and which type
if (!('Notification' in window)) {
console.log("This browser does not support notifications.");
}
else {
if(checkNotificationPromise()) {
Notification.requestPermission().then();
}
else {
Notification.requestPermission();
}
}
}
}
CM.ConfigData.BotBar = {label: ['Bottom Bar OFF', 'Bottom Bar ON'], desc: 'Building Information', toggle: true, func: function() {CM.Disp.ToggleBotBar();}};
CM.ConfigData.TimerBar = {label: ['Timer Bar OFF', 'Timer Bar ON'], desc: 'Timers of Golden Cookie, Season Popup, Frenzy (Normal, Clot, Elder), Click Frenzy', toggle: true, func: function() {CM.Disp.ToggleTimerBar();}};
CM.ConfigData.TimerBarPos = {label: ['Timer Bar Position (Top Left)', 'Timer Bar Position (Bottom)'], desc: 'Placement of the Timer Bar', toggle: false, func: function() {CM.Disp.ToggleTimerBarPos();}};
@@ -140,6 +169,7 @@ CM.ConfigData.CPSMode = {label: ['Current Cookies Per Second', 'Average Cookies
CM.ConfigData.AvgCPSHist = {label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false};
CM.ConfigData.AvgClicksHist = {label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false};
CM.ConfigData.ToolWarnBon = {label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true};
CM.ConfigData.GCNotification = {label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}};
CM.ConfigData.GCFlash = {label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true};
CM.ConfigData.GCSound = {label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true};
CM.ConfigData.GCVolume = {label: [], desc: 'Volume of the Golden Cookie sound'};
@@ -149,6 +179,7 @@ for (var i = 0; i < 101; i++) {
CM.ConfigData.GCSoundURL = {label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'};
CM.ConfigData.GCTimer = {label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}};
CM.ConfigData.Favicon = {label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}};
CM.ConfigData.FortuneNotification = {label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}};
CM.ConfigData.FortuneFlash = {label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true};
CM.ConfigData.FortuneSound = {label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true};
CM.ConfigData.FortuneVolume = {label: [], desc: 'Volume of the Fortune Cookie sound'};
@@ -156,6 +187,7 @@ for (var i = 0; i < 101; i++) {
CM.ConfigData.FortuneVolume.label[i] = i + '%';
}
CM.ConfigData.FortuneSoundURL = {label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'};
CM.ConfigData.SeaNotification = {label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}};
CM.ConfigData.SeaFlash = {label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true};
CM.ConfigData.SeaSound = {label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true};
CM.ConfigData.SeaVolume = {label: [], desc: 'Volume of the Season Special sound'};
@@ -170,8 +202,9 @@ for (var i = 0; i < 101; i++) {
CM.ConfigData.GardVolume.label[i] = i + '%';
}
CM.ConfigData.GardSoundURL = {label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'};
CM.ConfigData.MagicFlash = {label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maxium', toggle: true};
CM.ConfigData.MagicSound = {label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maxium', toggle: true};
CM.ConfigData.MagicNotification = {label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}};
CM.ConfigData.MagicFlash = {label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true};
CM.ConfigData.MagicSound = {label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true};
CM.ConfigData.MagicVolume = {label: [], desc: 'Volume of the Max Magic sound'};
for (var i = 0; i < 101; i++) {
CM.ConfigData.MagicVolume.label[i] = i + '%';

View File

@@ -873,6 +873,13 @@ CM.Disp.PlaySound = function(url, sndConfig, volConfig) {
}
}
CM.Disp.Notification = function(notifyConfig, title, message) {
if (CM.Config[notifyConfig] == 1 && document.visibilityState == 'hidden') {
var CookieIcon = 'https://orteil.dashnet.org/cookieclicker/favicon.ico'
var notification = new Notification(title, {body: message, badge: CookieIcon});
}
}
/**
* Needed for some of the functions to use the right object
*/
@@ -955,6 +962,7 @@ CM.Disp.CheckGoldenCookie = function() {
CM.Disp.Flash(3, 'GCFlash');
CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume');
CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!")
}
else if (CM.Config.GCTimer == 1) CM.Disp.GCTimer.style.display = 'none';
}
@@ -971,6 +979,7 @@ CM.Disp.CheckTickerFortune = function() {
if (CM.Disp.lastTickerFortuneState) {
CM.Disp.Flash(3, 'FortuneFlash');
CM.Disp.PlaySound(CM.Config.FortuneSoundURL, 'FortuneSound', 'FortuneVolume');
CM.Disp.Notification('FortuneNotification', "Fortune Cookie found", "A Fortune Cookie has appeared on the Ticker.")
}
}
}
@@ -989,6 +998,7 @@ CM.Disp.CheckSeasonPopup = function() {
CM.Disp.Flash(3, 'SeaFlash');
CM.Disp.PlaySound(CM.Config.SeaSoundURL, 'SeaSound', 'SeaVolume');
CM.Disp.Notification('SeaNotification',"Reindeer sighted!", "A Reindeer has spawned. Click it now!")
}
}
}
@@ -1013,6 +1023,7 @@ CM.Disp.CheckMagicMeter = function() {
CM.Disp.lastMagicBarFull = true;
CM.Disp.Flash(3, 'MagicFlash');
CM.Disp.PlaySound(CM.Config.MagicSoundURL, 'MagicSound', 'MagicVolume');
CM.Disp.Notification('MagicNotification', "Magic Meter full", "Your Magic Meter is full. Cast a spell!")
}
}
}
@@ -1238,16 +1249,19 @@ CM.Disp.AddMenuPref = function(title) {
frag.appendChild(listing('ToolWarnBon'));
frag.appendChild(header('Notification'));
frag.appendChild(listing('GCNotification'));
frag.appendChild(listing('GCFlash'));
frag.appendChild(listing('GCSound'));
frag.appendChild(vol('GCVolume'));
frag.appendChild(url('GCSoundURL'));
frag.appendChild(listing('GCTimer'));
frag.appendChild(listing('Favicon'));
frag.appendChild(listing('FortuneNotification'));
frag.appendChild(listing('FortuneFlash'));
frag.appendChild(listing('FortuneSound'));
frag.appendChild(vol('FortuneVolume'));
frag.appendChild(url('FortuneSoundURL'));
frag.appendChild(listing('SeaNotification'));
frag.appendChild(listing('SeaFlash'));
frag.appendChild(listing('SeaSound'));
frag.appendChild(vol('SeaVolume'));
@@ -1256,6 +1270,7 @@ CM.Disp.AddMenuPref = function(title) {
frag.appendChild(listing('GardSound'));
frag.appendChild(vol('GardVolume'));
frag.appendChild(url('GardSoundURL'));
frag.appendChild(listing('MagicNotification'));
frag.appendChild(listing('MagicFlash'));
frag.appendChild(listing('MagicSound'));
frag.appendChild(vol('MagicVolume'));
@@ -2355,4 +2370,3 @@ CM.Disp.TooltipText = [
['ResetTooltipPlaceholder', 'The bonus income you would get from new prestige levels unlocked at 100% of its potential and from reset achievements if you have the same buildings/upgrades after reset', '370px'],
['ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg', '300px']
];

View File

@@ -268,16 +268,19 @@ CM.ConfigDefault = {
AvgCPSHist: 3,
AvgClicksHist: 0,
ToolWarnBon: 0,
GCNotification: 0,
GCFlash: 1,
GCSound: 1,
GCVolume: 100,
GCSoundURL: 'https://freesound.org/data/previews/66/66717_931655-lq.mp3',
GCTimer: 1,
Favicon: 1,
FortuneNotification: 0,
FortuneFlash: 1,
FortuneSound: 1,
FortuneVolume: 100,
FortuneSoundURL: 'https://freesound.org/data/previews/174/174027_3242494-lq.mp3',
SeaNotification: 0,
SeaFlash: 1,
SeaSound: 1,
SeaVolume: 100,
@@ -286,6 +289,7 @@ CM.ConfigDefault = {
GardSound: 1,
GardVolume: 100,
GardSoundURL: 'https://freesound.org/data/previews/103/103046_861714-lq.mp3',
MagicNotification: 0,
MagicFlash: 1,
MagicSound: 1,
MagicVolume: 100,