Planets.nu map printing

Allows opening a printable map

  1. // ==UserScript==
  2. // @name Planets.nu map printing
  3. // @namespace planets.nu
  4. // @description Allows opening a printable map
  5. // @include http://planets.nu/*
  6. // @include http://planets.nu/games/*
  7. // @include http://*.planets.nu/*
  8. // @grant none
  9. // @version 0.3
  10. // ==/UserScript==
  11. // later there will be svg-map animations - hopefully
  12. // Version 0.3 - completely rewritten
  13. // Version 0.2 - works with new servers
  14. // Version 0.1 - created
  15. function wrapper() {
  16. // wrapper for injection
  17. var plugin = {
  18. /*
  19. * processload: executed whenever a turn is loaded: either the current turn or
  20. * an older turn through time machine
  21. */
  22. processload: function () {
  23. // console.log("ProcessLoad: plugin called.");
  24. },
  25. /*
  26. * loaddashboard: executed to rebuild the dashboard content after a turn is loaded
  27. */
  28. loaddashboard: function () {
  29. // console.log("LoadDashboard: plugin called.");
  30. },
  31. /*
  32. * showdashboard: executed when switching from starmap to dashboard
  33. */
  34. showdashboard: function () {
  35. // console.log("ShowDashboard: plugin called.");
  36. },
  37. /*
  38. * showsummary: executed when returning to the main screen of the dashboard
  39. */
  40. showsummary: function () {
  41. // console.log("ShowSummary: plugin called.");
  42. },
  43. /*
  44. * loadmap: executed after the first turn has been loaded to create the map
  45. * as far as I can tell not executed again when using time machine
  46. */
  47. loadmap: function () {
  48. vgap.map.addMapTool('Print Map', 'ShowMinerals', function () {
  49. vgap.plugins.PrintMap.openMap();
  50. });
  51. },
  52. /*
  53. * showmap: executed when switching from dashboard to starmap
  54. */
  55. showmap: function () {
  56. // console.log("ShowMap: plugin called.");
  57. },
  58. /*
  59. * draw: executed on any click or drag on the starmap
  60. */
  61. draw: function () {
  62. },
  63. /*
  64. * loadplanet: executed a planet is selected on dashboard or starmap
  65. * loadstarbase: executed a planet is selected on dashboard or starmap
  66. * Inside the function "load" of vgapPlanetScreen (vgapPlanetScreen.prototype.load) the normal planet screen
  67. * is set up. You can find the function in "nu.js" if you search for 'vgap.callPlugins("loadplanet");'.
  68. *
  69. * Things accessed inside this function several variables can be accessed. Elements accessed as "this.X"
  70. * can be accessed here as "vgap.planetScreen.X".
  71. */
  72. loadplanet: function () {
  73. // console.log("LoadPlanet: plugin called.");
  74. // console.log("Planet id: " + vgap.planetScreen.planet.id);
  75. },
  76. /*
  77. * loadstarbase: executed a planet is selected on dashboard or starmap
  78. * Inside the function "load" of vgapStarbaseScreen (vgapStarbaseScreen.prototype.load) the normal starbase screen
  79. * is set up. You can find the function in "nu.js" if you search for 'vgap.callPlugins("loadstarbase");'.
  80. *
  81. * Things accessed inside this function several variables can be accessed. Elements accessed as "this.X"
  82. * can be accessed here as "vgap.starbaseScreen.X".
  83. */
  84. loadstarbase: function () {
  85. // console.log("LoadStarbase: plugin called.");
  86. // console.log("Starbase id: " + vgap.starbaseScreen.starbase.id + " on planet id: " + vgap.starbaseScreen.planet.id);
  87. },
  88. /*
  89. * loadship: executed a planet is selected on dashboard or starmap
  90. * Inside the function "load" of vgapShipScreen (vgapShipScreen.prototype.load) the normal ship screen
  91. * is set up. You can find the function in "nu.js" if you search for 'vgap.callPlugins("loadship");'.
  92. *
  93. * Things accessed inside this function several variables can be accessed. Elements accessed as "this.X"
  94. * can be accessed here as "vgap.shipScreen.X".
  95. */
  96. loadship: function () {
  97. },
  98. // END PLUGIN FUNCS
  99. openMap: function ()
  100. {
  101. var canvas = vgap.map.canvas;
  102. //$(canvas).css('background-color', 'black');
  103. var imgURL = canvas.toDataURL('image/jpeg');
  104. var mapWindow = window.open(imgURL, 'MapWindow');
  105. }
  106. };
  107. // register your plugin with NU
  108. vgap.registerPlugin(plugin, 'PrintMap');
  109. }
  110. //wrapper for injection
  111.  
  112. var script = document.createElement('script');
  113. script.type = 'application/javascript';
  114. script.textContent = '(' + wrapper + ')();';
  115. document.body.appendChild(script);
  116. document.body.removeChild(script);