Rental Utils

cleans up the unnecessary junk off the end of urls and links location to vrbo

目前為 2024-01-01 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Rental Utils
// @namespace    https://fxzfun.com/userscripts
// @version      2023-12-31
// @description  cleans up the unnecessary junk off the end of urls and links location to vrbo
// @author       FXZFun
// @match        https://*.vrbo.com/*
// @match        https://*.airbnb.com/rooms/*
// @icon         https://fxzfun.com/favicon.ico
// @grant        none
// ==/UserScript==

(async function() {
    'use strict';

    function extractLatLngFromUrl(url) {
        const markersIndex = url.indexOf('markers=');
        if (markersIndex === -1) return null;

        const markersString = url.substring(markersIndex);
        const regex = /markers=.*?%7C([-+]?\d*\.\d+)%2C([-+]?\d*\.\d+)/;
        const match = markersString.match(regex);

        if (match && match.length === 3) {
            const latitude = parseFloat(match[1]);
            const longitude = parseFloat(match[2]);
            return { latitude, longitude };
        }
    }

    async function getAddress(lat, lng) {
        let r = await fetch(`https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?location=${lng}%2C${lat}&f=pjson`);
        let j = await r.json();
        return j.address.Match_addr;
    }

    if (location.host.endsWith('vrbo.com')) {
        const woSearch = window.location.href.replace(window.location.search, '');
        window.history.replaceState(null, null, woSearch);

        const mapImage = [...document.querySelectorAll("img")].filter(i => i.src.startsWith("https://maps.googleapis.com"))[0];
        const ll = extractLatLngFromUrl(mapImage.src);
        const addr = await getAddress(ll.latitude, ll.longitude);
        console.log(ll);
        console.log(addr);
        const p = document.createElement("a");
        p.target = "_blank";
        p.href = `https://www.google.com/maps/search/?api=1&query=${ll.latitude},${ll.longitude}`;
        p.style = "position: relative;background: #ffffffd1;z-index: 999999999;";
        p.innerText = addr;
        mapImage.insertAdjacentElement("afterEnd", p);
    }

    if (location.host.endsWith('airbnb.com')) {
        const woSearch = window.location.href.replace(window.location.search, '');
        window.history.replaceState(null, null, woSearch);
        setTimeout(() => window.history.replaceState(null, null, woSearch), 1000);
    }
})();