diff --git a/mods/chat.js b/mods/chat.js index 4a1d752..959772b 100644 --- a/mods/chat.js +++ b/mods/chat.js @@ -300,11 +300,22 @@ idrinth.chat = { addZero ( d.getSeconds (), 2 ) + addZero ( d.getMilliseconds (), 3 ); }; + var own = parseInt ( message.user, 10 ) === parseInt ( idrinth.chat.self, 10 ); + if ( !own ) { + try { + idrinth.core.sendNotification ( + message.time.split ( ' ' )[1] + ' ' + document.getElementById ( 'idrinth-chat-tab-click-' + chatId ).innerHTML + ':', + idrinth.chat.users[message.user].name + ': ' + message.text + ); + } catch ( exception ) { + idrinth.core.log ( exception.getMessage () ); + } + } chat.appendChild ( idrinth.ui.buildElement ( { type: 'li', id: 'idrinth-single-chat-message-' + messageId + ( parseInt ( messageId, 10 ) < 1 ? '-' + getfullDateInt () : '' ), - css: ( parseInt ( message.user, 10 ) === parseInt ( idrinth.chat.self, 10 ) ? 'self-written ' : '' ), + css: own ? 'self-written ' : '', children: [ { type: 'span', @@ -460,11 +471,223 @@ idrinth.chat = { }, emotes: { }, start: function () { + var build = function () { + var makeInput = function ( label ) { + return { + type: 'li', + children: [ + { + type: 'label', + content: label + }, + { + type: 'input', + attributes: [ + { + name: 'type', + value: 'text' + }, + { + name: 'onchange', + value: 'this.setAttribute(\'value\',this.value);' + } + ] + } + ] + }; + }; + var makeButton = function ( label, onclick ) { + return { + type: 'li', + children: [ + { + type: 'button', + attributes: [ + { + name: 'type', + value: 'button' + }, + { + name: 'onclick', + value: onclick + } + ], + content: label + } + ] + }; + }; + return idrinth.ui.buildElement ( { + id: 'idrinth-chat', + css: 'idrinth-hovering-box' + ( !idrinth.settings.chatHiddenOnStart ? ' active' : '' ) + ( idrinth.settings.moveLeft ? ' left-sided' : '' ), + children: [ + { + type: 'button', + content: ( idrinth.settings.chatHiddenOnStart ? '<<' : '>>' ), + attributes: [ { + name: 'onclick', + value: 'idrinth.chat.openCloseChat(this);' + } ] + }, { + type: 'ul', + css: 'styles-scrollbar chat-labels', + children: [ { + type: 'li', + css: 'active', + content: "\u2699", + attributes: [ + { + name: 'onclick', + value: 'idrinth.chat.enableChat(this);' + }, + { + name: 'data-id', + value: '0' + } + ] + } ] + }, { + type: 'ul', + css: 'chat-tabs', + children: [ { + type: 'li', + css: 'styles-scrollbar active', + attributes: [ + { + name: 'data-id', + value: '0' + } + ], + children: [ + { + type: 'h1', + content: 'Chat' + }, + { + type: 'p', + content: 'This part of the script is optional, so logging in is unneeded for raid catching etc.' + }, { + id: 'idrinth-chat-login', + children: [ + { + type: 'h2', + content: 'Account' + }, + { + type: 'p', + content: 'This should not be the data for logging in on the related gaming site and the login does not need to match your ingame name - you can set a display name after the registration.' + }, + { + type: 'ul', + css: 'settings', + children: [ + makeInput ( 'Username' ), + makeInput ( 'Password' ), + makeButton ( "Not logged in, click to login/register", "idrinth.chat.login()" ) + ] + } + ] + }, { + id: 'idrinth-add-chat', + children: [ + { + type: 'h2', + content: 'Join Chat' + }, + { + type: 'ul', + css: 'settings', + children: [ + makeInput ( 'Chat-ID' ), + makeInput ( 'Chat-Password' ), + makeButton ( "Click to join additional chat", "idrinth.chat.add()" ) + ] + } + ] + }, + { + id: 'idrinth-make-chat', + children: [ + { + type: 'h2', + content: 'Create Chat' + }, + { + type: 'ul', + css: 'settings', + children: [ + makeInput ( "Name" ), + makeButton ( "Click to create additional chat", "idrinth.chat.create()" ) + ] + } + ] + }, { + type: 'li', + children: [ + { + type: '#text', + content: 'More settings at ' + }, + { + type: 'a', + content: 'dotd.idrinth.de/' + idrinth.platform + '/chat/', + attributes: [ + { + name: 'target', + value: '_blank' + }, + { + name: 'href', + value: 'https://dotd.idrinth.de/' + idrinth.platform + '/chat/' + } + ] + }, + { + type: '#text', + content: '.' + } + ] + }, { + type: 'li', + children: [ + { + type: '#text', + content: 'Emoticons provided by ' + }, + { + type: 'a', + content: 'emoticonshd.com', + attributes: [ + { + name: 'target', + value: '_blank' + }, + { + name: 'href', + value: 'http://emoticonshd.com/' + } + ] + }, + { + type: '#text', + content: '.' + } + ] + } + ] + } + ] + } + ] + } ); + }; if ( !idrinth.settings.chatting ) { return; } if ( !document.getElementById ( 'idrinth-chat' ) ) { - window.setTimeout ( idrinth.chat.start, 1000 ); + idrinth.ui.body.appendChild ( build () ); + idrinth.chat.elements.chats = document.getElementById ( 'idrinth-chat' ).getElementsByTagName ( 'ul' )[1]; + idrinth.chat.elements.menu = document.getElementById ( 'idrinth-chat' ).getElementsByTagName ( 'ul' )[0]; } window.setTimeout ( function () { idrinth.core.ajax.run ( @@ -581,16 +804,16 @@ idrinth.chat = { }, loginCallback: function ( data ) { if ( !data ) { - idrinth.core.alert ( this.getMsg ( 'login.fail' ) ); + idrinth.core.alert ( idrinth.chat.getMsg ( 'login.fail' ) ); return; } data = JSON.parse ( data ); if ( !data ) { - idrinth.core.alert ( this.getMsg ( 'login.fail' ) ); + idrinth.core.alert ( idrinth.chat.getMsg ( 'login.fail' ) ); return; } if ( !data.success && data.message && data['allow-reg'] ) { - idrinth.core.confirm ( this.getMsg ( 'user.unknown' ), 'idrinth.chat.register();' ); + idrinth.core.confirm ( idrinth.chat.getMsg ( 'user.unknown' ), 'idrinth.chat.register();' ); return; } if ( !data.success && data.message ) { @@ -605,7 +828,7 @@ idrinth.chat = { idrinth.chat.join ( data.data ); return; } - idrinth.core.alert ( this.getMsg ( 'login.fail' ) ); + idrinth.core.alert ( idrinth.chat.getMsg ( 'login.fail' ) ); }, register: function () { this.loginActions ( 'register' ); diff --git a/mods/names.js b/mods/names.js index 5538c0f..fbf9f04 100644 --- a/mods/names.js +++ b/mods/names.js @@ -80,8 +80,103 @@ idrinth.names = { }, start: function ( ) { 'use strict'; + var build = function ( ) { + 'use strict'; + function getServerPart ( name ) { + return [ { + css: 'idrinth-line idrinth-tooltip-header', + type: 'a', + attributes: [ { + name: 'href', + value: '#' + }, { + name: 'target', + value: '_blank' + }, { + name: 'title', + value: 'go to summoner details' + } ] + }, { + css: 'idrinth-line idrinth-tooltip-level', + type: 'span', + children: [ { + type: '#text', + content: 'Level ' + }, { + css: 'idrinth-format-number idrinth-format-level', + type: 'span', + content: '0' + }, { + type: '#text', + content: ' ' + }, { + css: 'idrinth-format-class', + type: 'span', + content: 'Unknown' + } ] + }, { + css: 'idrinth-line idrinth-tooltip-guild', + type: 'span', + children: [ { + type: '#text', + content: 'of ' + }, { + css: 'idrinth-format-guild', + type: 'a', + attributes: [ { + name: 'href', + 'value': '#' + }, { + name: 'title', + value: 'go to guild details' + }, { + name: 'target', + value: '_blank' + } ] + } ] + }, { + css: 'idrinth-line idrinth-tooltip-update', + type: 'span', + children: [ { + type: '#text', + content: 'Updated ' + }, { + css: 'idrinth-format-date', + type: 'span', + content: 'Unknown' + } ] + }, { + type: 'span', + content: 'Server: ' + name + } ]; + } + idrinth.ui.tooltip = idrinth.ui.buildElement ( { + css: 'idrinth-hovering-box idrinth-tooltip-overwrite idrinth-hide', + id: 'idrinth-tooltip', + children: [ + { + children: getServerPart ( 'Kongregate' ) + }, + { + children: getServerPart ( 'World' ) + } + ], + attributes: [ + { + name: 'onmouseenter', + value: 'idrinth.names.isHovering=true;' + }, + { + name: 'onmouseleave', + value: 'idrinth.names.isHovering=false;' + } + ] + } ); + idrinth.ui.body.appendChild ( idrinth.ui.tooltip ); + }; if ( idrinth.platform === 'kongregate' ) { idrinth.names.ownTimeout = window.setTimeout ( idrinth.names.run, 10000 ); + build (); } }, counter: 0 diff --git a/mods/raids.js b/mods/raids.js index 2e6ae9f..5d4db06 100644 --- a/mods/raids.js +++ b/mods/raids.js @@ -138,11 +138,12 @@ idrinth.raids = { return prefix; }, messages: { - log: function ( string ) { - idrinth.core.log ( string ); + log: function ( string, key ) { + var message = ( string.replace ( '#name#', idrinth.raids.list[key].name ) ).replace ( '#raid#', idrinth.raids.list[key].raid ); + idrinth.core.log ( message ); var li = document.createElement ( 'li' ); var ul = document.getElementById ( 'idrinth-joined-raids' ).getElementsByTagName ( 'ul' )[0]; - li.appendChild ( document.createTextNode ( ( new Date () ).toLocaleTimeString () + ' ' + string ) ); + li.appendChild ( document.createTextNode ( ( new Date () ).toLocaleTimeString () + ' ' + message ) ); if ( !ul.firstChild ) { ul.appendChild ( li ); } else { @@ -160,13 +161,13 @@ idrinth.raids = { }, success: function ( key ) { 'use strict'; - idrinth.raids.join.messages.log ( 'Joined ' + idrinth.raids.list[key].name + '\'s ' + idrinth.raids.list[key].raid ); + idrinth.raids.join.messages.log ( 'Joined #name#\'s #raid#.', key ); idrinth.ui.removeElement ( 'idrinth-raid-link-' + key ); this.addToJoined ( key ); }, failed: function ( key ) { 'use strict'; - idrinth.raids.join.messages.log ( 'Could not join ' + idrinth.raids.list[key].name + '\'s ' + idrinth.raids.list[key].raid ); + idrinth.raids.join.messages.log ( 'Could not join #name#\'s #raid#', key ); }, trying: function ( key ) { 'use strict'; @@ -179,7 +180,7 @@ idrinth.raids = { }, 300 ); } ) ( key ) ); if ( idrinth.raids.list[key] ) { - idrinth.raids.join.messages.log ( 'Trying to join ' + idrinth.raids.list[key].name + '\'s ' + idrinth.raids.list[key].raid ); + idrinth.raids.join.messages.log ( 'Trying to join #name#\'s #raid#', key ); } this.addToJoined ( key ); } diff --git a/mods/settings.js b/mods/settings.js index edb5ce4..2dffc49 100644 --- a/mods/settings.js +++ b/mods/settings.js @@ -18,6 +18,7 @@ idrinth.settings = { isWorldServer: false, alarmTime: '8:0', alarmActive: false, + notificationActive: true, land: { cornfield: 0, stable: 0, diff --git a/mods/ui-buildBasis.js b/mods/ui-buildBasis.js deleted file mode 100644 index 0bb8420..0000000 --- a/mods/ui-buildBasis.js +++ /dev/null @@ -1,750 +0,0 @@ -idrinth.ui.buildBasis = { - 'do': function () { - 'use strict'; - var wrapper = function ( ) { - var buildActions = function () { - var buttonMaker = function ( label, onclick, platform ) { - return { - css: 'idrinth-float-half' + ( platform && platform !== idrinth.platform ? " idrinth-hide" : "" ), - type: 'button', - content: label, - attributes: [ { - name: 'type', - value: 'button' - }, { - name: 'onclick', - value: onclick - } ] - }; - }; - return [ { - children: [ - buttonMaker ( 'Import all manually', 'idrinth.raids.import(\'\');' ), - buttonMaker ( 'Import favs manually', 'idrinth.raids.import(idrinth.settings.favs);' ), - buttonMaker ( 'Reload game', 'idrinth.ui.reloadGame();' ), - buttonMaker ( 'Clear Raids', 'idrinth.raids.clearAll();' ), - buttonMaker ( 'Reload Script', 'idrinth.reload();' ), - buttonMaker ( 'Restart Raidjoin', 'idrinth.raids.restartInterval();' ), - buttonMaker ( 'Refresh Facebook Game Login', 'idrinth.facebook.rejoin()', 'facebook' ), - buttonMaker ( 'NG Raid Join(slow!)', 'idrinth.newgrounds.joinRaids()', 'newgrounds' ), - buttonMaker ( idrinth.settings.alarmActive ? 'disable timed Autojoin' : 'enable timed Autojoin', 'idrinth.settings.change(\'alarmActive\',!idrinth.settings.alarmActive);this.innerHTML=idrinth.settings.alarmActive?\'disable timed Autojoin\':\'enable timed Autojoin\'', 'newgrounds' ) - ] - }, { - css: 'idrinth-line', - id: 'idrinth-joined-raids', - content: 'Last raids joined:', - children: [ - { - type: 'ul' - } - ] - } - ]; - }; - var buildTiers = function () { - return [ { - css: 'idrinth-line', - children: [ { - type: 'label', - content: 'Enter Boss\' Name', - css: 'idrinth-float-half', - attributes: [ - { - name: 'for', - value: 'idrinth-tierlist-bosssearch' - } - ] - }, { - type: 'input', - css: 'idrinth-float-half', - id: 'idrinth-tierlist-bosssearch', - attributes: [ - { - name: 'onkeyup', - value: 'idrinth.tier.getTierForName(this.value);' - }, - { - name: 'onchange', - value: 'idrinth.tier.getTierForName(this.value);' - }, - { - name: 'onblur', - value: 'idrinth.tier.getTierForName(this.value);' - } - ] - } ] - }, { - id: 'idrinth-tierlist' - } ]; - }; - var buildControls = function () { - 'use strict'; - return [ { - name: 'names', - rType: '#input', - type: 'checkbox', - platforms: [ 'kongregate' ], - label: 'Enable extended Characterinformation?' - }, { - name: 'minimalist', - rType: '#input', - type: 'checkbox', - label: 'Minimalist Layout' - }, { - name: 'moveLeft', - rType: '#input', - type: 'checkbox', - label: 'Move settings left' - }, { - name: 'warBottom', - rType: '#input', - type: 'checkbox', - label: 'Show war at the bottom of the page' - }, { - name: 'landMax', - rType: '#input', - type: 'checkbox', - label: 'Check to try and use up the gold as efficient as possible - uncheck to only use the most efficient buy in the land buy calculator' - }, { - name: 'factor', - rType: '#input', - type: 'checkbox', - label: 'Buy 10 Buildings at once?(Rec)' - }, { - name: 'timeout', - rType: '#input', - type: 'number', - platforms: [ 'kongregate' ], - label: 'Milliseconds until the extended Characterinformation disappears' - }, { - name: 'newgroundLoad', - rType: '#input', - type: 'number', - platforms: [ 'newgrounds' ], - label: 'Seconds needed to load the game for joining' - }, { - name: 'chatting', - rType: '#input', - type: 'checkbox', - label: 'Enable chat(needs script reload)' - }, { - css: 'idrinth-line', - type: 'span', - content: 'This script will always import the raids you manually set to be imported on the website and if it\'s enabled it will also import all raids matched by one of the faved searches provided.' - }, { - name: 'raids', - rType: '#input', - type: 'checkbox', - label: 'Enable Auto-Raid-Request for Favorites?' - }, { - name: 'favs', - rType: '#input', - type: 'text', - label: 'FavoriteIds to join (separate multiple by comma)' - }, { - name: 'isWorldServer', - rType: '#input', - type: 'checkbox', - label: 'Worldserver?' - }, { - name: 'windows', - rType: '#input', - type: 'number', - platforms: [ 'dawnofthedragons' ], - label: 'Maximum Popups/Frames for joining raids' - }, { - name: 'alarmTime', - rType: '#input', - type: 'text', - platforms: [ 'newgrounds' ], - label: 'Time to automatically join raids slowly(reloads game multiple times). Format is [Hours]:[Minutes] without leading zeros, so 7:1 is fine, 07:01 is not' - }, { - css: 'idrinth-line', - type: 'p', - children: [ { - type: '#text', - content: 'Get your search-favorites from ' - }, { - type: 'a', - attributes: [ { - name: 'href', - value: 'https://dotd.idrinth.de/' + idrinth.platform + '/' - }, { - name: 'target', - value: '_blank' - } ], - content: 'Idrinth\'s Raidsearch' - } ] - } ]; - }; - var buildLand = function () { - var buildItem = function ( label ) { - return { - type: 'tr', - children: [ { - type: 'th', - content: label - }, { - type: 'td', - children: [ { - type: 'input', - id: 'idrinth-land-' + label.toLowerCase (), - attributes: [ - { - name: 'value', - value: idrinth.settings.land[label.toLowerCase ()] - }, - { - name: 'type', - value: 'number' - } - ] - } ] - }, { - type: 'td', - content: '-' - } ], - attributes: [ - { - name: 'title', - value: idrinth.land.data[label.toLowerCase ()].perHour + ' gold per hour each' - } - ] - }; - }; - return [ { - type: 'table', - id: 'idrinth-land-buy-table', - children: [ - buildItem ( 'Cornfield' ), - buildItem ( 'Stable' ), - buildItem ( 'Barn' ), - buildItem ( 'Store' ), - buildItem ( 'Pub' ), - buildItem ( 'Inn' ), - buildItem ( 'Tower' ), - buildItem ( 'Fort' ), - buildItem ( 'Castle' ), - { - type: 'tr', - children: [ { - type: 'td' - }, { - type: 'td' - }, { - type: 'td' - } ] - }, - { - type: 'tr', - children: [ { - type: 'th', - content: 'Avaible Gold' - }, { - type: 'td', - children: [ { - type: 'input', - id: 'idrinth-land-gold', - attributes: [ - { - name: 'value', - value: idrinth.settings.land.gold - }, - { - name: 'type', - value: 'number' - } - ] - } ] - }, { - type: 'td', - children: [ { - type: 'button', - content: 'Calculate', - attributes: [ - { - name: 'onclick', - value: 'idrinth.land.calculate();' - }, - { - name: 'type', - value: 'button' - } - ] - } ] - } ] - } - ] - } ]; - }; - var makeTabs = function ( config ) { - var head = [ ]; - var first = true; - var body = [ ]; - var buildHead = function ( name, width, first ) { - return { - type: 'li', - content: name, - css: 'tab-activator' + ( first ? ' active' : '' ), - id: 'tab-activator-' + name.toLowerCase (), - attributes: [ - { - name: 'onclick', - value: 'idrinth.ui.activateTab(\'' + name.toLowerCase () + '\');' - }, - { - name: 'style', - value: 'width:' + width + '%;' - } - ] - }; - }; - var buildBody = function ( name, children, first ) { - return { - type: 'li', - css: 'tab-element' + ( first ? '' : ' idrinth-hide' ), - id: 'tab-element-' + name.toLowerCase (), - children: children - }; - }; - var width = Math.floor ( 100 / ( Object.keys ( config ) ).length ); - for (var name in config) { - if ( typeof name === 'string' ) { - head.push ( buildHead ( name, width, first ) ); - body.push ( buildBody ( name, config[name], first ) ); - first = false; - } - } - return [ - { - type: 'ul', - children: head, - css: 'idrinth-ui-menu' - }, - { - type: 'ul', - children: body, - css: 'idrinth-ui-menu', - attributes: [ { - name: 'style', - value: 'max-height: 500px;overflow-y: scroll;' - } ] - } - ]; - }; - var buildRaidJoinList = function () { - return [ { - content: 'click to copy raid link', - type: 'strong' - }, { - id: 'idrinth-raid-link-list' - } ]; - }; - return makeTabs ( { - 'Actions': buildActions (), - 'Raids': buildRaidJoinList (), - 'Settings': buildControls (), - 'Tiers': buildTiers (), - 'Land': buildLand () - } ); - }; - var children = wrapper (); - children.unshift ( { - css: 'idrinth-line', - type: 'strong', - children: [ - { - type: 'span', - content: 'Idrinth\'s' - }, - { - type: 'span', - content: ' DotD Script v' + idrinth.version - } - ], - attributes: [ { - name: 'title', - value: 'Click to open/close' - }, { - name: 'onclick', - value: 'idrinth.ui.openCloseSettings();' - }, { - name: 'style', - value: 'display:block;cursor:pointer;' - } ] - } ); - idrinth.ui.controls = idrinth.ui.buildElement ( { - css: 'idrinth-hovering-box idrinth-controls-overwrite inactive' + ( idrinth.settings.moveLeft ? ' left-sided' : '' ) + ( idrinth.settings.minimalist ? ' small' : '' ), - id: 'idrinth-controls', - children: children - } ); - idrinth.ui.body.appendChild ( idrinth.ui.controls ); - if ( idrinth.settings.chatting ) { - idrinth.ui.body.appendChild ( idrinth.ui.buildBasis.buildChat () ); - idrinth.chat.elements.chats = document.getElementById ( 'idrinth-chat' ).getElementsByTagName ( 'ul' )[1]; - idrinth.chat.elements.menu = document.getElementById ( 'idrinth-chat' ).getElementsByTagName ( 'ul' )[0]; - } - document.getElementById ( 'idrinth-favs' ).setAttribute ( 'onkeyup', 'this.value=this.value.replace(/[^a-f0-9,]/g,\'\')' ); - }, - buildChat: function () { - var makeInput = function ( label ) { - return { - type: 'li', - children: [ - { - type: 'label', - content: label - }, - { - type: 'input', - attributes: [ - { - name: 'type', - value: 'text' - }, - { - name: 'onchange', - value: 'this.setAttribute(\'value\',this.value);' - } - ] - } - ] - }; - }; - var makeButton = function ( label, onclick ) { - return { - type: 'li', - children: [ - { - type: 'button', - attributes: [ - { - name: 'type', - value: 'button' - }, - { - name: 'onclick', - value: onclick - } - ], - content: label - } - ] - }; - }; - return idrinth.ui.buildElement ( { - id: 'idrinth-chat', - css: 'idrinth-hovering-box' + ( !idrinth.settings.chatHiddenOnStart ? ' active' : '' ) + ( idrinth.settings.moveLeft ? ' left-sided' : '' ), - children: [ - { - type: 'button', - content: ( idrinth.settings.chatHiddenOnStart ? '<<' : '>>' ), - attributes: [ { - name: 'onclick', - value: 'idrinth.chat.openCloseChat(this);' - } ] - }, { - type: 'ul', - css: 'styles-scrollbar chat-labels', - children: [ { - type: 'li', - css: 'active', - content: "\u2699", - attributes: [ - { - name: 'onclick', - value: 'idrinth.chat.enableChat(this);' - }, - { - name: 'data-id', - value: '0' - } - ] - } ] - }, { - type: 'ul', - css: 'chat-tabs', - children: [ { - type: 'li', - css: 'styles-scrollbar active', - attributes: [ - { - name: 'data-id', - value: '0' - } - ], - children: [ - { - type: 'h1', - content: 'Chat' - }, - { - type: 'p', - content: 'This part of the script is optional, so logging in is unneeded for raid catching etc.' - }, { - id: 'idrinth-chat-login', - children: [ - { - type: 'h2', - content: 'Account' - }, - { - type: 'p', - content: 'This should not be the data for logging in on the related gaming site and the login does not need to match your ingame name - you can set a display name after the registration.' - }, - { - type: 'ul', - css: 'settings', - children: [ - makeInput ( 'Username' ), - makeInput ( 'Password' ), - makeButton ( "Not logged in, click to login/register", "idrinth.chat.login()" ) - ] - } - ] - }, { - id: 'idrinth-add-chat', - children: [ - { - type: 'h2', - content: 'Join Chat' - }, - { - type: 'ul', - css: 'settings', - children: [ - makeInput ( 'Chat-ID' ), - makeInput ( 'Chat-Password' ), - makeButton ( "Click to join additional chat", "idrinth.chat.add()" ) - ] - } - ] - }, - { - id: 'idrinth-make-chat', - children: [ - { - type: 'h2', - content: 'Create Chat' - }, - { - type: 'ul', - css: 'settings', - children: [ - makeInput ( "Name" ), - makeButton ( "Click to create additional chat", "idrinth.chat.create()" ) - ] - } - ] - }, { - type: 'li', - children: [ - { - type: '#text', - content: 'More settings at ' - }, - { - type: 'a', - content: 'dotd.idrinth.de/' + idrinth.platform + '/chat/', - attributes: [ - { - name: 'target', - value: '_blank' - }, - { - name: 'href', - value: 'https://dotd.idrinth.de/' + idrinth.platform + '/chat/' - } - ] - }, - { - type: '#text', - content: '.' - } - ] - }, { - type: 'li', - children: [ - { - type: '#text', - content: 'Emoticons provided by ' - }, - { - type: 'a', - content: 'emoticonshd.com', - attributes: [ - { - name: 'target', - value: '_blank' - }, - { - name: 'href', - value: 'http://emoticonshd.com/' - } - ] - }, - { - type: '#text', - content: '.' - } - ] - } - ] - } - ] - } - ] - } ); - }, - war: function ( ) { - return idrinth.ui.buildElement ( - { - id: 'idrinth-war', - css: 'idrinth-central-box idrinth-hovering-box idrinth-hide', - children: [ - { - children: [ - { - type: 'span', - content: 'current WAR' - }, - { - type: 'span', - css: 'idrinth-circle', - content: '\u2195' - } - ] - }, - { - type: 'table', - children: [ - { - type: 'thead', - children: [ - { - type: 'tr', - children: [ - { - type: 'th', - content: 'summon?' - }, - { - type: 'th', - content: 'raid' - }, - { - type: 'th', - content: 'join' - }, - { - type: 'th', - content: 'magic2use' - } - ] - } - ] - }, - { - type: 'tbody' - } - ] - } - ] - } - ); - }, - buildTooltip: function ( ) { - 'use strict'; - function getServerPart ( name ) { - return [ { - css: 'idrinth-line idrinth-tooltip-header', - type: 'a', - attributes: [ { - name: 'href', - value: '#' - }, { - name: 'target', - value: '_blank' - }, { - name: 'title', - value: 'go to summoner details' - } ] - }, { - css: 'idrinth-line idrinth-tooltip-level', - type: 'span', - children: [ { - type: '#text', - content: 'Level ' - }, { - css: 'idrinth-format-number idrinth-format-level', - type: 'span', - content: '0' - }, { - type: '#text', - content: ' ' - }, { - css: 'idrinth-format-class', - type: 'span', - content: 'Unknown' - } ] - }, { - css: 'idrinth-line idrinth-tooltip-guild', - type: 'span', - children: [ { - type: '#text', - content: 'of ' - }, { - css: 'idrinth-format-guild', - type: 'a', - attributes: [ { - name: 'href', - 'value': '#' - }, { - name: 'title', - value: 'go to guild details' - }, { - name: 'target', - value: '_blank' - } ] - } ] - }, { - css: 'idrinth-line idrinth-tooltip-update', - type: 'span', - children: [ { - type: '#text', - content: 'Updated ' - }, { - css: 'idrinth-format-date', - type: 'span', - content: 'Unknown' - } ] - }, { - type: 'span', - content: 'Server: ' + name - } ]; - } - idrinth.ui.tooltip = idrinth.ui.buildElement ( { - css: 'idrinth-hovering-box idrinth-tooltip-overwrite idrinth-hide', - id: 'idrinth-tooltip', - children: [ - { - children: getServerPart ( 'Kongregate' ) - }, - { - children: getServerPart ( 'World' ) - } - ], - attributes: [ - { - name: 'onmouseenter', - value: 'idrinth.names.isHovering=true;' - }, - { - name: 'onmouseleave', - value: 'idrinth.names.isHovering=false;' - } - ] - } ); - idrinth.ui.body.appendChild ( idrinth.ui.tooltip ); - } -}; diff --git a/mods/ui.js b/mods/ui.js new file mode 100644 index 0000000..dc5e0ae --- /dev/null +++ b/mods/ui.js @@ -0,0 +1,785 @@ +idrinth.ui = { + tooltip: null, + formatNumber: function ( number ) { + if ( isNaN ( number ) ) { + return ''; + } + var count = 0; + var post = [ '', 'k', 'm', 'b', 't', 'qa', 'qi', 's' ]; + while ( number > 999 && count < post.length ) { + number = Math.round ( number / 10 ) / 100; + count++; + } + return number.toString () + post[count]; + }, + buildChat: function ( id, name, rank, pass ) { + if ( !idrinth.chat.elements.chats ) { + window.setTimeout ( function () { + idrinth.ui.buildChat ( id, name, rank, pass ); + }, 500 ); + } + idrinth.chat.elements.chats.appendChild ( idrinth.ui.buildElement ( { + type: 'li', + id: 'idrinth-chat-tab-' + id, + css: rank.toLowerCase (), + attributes: [ + { + name: 'data-id', + value: id + } + ], + children: [ + { + type: 'ul', + css: "styled-scrollbar users" + }, + { + type: 'ul', + css: "styled-scrollbar chat" + }, + { + type: 'input', + css: 'add-chat-box', + id: "idrinth-chat-input-" + id, + attributes: [ + { + name: 'title', + value: 'press ENTER or RETURN to send' + }, + { + name: 'onkeyup', + value: 'if(event.keyCode===13||event.which===13){idrinth.chat.send(' + id + ');}' + } + ] + } + ] + } ) ); + idrinth.chat.elements.menu.appendChild ( + idrinth.ui.buildElement ( + { + type: 'li', + content: name, + id: 'idrinth-chat-tab-click-' + id, + attributes: [ + { + name: 'data-id', + value: id + }, + { + name: 'title', + value: name + "\nID:" + id + "\nPassword: " + pass + }, + { + name: 'onclick', + value: 'idrinth.chat.enableChat(this);' + }, + { + name: 'oncontextmenu', + value: 'idrinth.chat.showOptions(event,this);' + } + ] + } + ) + ); + }, + getElementPositioning: function ( element, offsetX, offsetY ) { + var pos = { + x: element.getBoundingClientRect ().left + ( offsetX ? offsetX : 0 ), + y: element.getBoundingClientRect ().top + ( offsetY ? offsetY : 0 ) + }; + return 'position:fixed;left:' + pos.x + 'px;top:' + pos.y + 'px'; + }, + buildElement: function ( config ) { + 'use strict'; + var setBase = function ( el, config ) { + if ( config.id ) { + el.id = config.id; + } + if ( config.css ) { + el.setAttribute ( 'class', config.css ); + } + if ( config.content ) { + el.appendChild ( document.createTextNode ( config.content ) ); + } + }; + var addChildren = function ( el, config ) { + if ( !config.children || !config.children.length ) { + return; + } + for (var count = 0, l = config.children.length; count < l; count++) { + el.appendChild ( idrinth.ui.buildElement ( config.children[count] ) ); + } + }; + var addAttributes = function ( el, config ) { + var applyValue = function ( el, set ) { + if ( !set || set.value === undefined ) { + return; + } + if ( set.name ) { + set.names = [ set.name ]; + } + if ( set.names && Array.isArray ( set.names ) ) { + for (var pos = 0; pos < set.names.length; pos++) { + el.setAttribute ( set.names[pos], set.value ); + } + } + }; + if ( !config.attributes || !config.attributes.length ) { + return; + } + for (var count = 0, l = config.attributes.length; count < l; count++) { + applyValue ( el, config.attributes[count] ); + } + }; + var makeInputLabel = function ( config ) { + 'use strict'; + var inArray = function ( value, list ) { + 'use strict'; + if ( !Array.isArray ( list ) ) { + return false; + } + if ( typeof list.includes === 'function' ) { + return list.includes ( value ); + } + return list.indexOf ( value ) > -1; + }; + var input = [ { + name: 'type', + value: config.type + } ]; + if ( idrinth.settings[config.name] && config.type === 'checkbox' ) { + input.push ( { + name: 'checked', + value: 'checked' + } ); + } + if ( config.type !== 'checkbox' ) { + input.push ( { + name: 'value', + value: idrinth.settings[config.name] + } ); + input.push ( { + name: 'onchange', + value: 'idrinth.settings.change(\'' + config.name + '\',this.value)' + } ); + } else { + input.push ( { + name: 'onchange', + value: 'idrinth.settings.change(\'' + config.name + '\',this.checked)' + } ); + } + return idrinth.ui.buildElement ( { + css: 'idrinth-line' + ( config.platforms && !inArray ( idrinth.platform, config.platforms ) ? ' idrinth-hide' : '' ), + children: [ { + type: 'label', + css: 'idrinth-float-half', + content: config.label, + attributes: [ { + name: 'for', + value: 'idrinth-' + config.name + } ] + }, { + type: 'input', + css: 'idrinth-float-half', + id: 'idrinth-' + config.name, + attributes: input + } ] + } ); + }; + if ( config.type === '#text' ) { + return document.createTextNode ( config.content ); + } + if ( config.rType === '#input' ) { + return makeInputLabel ( config ); + } + var el = document.createElement ( config.type ? config.type : 'div' ); + setBase ( el, config ); + addChildren ( el, config ); + addAttributes ( el, config ); + return el; + }, + controls: null, + tooltipTO: null, + buildModal: function ( title, content, altFunc ) { + var mod = { + children: [ ], + css: 'idrinth-hovering-box idrinth-popup idrinth-' + ( typeof altFunc === 'string' ? 'confim' : 'alert' ) + }; + if ( typeof title === 'string' ) { + mod.children.push ( { + content: title, + css: 'header' + } ); + } else { + mod.children.push ( { + content: 'Title missing', + css: 'header' + } ); + } + if ( typeof content === 'string' ) { + mod.children.push ( { + content: content, + css: 'content' + } ); + } else if ( typeof content === 'object' && content.type ) { + mod.children.push ( { + children: content, + css: 'content' + } ); + } else { + mod.children.push ( { + children: 'Content missing', + css: 'content' + } ); + } + mod.children.push ( { + css: 'buttons' + } ); + var closeFunc = 'this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);'; + if ( typeof altFunc === 'string' ) { + mod.children[mod.children.length - 1].children = [ { + type: 'button', + content: 'Ok', + attributes: [ { + name: 'onclick', + value: altFunc + } ] + }, { + type: 'button', + content: 'Cancel', + attributes: [ { + name: 'onclick', + value: closeFunc + } ] + } ]; + } else { + mod.children[mod.children.length - 1].children = [ { + type: 'button', + content: 'Ok', + attributes: [ { + name: 'onclick', + value: closeFunc + } ] + } ]; + } + idrinth.ui.body.appendChild ( idrinth.ui.buildElement ( mod ) ); + }, + showTooltip: function ( element ) { + 'use strict'; + function tooltip ( set, element, world ) { + if ( !set ) { + idrinth.ui.updateClassesList ( element, [ 'idrinth-hide' ], [ ] ); + return; + } + var baseUrl = 'https://dotd.idrinth.de/' + ( world ? 'world-kongregate' : 'kongregate' ); + idrinth.ui.updateClassesList ( idrinth.ui.tooltip, [ ], [ 'idrinth-hide' ] ); + idrinth.ui.updateClassesList ( element, [ ], [ 'idrinth-hide' ] ); + element.childNodes[0].setAttribute ( 'href', baseUrl + '/summoner/' + set.id + '/' ); + element.childNodes[0].innerHTML = set.name; + element.childNodes[1].childNodes[1].innerHTML = set.level + ' (' + set['7day'] + '/week, ' + set['30day'] + '/month)'; + element.childNodes[1].childNodes[3].innerHTML = idrinth.names.classes[set.class]; + element.childNodes[2].childNodes[1].setAttribute ( 'href', baseUrl + '/guild/' + set.guildId + '/' ); + element.childNodes[2].childNodes[1].innerHTML = idrinth.names.guilds[world ? 'world' : 'kongregate'][set.guildId]; + element.childNodes[3].childNodes[1].innerHTML = set.updated; + element.childNodes[3].setAttribute ( 'style', ( new Date () ) - ( new Date ( set.updated ) ) > 86400000 ? 'color:#aa0000;' : '' ); + } + idrinth.names.isHovering = false; + var name = idrinth.names.parse ( element ).toLowerCase ( ); + if ( idrinth.settings.names && idrinth.ui.tooltip && idrinth.names.users[name] ) { + window.clearTimeout ( idrinth.ui.tooltipTO ); + idrinth.ui.tooltip.setAttribute ( 'style', idrinth.ui.getElementPositioning ( element, -200, -100 ) ); + tooltip ( idrinth.names.users[name].kongregate, idrinth.ui.tooltip.firstChild, false ); + tooltip ( idrinth.names.users[name].world, idrinth.ui.tooltip.lastChild, true ); + idrinth.ui.tooltipTO = window.setTimeout ( idrinth.ui.hideTooltip, idrinth.settings.timeout ? idrinth.settings.timeout : 5000 ); + } + }, + hideTooltip: function () { + if ( idrinth.names.isHovering ) { + idrinth.ui.tooltipTO = window.setTimeout ( idrinth.ui.hideTooltip, idrinth.settings.timeout ? idrinth.settings.timeout : 5000 ); + return; + } + idrinth.ui.updateClassesList ( idrinth.ui.tooltip, [ 'idrinth-hide' ], [ ] ); + }, + openCloseSettings: function ( ) { + 'use strict'; + var toRemove = [ ( idrinth.ui.controls.getAttribute ( 'class' ) ).match ( /(^|\s)inactive($|\s)/ ) ? 'inactive' : 'active' ]; + if ( !idrinth.settings.moveLeft ) { + toRemove.push ( 'left-sided' ); + } + if ( !idrinth.settings.minimalist ) { + toRemove.push ( 'small' ); + } + idrinth.ui.updateClassesList ( idrinth.ui.controls, [ 'active', 'inactive', 'left-sided', 'small' ], toRemove ); + }, + childOf: function ( element, cssClass ) { + 'use strict'; + do { + if ( element.className.match ( new RegExp ( '(^|\s)' + cssClass + '(\s|$)' ) ) ) { + return true; + } + if ( !element.parentNode || element === document.getElementsByTagName ( 'body' )[0] ) { + return false; + } + element = element.parentNode; + } while ( element ); + return false; + }, + removeElement: function ( id ) { + 'use strict'; + var el = document.getElementById ( id ); + if ( el ) { + el.parentNode.removeChild ( el ); + } + }, + reloadGame: function ( ) { + 'use strict'; + var handleFrame = function ( parent ) { + var frame = parent.getElementsByTagName ( 'iframe' )[0]; + frame.setAttribute ( 'src', ( frame.getAttribute ( 'src' ) ).replace ( /&ir=.*/, '' ) + '&ir=' + Math.random () ); + }; + try { + if ( idrinth.platform === 'kongregate' ) { + window.activateGame ( ); + } else if ( idrinth.platform === 'dawnofthedragons' ) { + handleFrame ( document ); + } else if ( idrinth.platform === 'newgrounds' ) { + handleFrame ( document.getElementById ( 'iframe_embed' ) ); + } else if ( idrinth.platform === 'armorgames' ) { + handleFrame ( document.getElementById ( 'gamefilearea' ) ); + } + } catch ( e ) { + idrinth.core.alert ( 'The game couldn\'t be reloaded' ); + } + }, + updateClassesList: function ( element, add, remove ) { + var getClassesList = function ( classString, add, remove ) { + var forceToArray = function ( value ) { + return value && typeof value === 'object' && Array.isArray ( value ) ? value : [ ]; + }; + var original = classString === null ? [ ] : classString.split ( ' ' ).concat ( forceToArray ( add ) ); + var list = [ ]; + remove = forceToArray ( remove ); + var addUnique = function ( list, element, forbidden ) { + if ( list.indexOf ( element ) === -1 && forbidden.indexOf ( element ) === -1 ) { + list.push ( element ); + } + return list; + }; + for (var counter = 0; counter < original.length; counter++) { + list = addUnique ( list, original[counter], remove ); + } + return list.join ( ' ' ); + }; + element.setAttribute ( 'class', getClassesList ( element.getAttribute ( 'class' ), add, remove ) ); + }, + activateTab: function ( name ) { + var head = document.getElementById ( 'tab-activator-' + name ).parentNode.childNodes; + var body = document.getElementById ( 'tab-element-' + name ).parentNode.childNodes; + var setClasses = function ( head, body, name ) { + if ( head === document.getElementById ( 'tab-activator-' + name ) ) { + idrinth.ui.updateClassesList ( head, [ 'active' ], [ ] ); + idrinth.ui.updateClassesList ( body, [ ], [ 'idrinth-hide' ] ); + return; + } + idrinth.ui.updateClassesList ( head, [ ], [ 'active' ] ); + idrinth.ui.updateClassesList ( body, [ 'idrinth-hide' ], [ ] ); + }; + for (var count = 0; count < head.length; count++) { + setClasses ( head[count], body[count], name ); + } + }, + start: function ( ) { + 'use strict'; + var build = function () { + 'use strict'; + var wrapper = function ( ) { + var buildActions = function () { + var buttonMaker = function ( label, onclick, platform ) { + return { + css: 'idrinth-float-half' + ( platform && platform !== idrinth.platform ? " idrinth-hide" : "" ), + type: 'button', + content: label, + attributes: [ { + name: 'type', + value: 'button' + }, { + name: 'onclick', + value: onclick + } ] + }; + }; + return [ { + children: [ + buttonMaker ( 'Import all manually', 'idrinth.raids.import(\'\');' ), + buttonMaker ( 'Import favs manually', 'idrinth.raids.import(idrinth.settings.favs);' ), + buttonMaker ( 'Reload game', 'idrinth.ui.reloadGame();' ), + buttonMaker ( 'Clear Raids', 'idrinth.raids.clearAll();' ), + buttonMaker ( 'Reload Script', 'idrinth.reload();' ), + buttonMaker ( 'Restart Raidjoin', 'idrinth.raids.restartInterval();' ), + buttonMaker ( 'Refresh Facebook Game Login', 'idrinth.facebook.rejoin()', 'facebook' ), + buttonMaker ( 'NG Raid Join(slow!)', 'idrinth.newgrounds.joinRaids()', 'newgrounds' ), + buttonMaker ( idrinth.settings.alarmActive ? 'disable timed Autojoin' : 'enable timed Autojoin', 'idrinth.settings.change(\'alarmActive\',!idrinth.settings.alarmActive);this.innerHTML=idrinth.settings.alarmActive?\'disable timed Autojoin\':\'enable timed Autojoin\'', 'newgrounds' ) + ] + }, { + css: 'idrinth-line', + id: 'idrinth-joined-raids', + content: 'Last raids joined:', + children: [ + { + type: 'ul' + } + ] + } + ]; + }; + var buildTiers = function () { + return [ { + css: 'idrinth-line', + children: [ { + type: 'label', + content: 'Enter Boss\' Name', + css: 'idrinth-float-half', + attributes: [ + { + name: 'for', + value: 'idrinth-tierlist-bosssearch' + } + ] + }, { + type: 'input', + css: 'idrinth-float-half', + id: 'idrinth-tierlist-bosssearch', + attributes: [ + { + names: [ 'onblur', 'onchange', 'onkeyup' ], + value: 'idrinth.tier.getTierForName(this.value);' + } + ] + } ] + }, { + id: 'idrinth-tierlist' + } ]; + }; + var buildControls = function () { + 'use strict'; + return [ { + name: 'names', + rType: '#input', + type: 'checkbox', + platforms: [ 'kongregate' ], + label: 'Enable extended Characterinformation?' + }, { + name: 'minimalist', + rType: '#input', + type: 'checkbox', + label: 'Minimalist Layout' + }, { + name: 'moveLeft', + rType: '#input', + type: 'checkbox', + label: 'Move settings left' + }, { + name: 'warBottom', + rType: '#input', + type: 'checkbox', + label: 'Show war at the bottom of the page' + }, { + name: 'landMax', + rType: '#input', + type: 'checkbox', + label: 'Check to try and use up the gold as efficient as possible - uncheck to only use the most efficient buy in the land buy calculator' + }, { + name: 'factor', + rType: '#input', + type: 'checkbox', + label: 'Buy 10 Buildings at once?(Rec)' + }, { + name: 'timeout', + rType: '#input', + type: 'number', + platforms: [ 'kongregate' ], + label: 'Milliseconds until the extended Characterinformation disappears' + }, { + name: 'newgroundLoad', + rType: '#input', + type: 'number', + platforms: [ 'newgrounds' ], + label: 'Seconds needed to load the game for joining' + }, { + name: 'chatting', + rType: '#input', + type: 'checkbox', + label: 'Enable chat(needs script reload)' + }, { + css: 'idrinth-line', + type: 'span', + content: 'This script will always import the raids you manually set to be imported on the website and if it\'s enabled it will also import all raids matched by one of the faved searches provided.' + }, { + name: 'raids', + rType: '#input', + type: 'checkbox', + label: 'Enable Auto-Raid-Request for Favorites?' + }, { + name: 'favs', + rType: '#input', + type: 'text', + label: 'FavoriteIds to join (separate multiple by comma)' + }, { + name: 'isWorldServer', + rType: '#input', + type: 'checkbox', + label: 'Worldserver?' + }, { + name: 'notificationActive', + rType: '#input', + type: 'checkbox', + label: 'enable chat notifications?' + }, { + name: 'windows', + rType: '#input', + type: 'number', + platforms: [ 'dawnofthedragons' ], + label: 'Maximum Popups/Frames for joining raids' + }, { + name: 'alarmTime', + rType: '#input', + type: 'text', + platforms: [ 'newgrounds' ], + label: 'Time to automatically join raids slowly(reloads game multiple times). Format is [Hours]:[Minutes] without leading zeros, so 7:1 is fine, 07:01 is not' + }, { + css: 'idrinth-line', + type: 'p', + children: [ { + type: '#text', + content: 'Get your search-favorites from ' + }, { + type: 'a', + attributes: [ { + name: 'href', + value: 'https://dotd.idrinth.de/' + idrinth.platform + '/' + }, { + name: 'target', + value: '_blank' + } ], + content: 'Idrinth\'s Raidsearch' + } ] + } ]; + }; + var buildLand = function () { + var buildItem = function ( label ) { + return { + type: 'tr', + children: [ { + type: 'th', + content: label + }, { + type: 'td', + children: [ { + type: 'input', + id: 'idrinth-land-' + label.toLowerCase (), + attributes: [ + { + name: 'value', + value: idrinth.settings.land[label.toLowerCase ()] + }, + { + name: 'type', + value: 'number' + } + ] + } ] + }, { + type: 'td', + content: '-' + } ], + attributes: [ + { + name: 'title', + value: idrinth.land.data[label.toLowerCase ()].perHour + ' gold per hour each' + } + ] + }; + }; + return [ { + type: 'table', + id: 'idrinth-land-buy-table', + children: [ + buildItem ( 'Cornfield' ), + buildItem ( 'Stable' ), + buildItem ( 'Barn' ), + buildItem ( 'Store' ), + buildItem ( 'Pub' ), + buildItem ( 'Inn' ), + buildItem ( 'Tower' ), + buildItem ( 'Fort' ), + buildItem ( 'Castle' ), + { + type: 'tr', + children: [ { + type: 'td' + }, { + type: 'td' + }, { + type: 'td' + } ] + }, + { + type: 'tr', + children: [ { + type: 'th', + content: 'Avaible Gold' + }, { + type: 'td', + children: [ { + type: 'input', + id: 'idrinth-land-gold', + attributes: [ + { + name: 'value', + value: idrinth.settings.land.gold + }, + { + name: 'type', + value: 'number' + } + ] + } ] + }, { + type: 'td', + children: [ { + type: 'button', + content: 'Calculate', + attributes: [ + { + name: 'onclick', + value: 'idrinth.land.calculate();' + }, + { + name: 'type', + value: 'button' + } + ] + } ] + } ] + } + ] + } ]; + }; + var makeTabs = function ( config ) { + var head = [ ]; + var first = true; + var body = [ ]; + var buildHead = function ( name, width, first ) { + return { + type: 'li', + content: name, + css: 'tab-activator' + ( first ? ' active' : '' ), + id: 'tab-activator-' + name.toLowerCase (), + attributes: [ + { + name: 'onclick', + value: 'idrinth.ui.activateTab(\'' + name.toLowerCase () + '\');' + }, + { + name: 'style', + value: 'width:' + width + '%;' + } + ] + }; + }; + var buildBody = function ( name, children, first ) { + return { + type: 'li', + css: 'tab-element' + ( first ? '' : ' idrinth-hide' ), + id: 'tab-element-' + name.toLowerCase (), + children: children + }; + }; + var width = Math.floor ( 100 / ( Object.keys ( config ) ).length ); + for (var name in config) { + if ( typeof name === 'string' ) { + head.push ( buildHead ( name, width, first ) ); + body.push ( buildBody ( name, config[name], first ) ); + first = false; + } + } + return [ + { + type: 'ul', + children: head, + css: 'idrinth-ui-menu' + }, + { + type: 'ul', + children: body, + css: 'idrinth-ui-menu', + attributes: [ { + name: 'style', + value: 'max-height: 500px;overflow-y: scroll;' + } ] + } + ]; + }; + var buildRaidJoinList = function () { + return [ { + content: 'click to copy raid link', + type: 'strong' + }, { + id: 'idrinth-raid-link-list' + } ]; + }; + return makeTabs ( { + 'Actions': buildActions (), + 'Raids': buildRaidJoinList (), + 'Settings': buildControls (), + 'Tiers': buildTiers (), + 'Land': buildLand () + } ); + }; + var children = wrapper (); + children.unshift ( { + css: 'idrinth-line', + type: 'strong', + children: [ + { + type: 'span', + content: 'Idrinth\'s' + }, + { + type: 'span', + content: ' DotD Script v' + idrinth.version + } + ], + attributes: [ { + name: 'title', + value: 'Click to open/close' + }, { + name: 'onclick', + value: 'idrinth.ui.openCloseSettings();' + }, { + name: 'style', + value: 'display:block;cursor:pointer;' + } ] + } ); + idrinth.ui.controls = idrinth.ui.buildElement ( { + css: 'idrinth-hovering-box idrinth-controls-overwrite inactive' + ( idrinth.settings.moveLeft ? ' left-sided' : '' ) + ( idrinth.settings.minimalist ? ' small' : '' ), + id: 'idrinth-controls', + children: children + } ); + idrinth.ui.body.appendChild ( idrinth.ui.controls ); + document.getElementById ( 'idrinth-favs' ).setAttribute ( 'onkeyup', 'this.value=this.value.replace(/[^a-f0-9,]/g,\'\')' ); + }; + idrinth.ui.body = document.getElementsByTagName ( 'body' )[0]; + document.getElementsByTagName ( 'head' )[0].appendChild ( idrinth.ui.buildElement ( { + type: 'link', + attributes: [ { + name: 'rel', + value: 'stylesheet' + }, { + name: 'href', + value: 'https://dotd.idrinth.de###PATH###/script-styles.css?###VERSION###' + } ] + } ) ); + build (); + } +}; \ No newline at end of file diff --git a/mods/war.js b/mods/war.js index 8c10d72..f2a2a4b 100644 --- a/mods/war.js +++ b/mods/war.js @@ -1,186 +1,245 @@ -idrinth.war = { - from: null, - to: null, - element: null, - getData: function () { - var raids2Join = function () { - var list = [ ]; - for (var input in idrinth.war.element.getElementsByTagName ( 'input' )) { - if ( idrinth.war.element.getElementsByTagName ( 'input' )[input].checked ) { - list.push ( idrinth.war.element.getElementsByTagName ( 'input' )[input].getAttribute ( 'data-id' ) ); - } - } - if ( list.length > 0 ) { - return list.join ( ',' ); - } - return '_'; - }; - idrinth.core.ajax.run ( - "https://dotd.idrinth.de/" + ( idrinth.settings.isWorldServer ? "world-" : "" ) + idrinth.platform + "/war-service/" + raids2Join () + "/" + Date.now () + "/", - idrinth.war.updateData, - function () { - window.setTimeout ( idrinth.war.getData, 1000 ); - }, - function () { - window.setTimeout ( idrinth.war.getData, 2000 ); - }, - idrinth.raids.knowRaids () - ); - }, - updateData: function ( data ) { - var process = function ( data ) { - var toggleGUI = function ( onOff ) { - var toggle = onOff || false; - var addClasses = [ ]; - var removeClasses = [ ]; - if ( toggle === true ) { - removeClasses.push ( 'idrinth-hide' ); - addClasses.push ( "bottom" ); - if ( !idrinth.settings.warBottom ) { - removeClasses.push ( "bottom" ); - } - } else { - addClasses.push ( "idrinth-hide" ); - while ( idrinth.war.element.childNodes[1].childNodes[1].firstChild ) { - idrinth.war.element.childNodes[1].childNodes[1].removeChild ( idrinth.war.element.childNodes[1].firstChild.firstChild ); - } - } - idrinth.ui.updateClassesList ( idrinth.war.element, addClasses, removeClasses ); - }; - var processJson = function ( data ) { - var magicIgmSrv = 'https://dotd.idrinth.de/static/magic-image-service/'; - var getMagic = function ( data ) { - var magics = [ ], - tmp; - if ( !data || ( data.magics === null || data.magics === '' ) ) { - return [ ]; - } - tmp = data.magics.split ( ',' ); - for (var key = 0; key < tmp.length; key++) { - var magic = tmp[key]; - var magicObj = { - type: 'img', - attributes: [ - { - name: 'src', - value: magicIgmSrv + magic + '/' - }, - { - name: 'width', - value: '20' - } ] - }; - magics.push ( magicObj ); - } - return magics; - }; - function addRaids ( raids ) { - for (var key in raids) { - if ( idrinth.raids.joined[key] === undefined && idrinth.raids.list[key] === undefined ) { - idrinth.raids.list[key] = raids[key]; - } - } - } - function updateBoss ( data, element ) { - //TODO: Dummy function, should be removed - function cleanUp () { - while ( element.getElementsByTagName ( 'td' )[3].firstChild ) { - element.getElementsByTagName ( 'td' )[3].removeChild ( element.getElementsByTagName ( 'td' )[3].firstChild ); - } - } - - cleanUp (); - var tmpMagics = getMagic ( data ); - for (var m = 0; m < tmpMagics.length; m++) { - element.getElementsByTagName ( 'td' )[3].appendChild ( idrinth.ui.buildElement ( tmpMagics[m] ) ); - } - element.getElementsByTagName ( 'td' )[0].setAttribute ( "class", 'traffic ' + ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ) ); - element.getElementsByTagName ( 'td' )[0].setAttribute ( "title", data.amount + '/100' ); - element.getElementsByTagName ( 'td' )[0].firstChild.innerHTML = ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ); - } - function newBoss ( data, boss ) { - idrinth.war.element.childNodes[1].appendChild ( idrinth.ui.buildElement ( - { - type: 'tr', - id: 'idrinth-war-' + boss, - children: [ - { - type: 'td', - css: 'traffic ' + ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ), - children: [ { - type: 'span', - content: ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ) - } ], - attributes: [ - { - name: 'title', - value: data.amount + '/100' - } - ] - }, - { - type: 'td', - content: data.name - }, - { - type: 'td', - children: [ - { - type: 'input', - attributes: [ - { - name: 'type', - value: 'checkbox' - }, - { - name: 'data-id', - value: boss - }, - { - name: 'title', - value: 'join ' + data.name - } - ] - } - ] - }, - { - type: 'td', - children: getMagic ( data ) - } - ] - } - ) ); - } - if ( data.raids !== undefined ) { - addRaids ( data.raids ); - } - for (var boss in data.stats) { - if ( document.getElementById ( 'idrinth-war-' + boss ) ) { - updateBoss ( data.stats[boss], document.getElementById ( 'idrinth-war-' + boss ) ); - } else { - newBoss ( data.stats[boss], boss ); - } - } - }; - if ( data === "" || data === "null" ) { - return; - } - if ( data === "{}" ) { - toggleGUI ( false ); - return; - } - toggleGUI ( true ); - try { - processJson ( JSON.parse ( data ) ); - } catch ( e ) { - idrinth.core.log ( e ); - } - }; - process ( data ); - window.setTimeout ( idrinth.war.getData, 50000 + Math.random () % 20000 ); - }, - start: function () { - window.setTimeout ( idrinth.war.getData, 5000 ); - } +idrinth.war = { + from: null, + to: null, + element: null, + getData: function () { + var raids2Join = function () { + var list = [ ]; + for (var input in idrinth.war.element.getElementsByTagName ( 'input' )) { + if ( idrinth.war.element.getElementsByTagName ( 'input' )[input].checked ) { + list.push ( idrinth.war.element.getElementsByTagName ( 'input' )[input].getAttribute ( 'data-id' ) ); + } + } + if ( list.length > 0 ) { + return list.join ( ',' ); + } + return '_'; + }; + idrinth.core.ajax.run ( + "https://dotd.idrinth.de/" + ( idrinth.settings.isWorldServer ? "world-" : "" ) + idrinth.platform + "/war-service/" + raids2Join () + "/" + Date.now () + "/", + idrinth.war.updateData, + function () { + window.setTimeout ( idrinth.war.getData, 1000 ); + }, + function () { + window.setTimeout ( idrinth.war.getData, 2000 ); + }, + idrinth.raids.knowRaids () + ); + }, + updateData: function ( data ) { + var process = function ( data ) { + var toggleGUI = function ( onOff ) { + var toggle = onOff || false; + var addClasses = [ ]; + var removeClasses = [ ]; + if ( toggle === true ) { + removeClasses.push ( 'idrinth-hide' ); + addClasses.push ( "bottom" ); + if ( !idrinth.settings.warBottom ) { + removeClasses.push ( "bottom" ); + } + } else { + addClasses.push ( "idrinth-hide" ); + while ( idrinth.war.element.childNodes[1].childNodes[1].firstChild ) { + idrinth.war.element.childNodes[1].childNodes[1].removeChild ( idrinth.war.element.childNodes[1].firstChild.firstChild ); + } + } + idrinth.ui.updateClassesList ( idrinth.war.element, addClasses, removeClasses ); + }; + var processJson = function ( data ) { + var magicIgmSrv = 'https://dotd.idrinth.de/static/magic-image-service/'; + var getMagic = function ( data ) { + var magics = [ ], + tmp; + if ( !data || ( data.magics === null || data.magics === '' ) ) { + return [ ]; + } + tmp = data.magics.split ( ',' ); + for (var key = 0; key < tmp.length; key++) { + var magic = tmp[key]; + var magicObj = { + type: 'img', + attributes: [ + { + name: 'src', + value: magicIgmSrv + magic + '/' + }, + { + name: 'width', + value: '20' + } ] + }; + magics.push ( magicObj ); + } + return magics; + }; + function addRaids ( raids ) { + for (var key in raids) { + if ( idrinth.raids.joined[key] === undefined && idrinth.raids.list[key] === undefined ) { + idrinth.raids.list[key] = raids[key]; + } + } + } + function updateBoss ( data, element ) { + //TODO: Dummy function, should be removed + function cleanUp () { + while ( element.getElementsByTagName ( 'td' )[3].firstChild ) { + element.getElementsByTagName ( 'td' )[3].removeChild ( element.getElementsByTagName ( 'td' )[3].firstChild ); + } + } + + cleanUp (); + var tmpMagics = getMagic ( data ); + for (var m = 0; m < tmpMagics.length; m++) { + element.getElementsByTagName ( 'td' )[3].appendChild ( idrinth.ui.buildElement ( tmpMagics[m] ) ); + } + element.getElementsByTagName ( 'td' )[0].setAttribute ( "class", 'traffic ' + ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ) ); + element.getElementsByTagName ( 'td' )[0].setAttribute ( "title", data.amount + '/100' ); + element.getElementsByTagName ( 'td' )[0].firstChild.innerHTML = ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ); + } + function newBoss ( data, boss ) { + idrinth.war.element.childNodes[1].appendChild ( idrinth.ui.buildElement ( + { + type: 'tr', + id: 'idrinth-war-' + boss, + children: [ + { + type: 'td', + css: 'traffic ' + ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ), + children: [ { + type: 'span', + content: ( data.amount < 90 ? 'yes' : ( data.amount > 110 ? 'no' : 'maybe' ) ) + } ], + attributes: [ + { + name: 'title', + value: data.amount + '/100' + } + ] + }, + { + type: 'td', + content: data.name + }, + { + type: 'td', + children: [ + { + type: 'input', + attributes: [ + { + name: 'type', + value: 'checkbox' + }, + { + name: 'data-id', + value: boss + }, + { + name: 'title', + value: 'join ' + data.name + } + ] + } + ] + }, + { + type: 'td', + children: getMagic ( data ) + } + ] + } + ) ); + } + if ( data.raids !== undefined ) { + addRaids ( data.raids ); + } + for (var boss in data.stats) { + if ( document.getElementById ( 'idrinth-war-' + boss ) ) { + updateBoss ( data.stats[boss], document.getElementById ( 'idrinth-war-' + boss ) ); + } else { + newBoss ( data.stats[boss], boss ); + } + } + }; + if ( data === "" || data === "null" ) { + return; + } + if ( data === "{}" ) { + toggleGUI ( false ); + return; + } + toggleGUI ( true ); + try { + processJson ( JSON.parse ( data ) ); + } catch ( e ) { + idrinth.core.log ( e ); + } + }; + process ( data ); + window.setTimeout ( idrinth.war.getData, 50000 + Math.random () % 20000 ); + }, + start: function () { + var build = function ( ) { + idrinth.war.element = idrinth.ui.buildElement ( + { + id: 'idrinth-war', + css: 'idrinth-central-box idrinth-hovering-box idrinth-hide', + children: [ + { + children: [ + { + type: 'span', + content: 'current WAR' + }, + { + type: 'span', + css: 'idrinth-circle', + content: '\u2195' + } + ] + }, + { + type: 'table', + children: [ + { + type: 'thead', + children: [ + { + type: 'tr', + children: [ + { + type: 'th', + content: 'summon?' + }, + { + type: 'th', + content: 'raid' + }, + { + type: 'th', + content: 'join' + }, + { + type: 'th', + content: 'magic2use' + } + ] + } + ] + }, + { + type: 'tbody' + } + ] + } + ] + } + ); + idrinth.ui.body.appendChild ( idrinth.war.element ); + }; + window.setTimeout ( idrinth.war.getData, 5000 ); + build (); + } }; \ No newline at end of file diff --git a/stable.js b/stable.js index d5b0744..a3e1f4f 100644 --- a/stable.js +++ b/stable.js @@ -99,406 +99,6 @@ var idrinth = { }, 1 ); }, platform: '', - ui: { - tooltip: null, - formatNumber: function ( number ) { - if ( isNaN ( number ) ) { - return ''; - } - var count = 0; - var post = [ '', 'k', 'm', 'b', 't', 'qa', 'qi', 's' ]; - while ( number > 999 && count < post.length ) { - number = Math.round ( number / 10 ) / 100; - count++; - } - return number.toString () + post[count]; - }, - buildChat: function ( id, name, rank, pass ) { - if ( !idrinth.chat.elements.chats ) { - window.setTimeout ( function () { - idrinth.ui.buildChat ( id, name, rank, pass ); - }, 500 ); - } - idrinth.chat.elements.chats.appendChild ( idrinth.ui.buildElement ( { - type: 'li', - id: 'idrinth-chat-tab-' + id, - css: rank.toLowerCase (), - attributes: [ - { - name: 'data-id', - value: id - } - ], - children: [ - { - type: 'ul', - css: "styled-scrollbar users" - }, - { - type: 'ul', - css: "styled-scrollbar chat" - }, - { - type: 'input', - css: 'add-chat-box', - id: "idrinth-chat-input-" + id, - attributes: [ - { - name: 'title', - value: 'press ENTER or RETURN to send' - }, - { - name: 'onkeyup', - value: 'if(event.keyCode===13||event.which===13){idrinth.chat.send(' + id + ');}' - } - ] - } - ] - } ) ); - idrinth.chat.elements.menu.appendChild ( - idrinth.ui.buildElement ( - { - type: 'li', - content: name, - id: 'idrinth-chat-tab-click-' + id, - attributes: [ - { - name: 'data-id', - value: id - }, - { - name: 'title', - value: name + "\nID:" + id + "\nPassword: " + pass - }, - { - name: 'onclick', - value: 'idrinth.chat.enableChat(this);' - }, - { - name: 'oncontextmenu', - value: 'idrinth.chat.showOptions(event,this);' - } - ] - } - ) - ); - }, - getElementPositioning: function ( element, offsetX, offsetY ) { - var pos = { - x: element.getBoundingClientRect ().left + ( offsetX ? offsetX : 0 ), - y: element.getBoundingClientRect ().top + ( offsetY ? offsetY : 0 ) - }; - return 'position:fixed;left:' + pos.x + 'px;top:' + pos.y + 'px'; - }, - buildElement: function ( config ) { - 'use strict'; - var setBase = function ( el, config ) { - if ( config.id ) { - el.id = config.id; - } - if ( config.css ) { - el.setAttribute ( 'class', config.css ); - } - if ( config.content ) { - el.appendChild ( document.createTextNode ( config.content ) ); - } - }; - var addChildren = function ( el, config ) { - if ( !config.children || !config.children.length ) { - return; - } - for (var count = 0, l = config.children.length; count < l; count++) { - el.appendChild ( idrinth.ui.buildElement ( config.children[count] ) ); - } - }; - var addAttributes = function ( el, config ) { - if ( !config.attributes || !config.attributes.length ) { - return; - } - for (var count = 0, l = config.attributes.length; count < l; count++) { - if ( config.attributes[count].name && config.attributes[count].value !== undefined ) { - el.setAttribute ( config.attributes[count].name, config.attributes[count].value ); - } - } - }; - var makeInputLabel = function ( config ) { - 'use strict'; - var inArray = function ( value, list ) { - 'use strict'; - if ( !Array.isArray ( list ) ) { - return false; - } - if ( typeof list.includes === 'function' ) { - return list.includes ( value ); - } - return list.indexOf ( value ) > -1; - }; - var input = [ { - name: 'type', - value: config.type - } ]; - if ( idrinth.settings[config.name] && config.type === 'checkbox' ) { - input.push ( { - name: 'checked', - value: 'checked' - } ); - } - if ( config.type !== 'checkbox' ) { - input.push ( { - name: 'value', - value: idrinth.settings[config.name] - } ); - input.push ( { - name: 'onchange', - value: 'idrinth.settings.change(\'' + config.name + '\',this.value)' - } ); - } else { - input.push ( { - name: 'onchange', - value: 'idrinth.settings.change(\'' + config.name + '\',this.checked)' - } ); - } - return idrinth.ui.buildElement ( { - css: 'idrinth-line' + ( config.platforms && !inArray ( idrinth.platform, config.platforms ) ? ' idrinth-hide' : '' ), - children: [ { - type: 'label', - css: 'idrinth-float-half', - content: config.label, - attributes: [ { - name: 'for', - value: 'idrinth-' + config.name - } ] - }, { - type: 'input', - css: 'idrinth-float-half', - id: 'idrinth-' + config.name, - attributes: input - } ] - } ); - }; - if ( config.type === '#text' ) { - return document.createTextNode ( config.content ); - } - if ( config.rType === '#input' ) { - return makeInputLabel ( config ); - } - var el = document.createElement ( config.type ? config.type : 'div' ); - setBase ( el, config ); - addChildren ( el, config ); - addAttributes ( el, config ); - return el; - }, - controls: null, - tooltipTO: null, - buildModal: function ( title, content, altFunc ) { - var mod = { - children: [ ], - css: 'idrinth-hovering-box idrinth-popup idrinth-' + ( typeof altFunc === 'string' ? 'confim' : 'alert' ) - }; - if ( typeof title === 'string' ) { - mod.children.push ( { - content: title, - css: 'header' - } ); - } else { - mod.children.push ( { - content: 'Title missing', - css: 'header' - } ); - } - if ( typeof content === 'string' ) { - mod.children.push ( { - content: content, - css: 'content' - } ); - } else if ( typeof content === 'object' && content.type ) { - mod.children.push ( { - children: content, - css: 'content' - } ); - } else { - mod.children.push ( { - children: 'Content missing', - css: 'content' - } ); - } - mod.children.push ( { - css: 'buttons' - } ); - var closeFunc = 'this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);'; - if ( typeof altFunc === 'string' ) { - mod.children[mod.children.length - 1].children = [ { - type: 'button', - content: 'Ok', - attributes: [ { - name: 'onclick', - value: altFunc - } ] - }, { - type: 'button', - content: 'Cancel', - attributes: [ { - name: 'onclick', - value: closeFunc - } ] - } ]; - } else { - mod.children[mod.children.length - 1].children = [ { - type: 'button', - content: 'Ok', - attributes: [ { - name: 'onclick', - value: closeFunc - } ] - } ]; - } - idrinth.ui.body.appendChild ( idrinth.ui.buildElement ( mod ) ); - }, - showTooltip: function ( element ) { - 'use strict'; - function tooltip ( set, element, world ) { - if ( !set ) { - idrinth.ui.updateClassesList ( element, [ 'idrinth-hide' ], [ ] ); - return; - } - var baseUrl = 'https://dotd.idrinth.de/' + ( world ? 'world-kongregate' : 'kongregate' ); - idrinth.ui.updateClassesList ( idrinth.ui.tooltip, [ ], [ 'idrinth-hide' ] ); - idrinth.ui.updateClassesList ( element, [ ], [ 'idrinth-hide' ] ); - element.childNodes[0].setAttribute ( 'href', baseUrl + '/summoner/' + set.id + '/' ); - element.childNodes[0].innerHTML = set.name; - element.childNodes[1].childNodes[1].innerHTML = set.level + ' (' + set['7day'] + '/week, ' + set['30day'] + '/month)'; - element.childNodes[1].childNodes[3].innerHTML = idrinth.names.classes[set.class]; - element.childNodes[2].childNodes[1].setAttribute ( 'href', baseUrl + '/guild/' + set.guildId + '/' ); - element.childNodes[2].childNodes[1].innerHTML = idrinth.names.guilds[world ? 'world' : 'kongregate'][set.guildId]; - element.childNodes[3].childNodes[1].innerHTML = set.updated; - element.childNodes[3].setAttribute ( 'style', ( new Date () ) - ( new Date ( set.updated ) ) > 86400000 ? 'color:#aa0000;' : '' ); - } - idrinth.names.isHovering = false; - var name = idrinth.names.parse ( element ).toLowerCase ( ); - if ( idrinth.settings.names && idrinth.ui.tooltip && idrinth.names.users[name] ) { - window.clearTimeout ( idrinth.ui.tooltipTO ); - idrinth.ui.tooltip.setAttribute ( 'style', idrinth.ui.getElementPositioning ( element, -200, -100 ) ); - tooltip ( idrinth.names.users[name].kongregate, idrinth.ui.tooltip.firstChild, false ); - tooltip ( idrinth.names.users[name].world, idrinth.ui.tooltip.lastChild, true ); - idrinth.ui.tooltipTO = window.setTimeout ( idrinth.ui.hideTooltip, idrinth.settings.timeout ? idrinth.settings.timeout : 5000 ); - } - }, - hideTooltip: function () { - if ( idrinth.names.isHovering ) { - idrinth.ui.tooltipTO = window.setTimeout ( idrinth.ui.hideTooltip, idrinth.settings.timeout ? idrinth.settings.timeout : 5000 ); - return; - } - idrinth.ui.updateClassesList ( idrinth.ui.tooltip, [ 'idrinth-hide' ], [ ] ); - }, - openCloseSettings: function ( ) { - 'use strict'; - var toRemove = [ ( idrinth.ui.controls.getAttribute ( 'class' ) ).match ( /(^|\s)inactive($|\s)/ ) ? 'inactive' : 'active' ]; - if ( !idrinth.settings.moveLeft ) { - toRemove.push ( 'left-sided' ); - } - if ( !idrinth.settings.minimalist ) { - toRemove.push ( 'small' ); - } - idrinth.ui.updateClassesList ( idrinth.ui.controls, [ 'active', 'inactive', 'left-sided', 'small' ], toRemove ); - }, - childOf: function ( element, cssClass ) { - 'use strict'; - do { - if ( element.className.match ( new RegExp ( '(^|\s)' + cssClass + '(\s|$)' ) ) ) { - return true; - } - if ( !element.parentNode || element === document.getElementsByTagName ( 'body' )[0] ) { - return false; - } - element = element.parentNode; - } while ( element ); - return false; - }, - removeElement: function ( id ) { - 'use strict'; - var el = document.getElementById ( id ); - if ( el ) { - el.parentNode.removeChild ( el ); - } - }, - reloadGame: function ( ) { - 'use strict'; - var handleFrame = function ( parent ) { - var frame = parent.getElementsByTagName ( 'iframe' )[0]; - frame.setAttribute ( 'src', ( frame.getAttribute ( 'src' ) ).replace ( /&ir=.*/, '' ) + '&ir=' + Math.random () ); - }; - try { - if ( idrinth.platform === 'kongregate' ) { - window.activateGame ( ); - } else if ( idrinth.platform === 'dawnofthedragons' ) { - handleFrame ( document ); - } else if ( idrinth.platform === 'newgrounds' ) { - handleFrame ( document.getElementById ( 'iframe_embed' ) ); - } else if ( idrinth.platform === 'armorgames' ) { - handleFrame ( document.getElementById ( 'gamefilearea' ) ); - } - } catch ( e ) { - idrinth.core.alert ( 'The game couldn\'t be reloaded' ); - } - }, - updateClassesList: function ( element, add, remove ) { - var getClassesList = function ( classString, add, remove ) { - var forceToArray = function ( value ) { - return value && typeof value === 'object' && Array.isArray ( value ) ? value : [ ]; - }; - var original = classString === null ? [ ] : classString.split ( ' ' ).concat ( forceToArray ( add ) ); - var list = [ ]; - remove = forceToArray ( remove ); - var addUnique = function ( list, element, forbidden ) { - if ( list.indexOf ( element ) === -1 && forbidden.indexOf ( element ) === -1 ) { - list.push ( element ); - } - return list; - }; - for (var counter = 0; counter < original.length; counter++) { - list = addUnique ( list, original[counter], remove ); - } - return list.join ( ' ' ); - }; - element.setAttribute ( 'class', getClassesList ( element.getAttribute ( 'class' ), add, remove ) ); - }, - activateTab: function ( name ) { - var head = document.getElementById ( 'tab-activator-' + name ).parentNode.childNodes; - var body = document.getElementById ( 'tab-element-' + name ).parentNode.childNodes; - var setClasses = function ( head, body, name ) { - if ( head === document.getElementById ( 'tab-activator-' + name ) ) { - idrinth.ui.updateClassesList ( head, [ 'active' ], [ ] ); - idrinth.ui.updateClassesList ( body, [ ], [ 'idrinth-hide' ] ); - return; - } - idrinth.ui.updateClassesList ( head, [ ], [ 'active' ] ); - idrinth.ui.updateClassesList ( body, [ 'idrinth-hide' ], [ ] ); - }; - for (var count = 0; count < head.length; count++) { - setClasses ( head[count], body[count], name ); - } - }, - start: function ( ) { - 'use strict'; - idrinth.ui.body = document.getElementsByTagName ( 'body' )[0]; - document.getElementsByTagName ( 'head' )[0].appendChild ( idrinth.ui.buildElement ( { - type: 'link', - attributes: [ { - name: 'rel', - value: 'stylesheet' - }, { - name: 'href', - value: 'https://dotd.idrinth.de###PATH###/script-styles.css?###VERSION###' - } ] - } ) ); - if ( idrinth.platform === 'kongregate' ) { - idrinth.ui.buildBasis.buildTooltip ( ); - } - idrinth.ui.buildBasis.do ( ); - idrinth.war.element = idrinth.ui.buildBasis.war (); - idrinth.ui.body.appendChild ( idrinth.war.element ); - } - }, startInternal: function () { var startModules = function () { idrinth.settings.start ( );