Created
May 16, 2022 22:52
-
-
Save ConnorNelson/6f8f33efa5d0fc14cb632ff5f4b3fd9b to your computer and use it in GitHub Desktop.
Print Google Maps Better
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); |
Author
ConnorNelson
commented
May 16, 2022
- Select directions on Google Maps
- Copy above code
- Press keyboard shortcut "Ctrl + Shift + J" (on Google Chrome)
- Paste code into developer console
- Press enter to run code
- Wait for code to finish formatting everything
- Put map to desired location
- Click anywhere outside of map to begin printing
This code can also be "saved" into google maps on Google Chrome.
- Press keyboard shortcut F12 to open developer tools
- Press keyboard shortcut Ctrl + Shift + P
- Type in "Create Snippet"
- Press enter
- Copy above code
- Paste code into snippet
- Press Keyboard Shortcut Ctrl + S
- Right click "Script snippet...", rename "Print Google Maps Better"
Now this snippet can be run whenever.
- Select directions on Google Maps
- Press keyboard shortcut F12 to open developer tools
- Press keyboard shortcut Ctrl + O
- Type "!"
- Press Enter
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