寻灯守护

配合寻灯定位app,在百度地图根据坐标定位位置的网站上https://lbsyun.baidu.com/jsdemo/demo/yLngLatLocation.htm,定位安装该app的安卓设备。可以用于小孩与老人定位、家人定位等

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

// ==UserScript==
// @name         寻灯守护
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  配合寻灯定位app,在百度地图根据坐标定位位置的网站上https://lbsyun.baidu.com/jsdemo/demo/yLngLatLocation.htm,定位安装该app的安卓设备。可以用于小孩与老人定位、家人定位等
// @author       刘liulliu刘
// @match        https://lbsyun.baidu.com/jsdemo/demo/yLngLatLocation.htm*
// @grant        GM_xmlhttpRequest
// @grant        GM_notification
// @grant        GM_openInTab
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 找到所有的 input 元素
    var inputs = document.querySelectorAll('input');
    var timerId; // 保存定时器 ID

    // 遍历每个 input 元素
    inputs.forEach(function(input) {
        // 设置 input 元素的宽度为 200px
        input.style.width = '90px';
    });

/////// @aaarequire111 11     https://unpkg.com/[email protected]/dist/gcoord.global.prod.js

    let Container = document.createElement('div');
    Container.id = "sp-ac-container";
    Container.style.position = "fixed";
    Container.style.left = "20px";
    Container.style.top = "60px";
    Container.style['z-index'] = "999999";
    Container.innerHTML = `
    <div style="display:flex; align-items:center;">
        <input type="text" id="usernameInput" placeholder="用户名" style="width:60px;margin-right: 10px;">
        <input type="text" id="uuidInput" placeholder="UUID" style="margin-right: 10px;">
        <button id="locateButton" style="width:60px;background-color: red; color: white;">定位</button>
    </div>`;
    document.body.appendChild(Container);

    let Container1 = document.createElement('div');
    Container1.id = "sp-ac-container1";
    Container1.style.position = "fixed";
    Container1.style.left = "20px";
    Container1.style.top = "88px";
    Container1.style['z-index'] = "999999";
    Container1.innerHTML = `
    <div style="display:flex; align-items:center;">
        <input type="text" id="usernameInput1" placeholder="用户名1" style="width:60px;margin-right: 10px;">
        <input type="text" id="uuidInput1" placeholder="UUID1" style="margin-right: 10px;">
        <button id="locateButton1" style="width:60px;background-color: red; color: white;">定位</button>
    </div>`;
    document.body.appendChild(Container1);

    var username = null;
    var uuid = null;
    username = GM_getValue('username'); // 从存储器中获取计数器初始值
    uuid = GM_getValue('uuid'); // 从存储器中获取计数器初始值
    document.getElementById("usernameInput").value = username;
    document.getElementById("uuidInput").value = uuid;


    var username1 = null;
    var uuid1 = null;
    username = GM_getValue('username1'); // 从存储器中获取计数器初始值
    uuid = GM_getValue('uuid1'); // 从存储器中获取计数器初始值
    document.getElementById("usernameInput1").value = username;
    document.getElementById("uuidInput1").value = uuid;


    // 检查页面是否完全加载
    window.addEventListener('load', function() {
        // 获取lng和lat的input元素
//         var lngInput = document.getElementById('lng');
//         var latInput = document.getElementById('lat');

//         // 检查input元素是否存在
//         if (lngInput && latInput) {
//             // 发送 POST 请求获取数据
//             username= document.getElementById("usernameInput").value;
//             uuid = document.getElementById("uuidInput").value;
//             GM_setValue('username', username);
//             GM_setValue('uuid', uuid);
//             postURL(username,uuid)

//         } else {
//             console.error('Lng or Lat input elements not found.');
//         }
    });

    // 定义一个函数,每隔 4 秒执行一次
    function postURL(username,uuid) {
        // 每4秒点击一次查询按钮
        // 设置定时器并保存其 ID
        timerId = setInterval(function() {
            //debugger;
            var lngInput = document.getElementById('lng');
            var latInput = document.getElementById('lat');

            GM_xmlhttpRequest({
                method: "POST",
                url: "https://pi.gdsouth.cn:50061/getLocationPost",
                headers: {
                    "Content-Type": "application/json"
                },
                data: JSON.stringify({ username: username,uuid:uuid}), // 使用 JSON.stringify 转换对象为 JSON 字符串
                onload: function(response){
                    console.log("请求成功");
                    console.log(response.responseText);

                    try {
                        var jsonResponse = JSON.parse(response.responseText); // 如果响应也是 JSON,可以解析它
                        console.log(jsonResponse);

                        // 设置lng和lat的值为接收到的数据
                        lngInput.value = jsonResponse.x;
                        latInput.value = jsonResponse.y;


                        // 模拟点击页面上的查询按钮
                        var buttons = document.getElementsByTagName('button');
                        //debugger;
                        for (var i = 0; i < buttons.length; i++) {
                            if (buttons[i].innerText.trim() === '查询') {
                                buttons[i].click(); // 模拟点击按钮操作
                                console.log('Query button clicked.');
                                break;
                            }
                        }

                    } catch (e) {
                        console.error("无法解析响应为 JSON:", e);
                    }
                },
                onerror: function(response){
                    console.log("请求失败");
                }
            });

        }, 4000); // 4000毫秒 = 4秒
    }


    // 监听定位按钮的点击事件
    document.getElementById("locateButton").addEventListener("click", function() {
        var username = document.getElementById("usernameInput").value;
        var uuid = document.getElementById("uuidInput").value;
        GM_setValue('username', username);
        GM_setValue('uuid', uuid);
        //debugger;
        document.getElementById("locateButton").innerText = "定位中";
        document.getElementById("locateButton1").innerText = "定位";
        clearInterval(timerId);
        postURL(username, uuid);
    });


    // 监听定位按钮1的点击事件
    document.getElementById("locateButton1").addEventListener("click", function() {
        var username = document.getElementById("usernameInput1").value;
        var uuid = document.getElementById("uuidInput1").value;
        GM_setValue('username1', username);
        GM_setValue('uuid1', uuid);
        //debugger;
        document.getElementById("locateButton1").innerText = "定位中";
        document.getElementById("locateButton").innerText = "定位";
        clearInterval(timerId);
        postURL(username, uuid);
    });

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址