// ==UserScript== // @name [Dragosien] Rohstoffupdate live // @version 2.2 // @description Zählt die Rohstoffe im Lager automatisch hoch // @namespace http://www.dragosien.de/user/ReelStory // @icon http://www.dragosien.de/favicon.ico // @include http://*.dragosien.de/* // @include http://dragosien.de/* // @exclude http://*dragosien.de/vt.php* // @grant GM_getValue // @grant GM_setValue // @grant GM_log // ==/UserScript== // Config: Interval between updates in milliseconds var updateInterval = 1000; // Load time of the page, used to get the counters right var pageOpenTime = new Date ().getTime (); // to keep track of the resources var hourlyResources = {}; var stockResources = {}; // use hostname of url as base name. this allows different // worlds to have different values var gameBase = location.host; // TimerIDs used by this script var myTimer; var myInterval; // compatibility with chromium et. al. // shamelessly taken from scrams post function testGM() { var isGM = typeof GM_getValue != 'undefined' && typeof GM_getValue('a', 'b') != 'undefined'; if(typeof(unsafeWindow) == 'undefined') { unsafeWindow = window; } if(!isGM) { log = function(msg) { try { unsafeWindow.console.log(msg); } catch(e) {} }; } else { log = GM_log; } if (window.opera) { log = opera.postError;} GM_setValue = isGM ? GM_setValue : function(name, value) { return localStorage.setItem(name, value) }; GM_getValue = isGM ? GM_getValue : function(name, def){ var s = localStorage.getItem(name); return s == null ? def : s }; thisIsFF=isGM; } testGM(); // process numbers with decimal dots every three digits function parseAsNumber (s) { s = new String(s); return parseInt (s.replace (/\./g, "")); } function printAsNumber (n) { function t (s) { if (s.length > 3) { return t (s.slice (0, -3)) + "." + s.slice(-3); } else { return s; } } return t (n.toString ()); } // Parse and setup the page. // This function should run after scams and uranos script ran, // so it gets called by a timer 1s after load. function initialize () { // timer called, reset ID myTimer = undefined; // Only used in initialization var hourlyProduction = {}; try { // don't parse foreign villages if (location.search.match ('t=foreign_village')) throw 'foreign_village'; var savedProduction = eval (GM_getValue (gameBase + '.hourlyProduction', {})); // Count all resources that our village produces var prodRegex = /produziert (\S+) (\S+)/; // main village class changes if dragontower is present var village = document.getElementById ('mainVillageDrachenzucht'); if (village == null) { village = document.getElementById ('mainVillage'); } var buildings = village.getElementsByClassName ('tooltip'); for (var b = 0; b < buildings.length; b++) { var position = buildings[b].id.slice (7); var divs=buildings[b].getElementsByTagName ('div'); for (var d = 0; d < divs.length; d++) { var divText = divs[d].textContent; var production = prodRegex.exec(divText); if (production != null) { // Save production for current building hourlyProduction[position] = [production[2], parseAsNumber (production[1])]; } else if (divText.match ('wird ausgebaut.')) { // Use previously saved production if (savedProduction[position] != null) { hourlyProduction[position] = savedProduction[position]; } } } } try { var saveKey = gameBase + '.hourlyProduction'; var saveVal = uneval (hourlyProduction); GM_setValue (saveKey, saveVal); } catch (err) { // saving failed, probably uneval is not implemented GM_log ("Speichern der aktuellen Produktion fehlgeschlagen:"); GM_log (err.toString ()); } } catch (err) { // if not on main village view get saved production values hourlyProduction = eval (GM_getValue (gameBase + '.hourlyProduction', {})); } // Now convert per building production into per resource prodution for (position in hourlyProduction) { if (hourlyResources[hourlyProduction[position][0]] == null) { hourlyResources[hourlyProduction[position][0]] = hourlyProduction[position][1]; } else { hourlyResources[hourlyProduction[position][0]] += hourlyProduction[position][1]; } } /* DEBUG for (p in hourlyResources) { GM_log("Poduktion erkannt: " + hourlyProduction[p] + " mal " + p); } */ // Set the id attribute on the