Skip to content
This repository has been archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #312 from IDotD/idrinth
Browse files Browse the repository at this point in the history
fixes #118
  • Loading branch information
w20k authored Apr 11, 2017
2 parents dd4194f + a87366b commit 2c07b34
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 41 deletions.
12 changes: 8 additions & 4 deletions src/mods/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
},
/**
*
Expand Down
53 changes: 36 additions & 17 deletions src/mods/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
10 changes: 10 additions & 0 deletions src/mods/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ idrinth.settings = {
* @type Boolean
*/
message: true,
/**
*
* @type Boolean
*/
content: true,
/**
*
* @type Boolean
*/
image: true,
/**
*
* @type Boolean
Expand Down
84 changes: 64 additions & 20 deletions src/mods/tier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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 );
};
/**
*
Expand Down
10 changes: 10 additions & 0 deletions src/mods/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 2c07b34

Please sign in to comment.