Greasy Fork

Greasy Fork is available in English.

Vodafone Easybox HASS Device Tracker

Sends the online status of network devices to HASS

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Vodafone Easybox HASS Device Tracker
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Sends the online status of network devices to HASS
// @author       [email protected]
// @match        http://192.168.0.1/*
// @grant        GM_xmlhttpRequest
// @connect      *
// ==/UserScript==

(function () {
    'use strict';
    var password = localStorage.getItem("password");
    var hassioHost, easyboxHost, hassioToken;
    if (!password) {
        password = prompt("Please provide the password for logging in to Vodafone Easybox (will be stored in your browser)");
        hassioHost = prompt("Please enter the URL where HomeAssistant is running (e.g. http://192.168.0.4:8123)");
        easyboxHost = prompt("Please enter the URL of your Vodafone Router (should be http://192.168.0.1)", "http://192.168.0.1");
        hassioToken = prompt("Please enter your 'Long-Lived Access Token' (can be obtained from HomeAssistant Web-GUI)");
        localStorage.setItem("hassioHost", hassioHost);
        localStorage.setItem("easyboxHost", easyboxHost);
        localStorage.setItem("password", password);
        localStorage.setItem("hassioToken", hassioToken);
    } else {
        hassioHost = localStorage.getItem("hassioHost");
        easyboxHost = localStorage.getItem("easyboxHost");
        hassioToken = localStorage.getItem("hassioToken");
    }

    setTimeout(() => checkLoginRequired(), 2000);
    setTimeout(() => location.reload(true), 90000);

    function checkLoginRequired() {
        if ($("#Password").length) {
            $("#Password").attr("value", password);
            $("#LoginBtn").click();
            setTimeout(() => $(".popup input").delay(1000).click(), 1000);
        } else {
            if ($("tbody#dhcpDevInfo").length) {
                getAllDevices();
            } else {
                window.location.href = easyboxHost + "/?status_lan&mid=StatusLan";
            }
        }
    }

    function getAllDevices() {
        console.log("looking for devices");
        $(".content-lan-status tbody#dhcpDevInfo tr").each(function () {
            var mac = $(this).find("td:nth-child(2)").text();
            var status = $(this).find("td:nth-child(5)").text().toLowerCase();

            var home = (status === "aktiv" || status === "active") ? "home" : "not_home";
            console.log(mac, "-->", home);

            GM_xmlhttpRequest({
                method: "POST",
                headers: {
                    "Authorization": "Bearer " + hassioToken
                },
                url: hassioHost + "/api/services/device_tracker/see",
                data: "{\"mac\":\"" + mac + "\",\"location_name\":\"" + home + "\"}",
                onload: function (response) {
                    console.log(mac, response.statusText);
                }
            });
        });
    }
})();