Open Waze Editor & Live Map from URL (ja)

URLから緯度と経度を取得してWaze EditorとWaze Live Mapを開く

当前为 2024-05-28 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Open Waze Editor & Live Map from URL (ja)
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  URLから緯度と経度を取得してWaze EditorとWaze Live Mapを開く
// @author       Your Name
// @match        https://www.waze.com/ja/events*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // コンテナを作成
    var container = document.createElement('div');
    container.style.position = 'fixed';
    container.style.bottom = '20px';
    container.style.left = '50%';
    container.style.transform = 'translateX(-50%)';
    container.style.display = 'flex';
    container.style.flexDirection = 'column';
    container.style.alignItems = 'center';
    container.style.zIndex = '1000';

    // テキスト入力フィールドを作成
    var urlInput = document.createElement('input');
    urlInput.type = 'text';
    urlInput.placeholder = 'https://www.waze.com/ja/events?zoom=15&lat=35.68299&lon=139.7603';
    urlInput.style.marginBottom = '5px';
    urlInput.style.width = '400px';

    // ボタンを格納するコンテナを作成
    var buttonContainer = document.createElement('div');
    buttonContainer.style.display = 'flex';

    // Waze Editorを開くボタンを作成
    var editorButton = document.createElement('button');
    editorButton.innerHTML = 'Waze Editorで開く';
    editorButton.style.padding = '5px 10px';
    editorButton.style.backgroundColor = '#007bff';
    editorButton.style.color = 'white';
    editorButton.style.border = 'none';
    editorButton.style.borderRadius = '3px';
    editorButton.style.cursor = 'pointer';
    editorButton.style.marginRight = '5px';

    // Waze Live Mapを開くボタンを作成
    var liveMapButton = document.createElement('button');
    liveMapButton.innerHTML = 'Waze Live Mapで開く';
    liveMapButton.style.padding = '5px 10px';
    liveMapButton.style.backgroundColor = '#007bff';
    liveMapButton.style.color = 'white';
    liveMapButton.style.border = 'none';
    liveMapButton.style.borderRadius = '3px';
    liveMapButton.style.cursor = 'pointer';

    // ボタンがクリックされたときにURLから緯度と経度を抽出してWaze EditorのURLを開く
    editorButton.addEventListener('click', function() {
        var url = urlInput.value.trim();
        var urlParams = new URLSearchParams(url.split('?')[1]);
        var lat = urlParams.get('lat');
        var lon = urlParams.get('lon');

        if (lat && lon) {
            // Waze EditorのURLを作成
            var editorUrl = `https://www.waze.com/ja/editor?env=row&lon=${lon}&lat=${lat}&zoom=5`;
            window.open(editorUrl, '_blank');
        } else {
            alert('正しいURLを入力してください。');
        }
    });

    // ボタンがクリックされたときにURLから緯度と経度を抽出してWaze Live MapのURLを開く
    liveMapButton.addEventListener('click', function() {
        var url = urlInput.value.trim();
        var urlParams = new URLSearchParams(url.split('?')[1]);
        var lat = urlParams.get('lat');
        var lon = urlParams.get('lon');

        if (lat && lon) {
            // Waze Live MapのURLを作成
            var liveMapUrl = `https://www.waze.com/ja/live-map/directions?to=ll.${lat}%2C${lon}`;
            window.open(liveMapUrl, '_blank');
        } else {
            alert('正しいURLを入力してください。');
        }
    });

    // ボタンをボタンコンテナに追加
    buttonContainer.appendChild(editorButton);
    buttonContainer.appendChild(liveMapButton);

    // コンテナに要素を追加
    container.appendChild(urlInput);
    container.appendChild(buttonContainer);

    // ページにコンテナを追加
    document.body.appendChild(container);
})();