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

Commit 2c07b34

Browse files
authored
Merge pull request #312 from IDotD/idrinth
fixes #118
2 parents dd4194f + a87366b commit 2c07b34

5 files changed

Lines changed: 128 additions & 41 deletions

File tree

src/mods/core.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,14 @@ idrinth.core = {
159159
if ( window.Notification.permission === "denied" ) {
160160
return false;
161161
}
162-
return new window.Notification ( title, {
163-
icon: "https://dotd.idrinth.de/Resources/Images/logo.png",
164-
body: content
165-
} );
162+
var data = {};
163+
if(idrinth.settings.get ('notification#image')) {
164+
data.icon = "https://dotd.idrinth.de/Resources/Images/logo.png";
165+
}
166+
if(idrinth.settings.get ('notification#content')) {
167+
data.body = content;
168+
}
169+
return new window.Notification ( title, data );
166170
},
167171
/**
168172
*

src/mods/observer.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,47 @@ idrinth.observer = {
2424
*/
2525
var handleLink = function ( element ) {
2626
var href = element.getAttribute ( 'href' );
27-
if ( href && href.match ( /action_type=raidhelp/ ) ) {
28-
var hash = '';
29-
var id = '';
30-
href = href.replace ( /^.*\?/, '' );
31-
var parts = href.split ( "&" );
27+
/**
28+
*
29+
* @param {Array} parts
30+
* @param {string} prefix
31+
* @returns {null|string}
32+
*/
33+
var getData = function ( parts, prefix ) {
3234
for (var count = 0; count < parts.length; count++) {
33-
if ( parts[count].match ( 'raid_id=' ) ) {
34-
id = parts[count].split ( '=' )[1];
35-
} else if ( parts[count].match ( 'hash=' ) ) {
36-
hash = parts[count].split ( '=' )[1];
37-
} else if ( parts[count].match ( 'serverid=2' ) && !idrinth.settings.get ( "world" ) ) {
38-
return;
39-
} else if ( !parts[count].match ( 'server_id=2' ) && idrinth.settings.get ( "world" ) ) {
40-
return;
35+
if ( parts[count].match ( prefix + '=' ) ) {
36+
return parts[count].split ( '=' )[1];
4137
}
4238
}
43-
if ( !id || !hash ) {
44-
return;
39+
return null;
40+
};
41+
/**
42+
*
43+
* @param {string} href
44+
* @param {Boolean} isWorld
45+
* @returns {Boolean}
46+
*/
47+
var correctServer = function ( href, isWorld ) {
48+
if ( href.match ( 'serverid=2' ) ) {
49+
return isWorld;
4550
}
46-
idrinth.raids.private[id] = hash;
47-
idrinth.core.ajax.runHome ( 'get-raid-service/' + id + '/' + hash + '/' );
51+
return !isWorld;
52+
};
53+
if ( !href || !href.match ( /action_type=raidhelp/ ) ) {
54+
return;
55+
}
56+
href = href.replace ( /^.*\?/, '' );
57+
if ( !correctServer ( href, idrinth.settings.get ( "world" ) ) ) {
58+
return;
59+
}
60+
var parts = href.split ( "&" );
61+
var id = getData ( parts, 'raid_id' );
62+
var hash = getData ( parts, 'hash' );
63+
if ( !id || !hash ) {
64+
return;
4865
}
66+
idrinth.raids.private[id] = hash;
67+
idrinth.core.ajax.runHome ( 'get-raid-service/' + id + '/' + hash + '/' );
4968
};
5069
if ( node.tagName === 'A' || node.tagName === 'a' ) {
5170
handleLink ( node );

src/mods/settings.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ idrinth.settings = {
134134
* @type Boolean
135135
*/
136136
message: true,
137+
/**
138+
*
139+
* @type Boolean
140+
*/
141+
content: true,
142+
/**
143+
*
144+
* @type Boolean
145+
*/
146+
image: true,
137147
/**
138148
*
139149
* @type Boolean

src/mods/tier.js

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -185,28 +185,71 @@ idrinth.tier = {
185185
*/
186186
var makeField = function ( listKey, difficulty, ic ) {
187187
var ln = {
188-
type: 'td'
188+
type: 'td',
189+
attributes: [ ]
189190
};
190-
if (
191-
idrinth.tier.list[listKey].hasOwnProperty ( 'loot' ) &&
192-
idrinth.tier.list[listKey].loot.hasOwnProperty ( difficulty ) &&
193-
idrinth.tier.list[listKey].loot[difficulty].hasOwnProperty ( ic ) &&
194-
idrinth.tier.list[listKey].loot[difficulty][ic]
195-
) {
196-
ln.attributes = ln.attributes?ln.attributes:[];
191+
/**
192+
*
193+
* @param {object} ln
194+
* @param {string} listKey
195+
* @param {string} difficulty
196+
* @param {string} ic
197+
* @returns {object} for the buildElement wrapper
198+
*/
199+
var addTitle = function ( ln, listKey, difficulty, ic ) {
200+
/**
201+
*
202+
* @param {string} listKey
203+
* @param {string} difficulty
204+
* @param {string} ic
205+
* @returns {Boolean}
206+
*/
207+
var isUseable = function ( listKey, difficulty, ic ) {
208+
return idrinth.tier.list[listKey].hasOwnProperty ( 'loot' ) &&
209+
idrinth.tier.list[listKey].loot.hasOwnProperty ( difficulty ) &&
210+
idrinth.tier.list[listKey].loot[difficulty].hasOwnProperty ( ic ) &&
211+
idrinth.tier.list[listKey].loot[difficulty][ic];
212+
};
213+
if ( !isUseable ( listKey, difficulty, ic ) ) {
214+
return ln;
215+
}
197216
var title = "";
198-
for(var key in idrinth.tier.list[listKey].loot[difficulty][ic]) {
199-
if(idrinth.tier.list[listKey].loot[difficulty][ic].hasOwnProperty (key)) {
200-
title += idrinth.tier.list[listKey].loot[difficulty][ic][key]+" "+idrinth.text.get ('tier.loot.'+key)+"\n";
217+
for (var key in idrinth.tier.list[listKey].loot[difficulty][ic]) {
218+
if ( idrinth.tier.list[listKey].loot[difficulty][ic].hasOwnProperty ( key ) ) {
219+
title += idrinth.tier.list[listKey].loot[difficulty][ic][key] + " " + idrinth.text.get ( 'tier.loot.' + key ) + "\n";
201220
}
202221
}
203-
ln.attributes.push({name:'title',value:title});
204-
}
205-
if (
206-
idrinth.tier.list[listKey].hasOwnProperty ( difficulty ) &&
207-
idrinth.tier.list[listKey][difficulty].hasOwnProperty ( ic )
208-
) {
209-
ln.styles = idrinth.tier.list[listKey].os[difficulty] === idrinth.tier.list[listKey][difficulty][ic] ? 'is-os' : '';
222+
ln.attributes.push ( {
223+
name: 'title',
224+
value: title
225+
} );
226+
return ln;
227+
};
228+
/**
229+
*
230+
* @param {object} ln
231+
* @param {string} listKey
232+
* @param {string} difficulty
233+
* @param {string} ic
234+
* @returns {object} for the buildElement wrapper
235+
*/
236+
var addContent = function ( ln, listKey, difficulty, ic ) {
237+
/**
238+
*
239+
* @param {string} os numeric string
240+
* @param {string} current numeric string
241+
* @returns {Boolean}
242+
*/
243+
var isOs = function ( os, current ) {
244+
return Number.parseInt ( os, 10 ) === Number.parseInt ( current, 10 );
245+
};
246+
if (
247+
!idrinth.tier.list[listKey].hasOwnProperty ( difficulty ) ||
248+
!idrinth.tier.list[listKey][difficulty].hasOwnProperty ( ic )
249+
) {
250+
return ln;
251+
}
252+
ln.css = isOs ( idrinth.tier.list[listKey].os[difficulty], idrinth.tier.list[listKey][difficulty][ic] ) ? 'is-os' : '';
210253
ln.content = idrinth.ui.formatNumber ( idrinth.tier.list[listKey][difficulty][ic] );
211254
if (
212255
idrinth.tier.list[listKey].epics &&
@@ -215,8 +258,9 @@ idrinth.tier = {
215258
) {
216259
ln.content += ' ' + idrinth.tier.list[listKey].epics[difficulty][ic] + 'E';
217260
}
218-
}
219-
return ln;
261+
return ln;
262+
};
263+
return addContent ( addTitle ( ln, listKey, difficulty, ic ), listKey, difficulty, ic );
220264
};
221265
/**
222266
*

src/mods/ui.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,16 @@ idrinth.ui = {
744744
rType: '#input',
745745
type: 'checkbox',
746746
label: 'chat.notification.message'
747+
}, {
748+
name: 'notification#content',
749+
rType: '#input',
750+
type: 'checkbox',
751+
label: 'chat.notification.content'
752+
}, {
753+
name: 'notification#image',
754+
rType: '#input',
755+
type: 'checkbox',
756+
label: 'chat.notification.image'
747757
} ], 'chat' ),
748758
{
749759
css: 'idrinth-line',

0 commit comments

Comments
 (0)