NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name OGame v6: Improved Messages // @namespace RiV-improve_msg // @version 0.2 // @description Extends messages menu with useful features // @author RiV- aka. dred ghawl // @match http://*.ogame.gameforge.com/game/index.php*messages* // @grant none // ==/UserScript== /* jshint -W097 */ 'use strict'; (function() { var $ = window.jQuery; try { $ = unsafeWindow.jQuery; } catch(e) { } var db; var db2; var arrayPrintNameIDs = new Array (); var $playersAPI, $universeAPI; var LANG = $('meta[name="ogame-language"]')[0].getAttribute('content').toUpperCase(); var PLAYERID = $('meta[name="ogame-player-id"]')[0].getAttribute('content'); var SERVER = $('meta[name="ogame-universe"]')[0].getAttribute('content').split('.')[0].toUpperCase(); function printLog(msg) { console.log('[OGame v6: Improved Messages] ' + msg); } function addText() { var parentTrashBox = document.getElementsByClassName('trash_box')[0].parentNode; var msgBtns = document.createElement('p'); msgBtns.id = 'msgBtns'; msgBtns.setAttribute('style', 'border: 1px dotted; position: absolute; left: -620px; top: -9px; width: 150px; height: 20px; background: #32495a;'); msgBtns.innerHTML = '<div style="border: 1px solid; text-align: center; width: 20px; height: 19px; float: left;"> \ <a href="javascript:void(0);" id="btnEspA" style="color: #ff9600;"> \ <span style="vertical-align: middle;">S</span> \ </a> \ </div> \ <div style="border: 1px solid; text-align: center; width: 30px; height: 19px; float: left;"> \ <a href="javascript:void(0);" id="btnEspLoot" style="color: #aa0000;"> \ <span style="vertical-align: middle;">< S</span> \ </a> \ </div>'; parentTrashBox.insertBefore(msgBtns, parentTrashBox.childNodes[2]); document.getElementById('btnEspA').addEventListener('click', deleteEspA, false); $('#btnEspLoot').contextmenu(function(ev) { var parentNode = document.getElementsByTagName('body')[0]; if ($('#stngEspLoot').length) { $('#stngEspLoot').remove(); return false; } var stngEspLoot = document.createElement('div'); stngEspLoot.className = 'stngPopUp'; stngEspLoot.id = 'stngEspLoot'; stngEspLoot.style.left = ev.pageX + 'px'; stngEspLoot.style.top = ev.pageY + 'px'; stngEspLoot.innerHTML = '<p class="rivLink" style="position:absolute; top:-2px; left: 247px; padding-top:0px;"><a href="javascript:void(0);" id="closeStngEspLoot">x</a></p>L: <input style="width: 50px; text-align:center; font-size: 11px;" id="stngLoot" value=""> K F: <input style="width: 50px; text-align:center; font-size: 11px;" id="stngFleet" value=""> K'; parentNode.appendChild(stngEspLoot); document.getElementById('stngLoot').focus(); document.getElementById('stngLoot').select(); document.getElementById('closeStngEspLoot').addEventListener('click', function(e) { parentNode.removeChild(document.getElementById('stngEspLoot')); }, false); return false; }); document.getElementById('btnEspLoot').addEventListener('click', deleteEspLoot, false); var $espActions = $('#ui-id-14 .msg .espionageDefText'); for (var i = 0; i < $espActions.length; i++) { arrayPrintNameIDs.push($espActions.eq(i).parent().parent().attr('data-msg-id')); } if(arrayPrintNameIDs.length && (!$('#universeView').length || localStorage['UV_planetOption'] != 'idb' || !("indexedDB" in window))) { loadAPI(); setTimeout(function() { printPlayerNames(arrayPrintNameIDs); }, 100); } else if(arrayPrintNameIDs.length) printPlayerNames(arrayPrintNameIDs); } var ob; function getFromDB(mod,os,key,cfunc) { var openRequest = indexedDB.open('UVIDB_' + PLAYERID + '_' + LANG + '_' + SERVER + '_' + mod); openRequest.onsuccess = function(e) { db = e.target.result; var transaction = db.transaction(['' + os + ''], "readonly"); var objectStore = transaction.objectStore(os); ob = objectStore.get(key); ob.onsuccess = cfunc; } openRequest.onerror = function(e) { printLog('IndexedDB Error'); console.dir(e); } } function getFromAPI(api,cfunc) { $.ajax({ url: 'http://' + SERVER + '.ogame.gameforge.com/api/' + api + '.xml', type: 'GET', dataType: "xml", success: cfunc }); } function loadAPI() { getFromAPI('players', function(data) { $playersAPI = $('players', data); }); getFromAPI('universe', function(data) { $universeAPI = $('universe', data); }); printLog('API loaded.'); } // Shows the player name next to coords in 'Espionage action' messages function printPlayerNames(array) { var playerCoord = $('[data-msg-id="' + array[0] + '"] .espionageDefText .txt_link').get(0).innerHTML.split('[')[1].split(']')[0]; if($('#universeView').length && localStorage['UV_planetOption'] == 'idb' && "indexedDB" in window) { getFromDB('PLANETS', 'universe', playerCoord, function(e) { var playerID = ob.result['pid'].match(/[0-9]+/g); getFromDB('RESEARCH', 'players', '' + playerID + '', function(e) { var playerName = ob.result['name']; $('[data-msg-id="' + array[0] + '"] .espionageDefText .txt_link').get(0).innerHTML += ' (' + playerName + ')'; arrayPrintNameIDs.shift(); if(arrayPrintNameIDs.length) printPlayerNames(arrayPrintNameIDs); }); }); } else { var playerID = $universeAPI.find('planet[coords="' + playerCoord + '"]').attr('player'); var playerName = $playersAPI.find('player[id="' + playerID + '"]').attr('name'); $('[data-msg-id="' + array[0] + '"] .espionageDefText .txt_link').get(0).innerHTML += ' (' + playerName + ')'; arrayPrintNameIDs.shift(); if(arrayPrintNameIDs.length) printPlayerNames(arrayPrintNameIDs); } } // Deletes all messages with 'Espionage action' in subject function deleteEspA() { // Select all message boxes var msgBoxes = document.getElementById('ui-id-14').getElementsByClassName('msg'); printLog('Looking for messages with subject \'Espionage action\'...'); // Push ID of messages with 'Espionage action' in an array var numEspA = 0; var arrayDeleteIDs = new Array(); for (var i = 0; i <= msgBoxes.length; i++) if (msgBoxes[i] && msgBoxes[i].innerHTML.match('Espionage action')) { // #TODO: Add loca numEspA++; arrayDeleteIDs.push(msgBoxes[i].getAttribute('data-msg-id')); msgBoxes[i].getElementsByClassName('js_actionKill')[0].click(); } // Delete found messages and reload page so older messages can be shown printLog(numEspA + ' messages found.'); if (arrayDeleteIDs.length > 0) { printLog('IDs deleted: ' + arrayDeleteIDs); printLog('Reloading page...'); setTimeout(function() { location.reload(); }, 100); } else printLog('Nothing deleted.'); } // Deletes all reports with under 1kk loot // #TODO: Add setting (right click on button) to change value function deleteEspLoot() { var $msgBoxes = $('#ui-id-14 .msg'); for (var i = 0; i < $msgBoxes.length; i++) { if(!$msgBoxes.eq(i).find('.msg_head .msg_title').html().match('Espionage report')) return; // #TODO: Add loca var avLoot = $msgBoxes.eq(i).find('.msg_content .compacting .tooltipRight').eq(0).attr('title').match(/: ([^<]+)*/)[1]; // Thanks to vulca for code if (avLoot.match(/^[0-9]{1,3}\.[0-9]{3}$/)) avLoot = avLoot.replace('.', ''); else if(avLoot.match(/^([0-9]{1,3}(\.|,))?[0-9]{1,3}(Md|Bn|Mrd)/)) avLoot = avLoot.replace(/,/g,'.').replace(/Md|Bn|Mrd/g,'')*1000000000; else if(avLoot.match(/^([0-9]{1,3}(\.|,))?[0-9]{1,3}(M|m)/)) avLoot = avLoot.replace(/,/g,'.').replace(/(M|m)/g,'')*1000000; if(parseInt(avLoot) < 1000000) { $msgBoxes.eq(i).find('.js_actionKill').eq(0).click(); printLog('Loot: ' + avLoot + '. Deleting...'); } } } // Doesn't do anything yet ... function refreshSpyTable(e) { if (!e || !e.target || !e.target.id || e.target.tagName != 'LI') return; console.log(e.target.outerHTML); if (!e.target.hasAttribute('data-msg-id')) return; if (e.target.innerHTML.match('Espionage report')) console.log('Espionage report found'); } document.getElementsByTagName('head')[0].appendChild(document.createElement("style")); var stylesheet = document.styleSheets[document.styleSheets.length-1]; stylesheet.insertRule('.stngPopUp { \ margin: 5px 0px 0px 5px; \ padding: 3px 3px 3px 3px; \ background-color: #13181D; \ border: 3px double black; \ width: 250px; \ font-size: 11px; \ float: left; \ text-align: center; \ position: absolute; \ z-index: 101; \ }', 0); stylesheet.insertRule('.rivLink a:link, .rivLink a:visited, .rivLink a:hover, .rivLink a:active { color: rgb(255,255,255); text-decoration: none; }', 0); stylesheet.insertRule('.rivLink { margin-left: 0px; padding-top: 4px; }', 0); var modifyCycle = 0; var textAdded = false; document.addEventListener('DOMSubtreeModified', function (e) { if (!e || !e.target || !e.target.id) return; if (e.target.id.match('ui-id-14') && e.target.hasAttribute('aria-hidden') && modifyCycle < 4) { modifyCycle++; return; } if (modifyCycle == 4 && textAdded == false) { textAdded = true; addText(); printLog('All buttons loaded.'); } }, false); //document.addEventListener('DOMNodeInserted', refreshSpyTable, false); }) ()