pokehuntr_auto-refresh

refresh pokehuntr map

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         pokehuntr_auto-refresh
// @namespace    niu541412
// @version      0.63
// @icon         http://img.informer.com/icons_mac/png/128/400/400605.png
// @description  refresh pokehuntr map
// @author       [email protected]
// @license      MIT License
// @match        *://*.pokehuntr.com/*
// @match        *://*.gymhuntr.com/*
// @match        *://*.pokefetch.com/*
// @grant        none
// @run-at       document-end
// ==/UserScript==
(function() {
    'use strict';
    //full screen button
    document.getElementsByClassName("controls")[0].insertAdjacentHTML('beforeend', '<button id="fullscreen" class="botton button-circle" title="Toggle fullscreen" onclick="toggleFullScreen()"><span class="inner"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAQAAAADQ4RFAAAAUklEQVR4AWOgGhgF/8HwPIrYeYgoIU0OKGIOxGm6jyJ2n5Cm8wwOQEUGKGIGQBEHoAwB0AA0FwEbSAgOBBwWmggHBOVBTjhyKU9GhBMslcAoAABPu2Hh6JIyeQAAAABJRU5ErkJggg==" style="opacity:0.6;"></span></button>');
    document.getElementById('fullscreen').addEventListener('click', toggleFullScreen, false);
    //full screen, from mozilla.org
    function toggleFullScreen() {
        var doc = window.document;
        var docEl = doc.documentElement;

        var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
        var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;

        if (!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) {
            requestFullScreen.call(docEl);
        } else {
            cancelFullScreen.call(doc);
        }
    }

    var place = location.hash.match(/[-]*[0-9]*\.[0-9]*/g);
    var lttd_ctr = parseFloat(place[0]);
    var lgtd_ctr = parseFloat(place[1]);
    var ofst = 0.005;
    var num_of_side = 5; // scanning_region_num = num_of_side^2, if you want to change the scanning size, modify this parameter, one sacnning_region is about 0.5 km^2.

    function scan(lttd, lgtd, index) {
        setTimeout(function() {
            var frame = document.createElement("iframe");
            frame.src = "https://pokehuntr.com/#" + lttd + "," + lgtd;
            frame.style.visibility = "hidden";
            //frame.style.position = "fixed";
            frame.id = "Y" + lttd + "X" + lgtd;
            document.body.appendChild(frame);
            setTimeout(function() {
                //console.log(document.getElementById(frame.id).contentWindow.document.location.href);
                document.getElementById(frame.id).contentWindow.document.getElementById("scan").click();
                document.body.removeChild(document.getElementById(frame.id));
            }, 2000 + (Math.random() * 2 - 1) * 10);
        }, 10000 * index);
    }

    function scan_region(lttd_ctr, lgtd_ctr, num) {
        var index = 0;
        var n = (num - 1) / 2;
        for (var i = -n; i <= n; i++) {
            for (var j = -n; j <= n; j++) {
                var lttd = lttd_ctr + ofst * (i + (Math.random() * 2 - 1) / 1000);
                var lgtd = lgtd_ctr + ofst * (j + (Math.random() * 2 - 1) / 1000);
                scan(lttd, lgtd, index);
                index++;
            }
        }
    }

    document.getElementsByClassName("leaflet-control-attribution leaflet-control")[0].style.visibility = "hidden";
    document.getElementsByClassName("scan")[0].style.visibility = "hidden";
    document.getElementById("search").style.display = "none";
    if (document.domain == "pokehuntr.com") {
        scan_region(lttd_ctr, lgtd_ctr, num_of_side);
        setInterval(function() {
            //console.log(new Date());
            scan_region(lttd_ctr, lgtd_ctr, num_of_side);
        }, 420000);
    } else if (document.domain == "pokefetch.com") {
        document.querySelectorAll('a.button.button-circle')[0].style.display = "none";
    }
})();