Skip to content

Instantly share code, notes, and snippets.

@ConnorNelson
Created May 16, 2022 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ConnorNelson/6f8f33efa5d0fc14cb632ff5f4b3fd9b to your computer and use it in GitHub Desktop.
Save ConnorNelson/6f8f33efa5d0fc14cb632ff5f4b3fd9b to your computer and use it in GitHub Desktop.
Print Google Maps Better
const width = "8.5in";
const height = "11in";
function sleep(s) {
var sleepTime = 1000;
return new Promise(resolve => setTimeout(resolve, sleepTime));
}
var body = document.querySelector("body");
var content = document.querySelector("#content-container");
var app = document.querySelector("#app-container");
var scene = document.querySelector("#scene");
while (true) {
var printWithMaps = document.querySelector('button[jsaction="pane.action.printWithMaps"]');
if (printWithMaps) break;
var printOpen = document.querySelector('button[jsaction="pane.action.printOpen"]');
printOpen.click();
await sleep();
}
printWithMaps.click();
await sleep();
var printRegion = document.querySelector("#print");
printRegion.remove();
await sleep();
var directions = null;
content.querySelectorAll("div").forEach((div) => {
if (directions)
return;
if (window.getComputedStyle(div).position != "absolute")
return;
div.querySelectorAll("span").forEach((span) => {
if (directions)
return;
if (!span.textContent.includes("These directions are for planning"))
return;
span.remove();
directions = div;
});
});
directions.remove();
directions.style.position = "static";
directions.style.width = width;
body.appendChild(directions);
await sleep();
app.style.width = width;
app.style.height = height;
scene.style.width = width;
scene.style.height = height;
await sleep();
window.dispatchEvent(new Event("resize"));
await sleep();
window.addEventListener("click", (event) => {
print();
});
@ConnorNelson
Copy link
Author

  1. Select directions on Google Maps
  2. Copy above code
  3. Press keyboard shortcut "Ctrl + Shift + J" (on Google Chrome)
  4. Paste code into developer console
  5. Press enter to run code
  6. Wait for code to finish formatting everything
  7. Put map to desired location
  8. Click anywhere outside of map to begin printing

@ConnorNelson
Copy link
Author

This code can also be "saved" into google maps on Google Chrome.

  1. Press keyboard shortcut F12 to open developer tools
  2. Press keyboard shortcut Ctrl + Shift + P
  3. Type in "Create Snippet"
  4. Press enter
  5. Copy above code
  6. Paste code into snippet
  7. Press Keyboard Shortcut Ctrl + S
  8. Right click "Script snippet...", rename "Print Google Maps Better"

Now this snippet can be run whenever.

  1. Select directions on Google Maps
  2. Press keyboard shortcut F12 to open developer tools
  3. Press keyboard shortcut Ctrl + O
  4. Type "!"
  5. Press Enter

@ConnorNelson
Copy link
Author

Get The Google Chrome Extension!
See https://github.com/ConnorNelson/PrintGoogleMapsBetter.

Available as "Print Google Maps Better".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment