Last active
September 4, 2022 07:53
-
-
Save dacer/e8fdaaee1135c9fcbbf951e25707c8a9 to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name Find House Helper - google maps | |
// @namespace Violentmonkey Scripts | |
// @match https://www.google.*/maps/* | |
// @grant none | |
// @version 1.0 | |
// @author - | |
// @description 9/4/2022, 1:14:46 PM | |
// @require https://cdn.jsdelivr.net/npm/@violentmonkey/dom@2 | |
// ==/UserScript== | |
var previousUrl = ''; | |
const disconnect = VM.observe(document.body, () => { | |
// Find the target node | |
var shareEle = document.evaluate("//div[text()='共有']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
var hotelHint = document.evaluate("//span[text()='ホテル']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
var car = document.querySelectorAll('[aria-label="車"]'); | |
var walking = document.evaluate("//div[text()='徒歩']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
console.log('finding...') | |
if (shareEle) { | |
shareEle.parentElement.parentNode.replaceChild(generateMapButton(), shareEle.parentElement); | |
// disconnect observer | |
// return true; | |
} | |
if (hotelHint) { | |
hotelHint.innerText = 'スーパー'; | |
} | |
if (car && car[0]) { | |
console.log('click car'); | |
car[0].click(); | |
} | |
if (walking) { | |
console.log('click walking'); | |
walking.click(); | |
} | |
if (location.href !== previousUrl) { | |
previousUrl = location.href; | |
console.log(`URL changed to ${location.href}`); | |
if (previousUrl.includes('maps/search/%E3%83%9B%E3%83%86%E3%83%AB')) {// ホテル | |
window.location.href = previousUrl.replace('maps/search/%E3%83%9B%E3%83%86%E3%83%AB', 'maps/search/スーパー') | |
} | |
} | |
}); | |
const generateMapButton = () => { | |
const btn = document.createElement("button"); | |
btn.innerHTML = "ハザード\nマップ"; | |
btn.onclick = function () { | |
window.open(generateMapUrl(), '_blank').focus(); | |
}; | |
return btn; | |
} | |
const generateMapUrl = () => { | |
const regex = new RegExp('@(\\d+.\\d+),(\\d+.\\d+)', 'gm'); | |
const result = regex.exec(window.location.href); | |
const latitude = result[1]; | |
const longitude = result[2]; | |
return `https://disaportal.gsi.go.jp/maps/index.html?ll=${latitude.slice(0, -1)},${longitude.slice(0, -1)}&z=15&base=pale&ls=seamless%7Ctameike_raster%2C0.8%7Cflood_l2_kaokutoukai_kagan%2C0.8%7Cflood_l2_kaokutoukai_hanran%2C0.8%7Cflood_l2_keizoku%2C0.8%7Cflood_list%2C0.8%7Cflood_l1%2C0.8%7Cflood_list_l2%2C0.75%7Cdosha_kiken_nadare%2C0.8%7Cdosha_kiken_jisuberi%2C0.8%7Cdosha_kiken_kyukeisha%2C0.8%7Cdosha_kiken_dosekiryu%2C0.8%7Cdosha_keikai_jisuberi%2C0.8%7Cdosha_keikai_dosekiryu%2C0.8%7Cdosha_keikai_kyukeisha%2C0.8%7Ctakashio_sinsuisin_raster%2C0.8%7CchikeiBunrui50000_multi%2C0.8%7Cyoboukiseikukan_multi%2C0.8%7Cjizenkisei_00_multi%2C0.8%7Ckansui_multi%2C0.8%7Cekijouka_zenkoku%2C0.8%7Ctsunamishinsui_raster%2C0.8%7Cdisaster1%7Cdisaster2%7Cdisaster3%7Cexperimental_landformclassification%7Cdisaster5&disp=010000011111111101110100010&vs=c1j0l0u0t0h0z0` | |
} | |
window.onpopstate = function(event) { | |
console.log("location: " + document.location + ", state: " + JSON.stringify(event.state)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment