Waze major traffic events from Waze Editor(ja)

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Waze major traffic events from Waze Editor(ja)
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  URLから緯度と経度を取得してWaze EditorとWaze Live Mapを開く
// @author       Aoi
// @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.value = ''; // テキスト入力の中身を空にする
    urlInput.placeholder = 'https://www.waze.com/ja/events?zoom=17&lat=42.9904&lon=141.5554'; // デフォルトのURLをplaceholderにする
    urlInput.style.marginBottom = '5px';
    urlInput.style.width = '400px';

    // ボタンコンテナを作成
    var buttonContainer = document.createElement('div');
    buttonContainer.style.display = 'flex';
    buttonContainer.style.marginBottom = '5px';

    // 貼り付けボタンを作成
    var pasteButton = document.createElement('button');
    pasteButton.innerHTML = '貼り付け';
    pasteButton.style.padding = '5px 10px';
    pasteButton.style.backgroundColor = '#007bff';
    pasteButton.style.color = 'white';
    pasteButton.style.border = 'none';
    pasteButton.style.borderRadius = '3px';
    pasteButton.style.cursor = 'pointer';
    pasteButton.style.marginRight = '5px';

    // ボタンがクリックされたときにテキスト入力フィールドにクリップボードの内容を貼り付ける
    pasteButton.addEventListener('click', function() {
        navigator.clipboard.readText()
            .then(text => {
                urlInput.value = text.trim();
            })
            .catch(err => {
                console.error('Failed to read clipboard contents: ', err);
            });
    });

    // 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(pasteButton);
    buttonContainer.appendChild(editorButton);
    buttonContainer.appendChild(liveMapButton);

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

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