// ==UserScript== // @author jaiperdu // @name MUs Tab // @category COMM // @version 0.1.1 // @description Add a MUs tab scoring the MU // @id muTab@jaiperdu // @namespace https://github.com/IITC-CE/ingress-intel-total-conversion // @updateURL https://raw.githubusercontent.com/IITC-CE/Community-plugins/master/dist/jaiperdu/muTab.meta.js // @downloadURL https://raw.githubusercontent.com/IITC-CE/Community-plugins/master/dist/jaiperdu/muTab.user.js // @match https://intel.ingress.com/* // @grant none // ==/UserScript== function wrapper(plugin_info) { // ensure plugin framework is there, even if iitc is not yet loaded if(typeof window.plugin !== 'function') window.plugin = function() {}; //PLUGIN AUTHORS: writing a plugin outside of the IITC build environment? if so, delete these lines!! //(leaving them in place might break the 'About IITC' page or break update checks) plugin_info.buildName = 'lejeu'; plugin_info.dateTimeVersion = '2023-10-19-070329'; plugin_info.pluginId = 'muTab'; //END PLUGIN AUTHORS NOTE var musTab = {}; // musTab.commTab = { // channel: 'mus', // name: 'MUs', // inputPrompt: '', // sendMessage: () => true, // request: (_, b) => chat.requestChannel('all', b), // render: chat.renderChannel, // localBounds: true, // } musTab.maxMus = 1; musTab.maxDest = { ENLIGHTENED: 1, RESISTANCE: 1, }; musTab.data = {} musTab.ENLIGHTENED = { name: 'Enlightened', team: 'enl', totalMus: 0, destroyedMus: { ENLIGHTENED: 0, RESISTANCE: 0, }, }; musTab.RESISTANCE = { name: 'Resistance', team: 'res', totalMus: 0, destroyedMus: { ENLIGHTENED: 0, RESISTANCE: 0, }, } musTab.addMus = function (guid, player, team, mus) { if (!(player.name in musTab.data)) musTab.data[player.name] = { player: player, totalMus: 0, destroyedMus: { ENLIGHTENED: 0, RESISTANCE: 0, }, mus: {}, }; var playerData = musTab.data[player.name]; if (guid in playerData.mus); else { playerData.mus[guid] = mus; if (mus > 0) { playerData.totalMus += mus; if (playerData.totalMus > musTab.maxMus) musTab.maxMus = playerData.totalMus; musTab[player.team].totalMus += mus; } else { playerData.destroyedMus[team] -= mus; if (playerData.destroyedMus[team] > musTab.maxDest[team]) musTab.maxDest[team] = playerData.destroyedMus[team]; musTab[player.team].destroyedMus[team] -= mus; } } }; musTab.delPlayer = function (name) { if (!(name in musTab.data)) return; var playerData = musTab.data[name]; var teamData = musTab[playerData.player.team]; teamData.totalMus -= playerData.totalMus; teamData.destroyedMus.ENLIGHTENED -= playerData.destroyedMus.ENLIGHTENED; teamData.destroyedMus.RESISTANCE -= playerData.destroyedMus.RESISTANCE; delete musTab.data[name]; }; musTab.newChatData = function (data) { // {raw: data, result: data.result, processed: chat._channels[channel].data} for (const row of data.result) { const guid = row[0]; const parseData = data.processed[guid][4]; const idMUs = row[2].plext.markup.findIndex((ent) => ent[0] == 'TEXT' && ent[1].plain === ' MUs'); if (idMUs < 0) continue; const isCreateField = row[2].plext.markup[idMUs - 2][1].plain === ' +'; const isDestroyField = row[2].plext.markup[idMUs - 2][1].plain === ' -'; const mus = +row[2].plext.markup[idMUs - 1][1].plain; if (isCreateField) { const player = { name: parseData.player.name, team: window.TEAM_CODENAMES[parseData.player.team], } musTab.addMus(guid, player, player.team, mus); } else if (isDestroyField) { const player = { name: parseData.player.name, team: window.TEAM_CODENAMES[parseData.player.team], } const team = row[2].plext.markup[idMUs - 3][1].team; musTab.addMus(guid, player, team, -mus); } } musTab.render(); }; const template = '