From 3a68c1c17c07ff86c032070820d0c3829a37d80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 11 Apr 2017 11:35:47 +0200 Subject: [PATCH 01/10] fixes #118 more control for notifications --- src/mods/core.js | 12 ++++++++---- src/mods/settings.js | 10 ++++++++++ src/mods/ui.js | 10 ++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) 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/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/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', From 974e46e48fb9d7b4cc75cfc3a3543ac2f948be73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 11 Apr 2017 13:37:40 +0200 Subject: [PATCH 02/10] simplifications of observer fixes #299 --- src/mods/observer.js | 52 +++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/src/mods/observer.js b/src/mods/observer.js index 3c6a03b..9a3aeef 100644 --- a/src/mods/observer.js +++ b/src/mods/observer.js @@ -24,28 +24,44 @@ 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; - } - idrinth.raids.private[id] = hash; - idrinth.core.ajax.runHome ( 'get-raid-service/' + id + '/' + hash + '/' ); + return null; + }; + /** + * + * @param {string} href + * @param {Boolean} isWorld + * @returns {Boolean} + */ + var correctServer = function(href, isWorld) { + return (!href.match ( 'serverid=2' )) === !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 ); From cb8abc7b1d5ba750cd4b12dddc07e6aa8d4aabda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 11 Apr 2017 13:38:46 +0200 Subject: [PATCH 03/10] making ! less confusing I hope --- src/mods/observer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mods/observer.js b/src/mods/observer.js index 9a3aeef..cc648e6 100644 --- a/src/mods/observer.js +++ b/src/mods/observer.js @@ -45,7 +45,7 @@ idrinth.observer = { * @returns {Boolean} */ var correctServer = function(href, isWorld) { - return (!href.match ( 'serverid=2' )) === !isWorld; + return (!href.match ( 'serverid=2' )) !== isWorld; }; if(!href || !href.match ( /action_type=raidhelp/ )) { return; From 3433daad5bbb8206e19e6f88b085fad9c6dacb6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 11 Apr 2017 13:40:56 +0200 Subject: [PATCH 04/10] making ! less confusing I hope --- src/mods/observer.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mods/observer.js b/src/mods/observer.js index cc648e6..2feb937 100644 --- a/src/mods/observer.js +++ b/src/mods/observer.js @@ -45,7 +45,10 @@ idrinth.observer = { * @returns {Boolean} */ var correctServer = function(href, isWorld) { - return (!href.match ( 'serverid=2' )) !== isWorld; + if (href.match ( 'serverid=2' )) { + return isWorld; + } + return !isWorld; }; if(!href || !href.match ( /action_type=raidhelp/ )) { return; From 0ec836adbf9402eb9573a3ba60bc74bfde30f447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 11 Apr 2017 13:52:04 +0200 Subject: [PATCH 05/10] fixes #313 --- src/mods/observer.js | 16 +++++------ src/mods/tier.js | 67 ++++++++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/mods/observer.js b/src/mods/observer.js index 2feb937..baf5e21 100644 --- a/src/mods/observer.js +++ b/src/mods/observer.js @@ -30,9 +30,9 @@ idrinth.observer = { * @param {string} prefix * @returns {null|string} */ - var getData = function(parts,prefix) { + var getData = function ( parts, prefix ) { for (var count = 0; count < parts.length; count++) { - if ( parts[count].match ( prefix+'=' ) ) { + if ( parts[count].match ( prefix + '=' ) ) { return parts[count].split ( '=' )[1]; } } @@ -44,22 +44,22 @@ idrinth.observer = { * @param {Boolean} isWorld * @returns {Boolean} */ - var correctServer = function(href, isWorld) { - if (href.match ( 'serverid=2' )) { + var correctServer = function ( href, isWorld ) { + if ( href.match ( 'serverid=2' ) ) { return isWorld; } return !isWorld; }; - if(!href || !href.match ( /action_type=raidhelp/ )) { + if ( !href || !href.match ( /action_type=raidhelp/ ) ) { return; } href = href.replace ( /^.*\?/, '' ); - if ( !correctServer(href, idrinth.settings.get ( "world" )) ) { + if ( !correctServer ( href, idrinth.settings.get ( "world" ) ) ) { return; } var parts = href.split ( "&" ); - var id = getData(parts, 'raid_id'); - var hash = getData(parts, 'hash'); + var id = getData ( parts, 'raid_id' ); + var hash = getData ( parts, 'hash' ); if ( !id || !hash ) { return; } diff --git a/src/mods/tier.js b/src/mods/tier.js index 8225553..f97d881 100644 --- a/src/mods/tier.js +++ b/src/mods/tier.js @@ -187,25 +187,55 @@ idrinth.tier = { var ln = { type: 'td' }; - 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 ) { + if ( !idrinth.tier.list[listKey].hasOwnProperty ( 'loot' ) ) { + return ln; + } + if ( !idrinth.tier.list[listKey].loot.hasOwnProperty ( difficulty ) ) { + return ln; + } + if ( !idrinth.tier.list[listKey].loot[difficulty].hasOwnProperty ( ic ) ) { + return ln; + } + if ( !idrinth.tier.list[listKey].loot[difficulty][ic] ) { + return ln; + } + ln.attributes = ln.attributes ? ln.attributes : [ ]; 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.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 ) { + if ( + !idrinth.tier.list[listKey].hasOwnProperty ( difficulty ) || + !idrinth.tier.list[listKey][difficulty].hasOwnProperty ( ic ) + ) { + return ln; + } ln.styles = 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 ( @@ -215,8 +245,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 ); }; /** * From 4dc3044eebc2f2c1e75d4cc7e80fa0fd39d0f7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 11 Apr 2017 14:02:07 +0200 Subject: [PATCH 06/10] removing unecessary condition --- src/mods/tier.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/mods/tier.js b/src/mods/tier.js index f97d881..01d9421 100644 --- a/src/mods/tier.js +++ b/src/mods/tier.js @@ -185,7 +185,8 @@ idrinth.tier = { */ var makeField = function ( listKey, difficulty, ic ) { var ln = { - type: 'td' + type: 'td', + attributes: [] }; /** * @@ -196,19 +197,14 @@ idrinth.tier = { * @returns {object} for the buildElement wrapper */ var addTitle = function ( ln, listKey, difficulty, ic ) { - if ( !idrinth.tier.list[listKey].hasOwnProperty ( 'loot' ) ) { - return ln; - } - if ( !idrinth.tier.list[listKey].loot.hasOwnProperty ( difficulty ) ) { - return ln; - } - if ( !idrinth.tier.list[listKey].loot[difficulty].hasOwnProperty ( ic ) ) { - return ln; - } - if ( !idrinth.tier.list[listKey].loot[difficulty][ic] ) { + 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] + ) { return ln; } - ln.attributes = ln.attributes ? ln.attributes : [ ]; var title = ""; for (var key in idrinth.tier.list[listKey].loot[difficulty][ic]) { if ( idrinth.tier.list[listKey].loot[difficulty][ic].hasOwnProperty ( key ) ) { From e7fb594f251a9016c92ceee03ad1e4378e89df03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 11 Apr 2017 14:12:37 +0200 Subject: [PATCH 07/10] fixing is-os check --- src/mods/tier.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/mods/tier.js b/src/mods/tier.js index 01d9421..5d8e430 100644 --- a/src/mods/tier.js +++ b/src/mods/tier.js @@ -186,7 +186,7 @@ idrinth.tier = { var makeField = function ( listKey, difficulty, ic ) { var ln = { type: 'td', - attributes: [] + attributes: [ ] }; /** * @@ -201,8 +201,8 @@ idrinth.tier = { !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] - ) { + !idrinth.tier.list[listKey].loot[difficulty][ic] + ) { return ln; } var title = ""; @@ -226,13 +226,22 @@ idrinth.tier = { * @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 ) === Number.parseInt ( current ); + }; if ( !idrinth.tier.list[listKey].hasOwnProperty ( difficulty ) || !idrinth.tier.list[listKey][difficulty].hasOwnProperty ( ic ) ) { return ln; } - ln.styles = idrinth.tier.list[listKey].os[difficulty] === idrinth.tier.list[listKey][difficulty][ic] ? 'is-os' : ''; + ln.styles = 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 && From 4f5df5e6da0d37562458acb242fe6dc337d936da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 11 Apr 2017 14:16:50 +0200 Subject: [PATCH 08/10] extracting contions for title into function --- src/mods/tier.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/mods/tier.js b/src/mods/tier.js index 5d8e430..d64da66 100644 --- a/src/mods/tier.js +++ b/src/mods/tier.js @@ -197,12 +197,20 @@ idrinth.tier = { * @returns {object} for the buildElement wrapper */ var addTitle = function ( ln, listKey, difficulty, ic ) { - 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] - ) { + /** + * + * @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 = ""; From c35c841aee4075a662121a07a395ecd442c18caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 11 Apr 2017 14:18:04 +0200 Subject: [PATCH 09/10] adding missing radix parameter --- src/mods/tier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mods/tier.js b/src/mods/tier.js index d64da66..6209125 100644 --- a/src/mods/tier.js +++ b/src/mods/tier.js @@ -241,7 +241,7 @@ idrinth.tier = { * @returns {Boolean} */ var isOs = function ( os, current ) { - return Number.parseInt ( os ) === Number.parseInt ( current ); + return Number.parseInt ( os, 10 ) === Number.parseInt ( current, 10 ); }; if ( !idrinth.tier.list[listKey].hasOwnProperty ( difficulty ) || From a87366be5c3a9547951a22cbb0105917c520d951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 11 Apr 2017 14:31:18 +0200 Subject: [PATCH 10/10] making sure is-os class can actually be set --- src/mods/tier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mods/tier.js b/src/mods/tier.js index 6209125..f99aa6e 100644 --- a/src/mods/tier.js +++ b/src/mods/tier.js @@ -249,7 +249,7 @@ idrinth.tier = { ) { return ln; } - ln.styles = isOs ( idrinth.tier.list[listKey].os[difficulty], idrinth.tier.list[listKey][difficulty][ic] ) ? 'is-os' : ''; + 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 &&