diff --git a/src/mods/core.js b/src/mods/core.js index 00a64d9..fb8ec3e 100644 --- a/src/mods/core.js +++ b/src/mods/core.js @@ -159,10 +159,14 @@ idrinth.core = { if ( window.Notification.permission === "denied" ) { return false; } - return new window.Notification ( title, { - icon: "https://dotd.idrinth.de/Resources/Images/logo.png", - body: content - } ); + var data = {}; + if(idrinth.settings.get ('notification#image')) { + data.icon = "https://dotd.idrinth.de/Resources/Images/logo.png"; + } + if(idrinth.settings.get ('notification#content')) { + data.body = content; + } + return new window.Notification ( title, data ); }, /** * diff --git a/src/mods/observer.js b/src/mods/observer.js index 3c6a03b..baf5e21 100644 --- a/src/mods/observer.js +++ b/src/mods/observer.js @@ -24,28 +24,47 @@ idrinth.observer = { */ var handleLink = function ( element ) { var href = element.getAttribute ( 'href' ); - if ( href && href.match ( /action_type=raidhelp/ ) ) { - var hash = ''; - var id = ''; - href = href.replace ( /^.*\?/, '' ); - var parts = href.split ( "&" ); + /** + * + * @param {Array} parts + * @param {string} prefix + * @returns {null|string} + */ + var getData = function ( parts, prefix ) { for (var count = 0; count < parts.length; count++) { - if ( parts[count].match ( 'raid_id=' ) ) { - id = parts[count].split ( '=' )[1]; - } else if ( parts[count].match ( 'hash=' ) ) { - hash = parts[count].split ( '=' )[1]; - } else if ( parts[count].match ( 'serverid=2' ) && !idrinth.settings.get ( "world" ) ) { - return; - } else if ( !parts[count].match ( 'server_id=2' ) && idrinth.settings.get ( "world" ) ) { - return; + if ( parts[count].match ( prefix + '=' ) ) { + return parts[count].split ( '=' )[1]; } } - if ( !id || !hash ) { - return; + return null; + }; + /** + * + * @param {string} href + * @param {Boolean} isWorld + * @returns {Boolean} + */ + var correctServer = function ( href, isWorld ) { + if ( href.match ( 'serverid=2' ) ) { + return isWorld; } - idrinth.raids.private[id] = hash; - idrinth.core.ajax.runHome ( 'get-raid-service/' + id + '/' + hash + '/' ); + return !isWorld; + }; + if ( !href || !href.match ( /action_type=raidhelp/ ) ) { + return; + } + href = href.replace ( /^.*\?/, '' ); + if ( !correctServer ( href, idrinth.settings.get ( "world" ) ) ) { + return; + } + var parts = href.split ( "&" ); + var id = getData ( parts, 'raid_id' ); + var hash = getData ( parts, 'hash' ); + if ( !id || !hash ) { + return; } + idrinth.raids.private[id] = hash; + idrinth.core.ajax.runHome ( 'get-raid-service/' + id + '/' + hash + '/' ); }; if ( node.tagName === 'A' || node.tagName === 'a' ) { handleLink ( node ); diff --git a/src/mods/settings.js b/src/mods/settings.js index 2cfd5a8..9fc1c2f 100644 --- a/src/mods/settings.js +++ b/src/mods/settings.js @@ -134,6 +134,16 @@ idrinth.settings = { * @type Boolean */ message: true, + /** + * + * @type Boolean + */ + content: true, + /** + * + * @type Boolean + */ + image: true, /** * * @type Boolean diff --git a/src/mods/tier.js b/src/mods/tier.js index 8225553..f99aa6e 100644 --- a/src/mods/tier.js +++ b/src/mods/tier.js @@ -185,28 +185,71 @@ idrinth.tier = { */ var makeField = function ( listKey, difficulty, ic ) { var ln = { - type: 'td' + type: 'td', + attributes: [ ] }; - if ( - idrinth.tier.list[listKey].hasOwnProperty ( 'loot' ) && - idrinth.tier.list[listKey].loot.hasOwnProperty ( difficulty ) && - idrinth.tier.list[listKey].loot[difficulty].hasOwnProperty ( ic ) && - idrinth.tier.list[listKey].loot[difficulty][ic] - ) { - ln.attributes = ln.attributes?ln.attributes:[]; + /** + * + * @param {object} ln + * @param {string} listKey + * @param {string} difficulty + * @param {string} ic + * @returns {object} for the buildElement wrapper + */ + var addTitle = function ( ln, listKey, difficulty, ic ) { + /** + * + * @param {string} listKey + * @param {string} difficulty + * @param {string} ic + * @returns {Boolean} + */ + var isUseable = function ( listKey, difficulty, ic ) { + return idrinth.tier.list[listKey].hasOwnProperty ( 'loot' ) && + idrinth.tier.list[listKey].loot.hasOwnProperty ( difficulty ) && + idrinth.tier.list[listKey].loot[difficulty].hasOwnProperty ( ic ) && + idrinth.tier.list[listKey].loot[difficulty][ic]; + }; + if ( !isUseable ( listKey, difficulty, ic ) ) { + return ln; + } var title = ""; - for(var key in idrinth.tier.list[listKey].loot[difficulty][ic]) { - if(idrinth.tier.list[listKey].loot[difficulty][ic].hasOwnProperty (key)) { - title += idrinth.tier.list[listKey].loot[difficulty][ic][key]+" "+idrinth.text.get ('tier.loot.'+key)+"\n"; + for (var key in idrinth.tier.list[listKey].loot[difficulty][ic]) { + if ( idrinth.tier.list[listKey].loot[difficulty][ic].hasOwnProperty ( key ) ) { + title += idrinth.tier.list[listKey].loot[difficulty][ic][key] + " " + idrinth.text.get ( 'tier.loot.' + key ) + "\n"; } } - ln.attributes.push({name:'title',value:title}); - } - if ( - idrinth.tier.list[listKey].hasOwnProperty ( difficulty ) && - idrinth.tier.list[listKey][difficulty].hasOwnProperty ( ic ) - ) { - ln.styles = idrinth.tier.list[listKey].os[difficulty] === idrinth.tier.list[listKey][difficulty][ic] ? 'is-os' : ''; + ln.attributes.push ( { + name: 'title', + value: title + } ); + return ln; + }; + /** + * + * @param {object} ln + * @param {string} listKey + * @param {string} difficulty + * @param {string} ic + * @returns {object} for the buildElement wrapper + */ + var addContent = function ( ln, listKey, difficulty, ic ) { + /** + * + * @param {string} os numeric string + * @param {string} current numeric string + * @returns {Boolean} + */ + var isOs = function ( os, current ) { + return Number.parseInt ( os, 10 ) === Number.parseInt ( current, 10 ); + }; + if ( + !idrinth.tier.list[listKey].hasOwnProperty ( difficulty ) || + !idrinth.tier.list[listKey][difficulty].hasOwnProperty ( ic ) + ) { + return ln; + } + ln.css = isOs ( idrinth.tier.list[listKey].os[difficulty], idrinth.tier.list[listKey][difficulty][ic] ) ? 'is-os' : ''; ln.content = idrinth.ui.formatNumber ( idrinth.tier.list[listKey][difficulty][ic] ); if ( idrinth.tier.list[listKey].epics && @@ -215,8 +258,9 @@ idrinth.tier = { ) { ln.content += ' ' + idrinth.tier.list[listKey].epics[difficulty][ic] + 'E'; } - } - return ln; + return ln; + }; + return addContent ( addTitle ( ln, listKey, difficulty, ic ), listKey, difficulty, ic ); }; /** * diff --git a/src/mods/ui.js b/src/mods/ui.js index 1871e90..52122e6 100644 --- a/src/mods/ui.js +++ b/src/mods/ui.js @@ -744,6 +744,16 @@ idrinth.ui = { rType: '#input', type: 'checkbox', label: 'chat.notification.message' + }, { + name: 'notification#content', + rType: '#input', + type: 'checkbox', + label: 'chat.notification.content' + }, { + name: 'notification#image', + rType: '#input', + type: 'checkbox', + label: 'chat.notification.image' } ], 'chat' ), { css: 'idrinth-line',