Raw Source
natsxd / POGOCenter

// ==UserScript==
// @name         POGOCenter
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  In pogovision, turns position into current, and changes the default url to open location
// @copyright    2018, natsxd
// @license      MIT; https://opensource.org/licenses/MIT
// @author       natsxd
// @match        https://pogovision.xyz/map/
// @grant        none
// @updateURL    https://openuserjs.org/meta/natsxd/My_Script.meta.js
// ==/UserScript==

(function() {
    'use strict';

    if(!Store.get('startAtLastLocationPosition')) {
        Store.set('startAtLastLocationPosition', true);
        centerMapOnLocation();
        console.log('Setting start position as last');
    }
    notifyIvTitle = '<pkm> <prc>% / lvl<plv>';

    openMapDirections = function(lat, lng) {
        var url = 'http://www.google.com/maps/place/' + lat + ',' + lng;
        window.open(url, '_blank');
    };
    getNotifyText = function(item) {
        var iv = getIv(item['individual_attack'], item['individual_defense'], item['individual_stamina']);
        var find = ['<prc>', '<plv>', '<pkm>'];
        var replace = [iv ? iv.toFixed(1) : '', item['level'], item['pokemon_name']];
        var ntitle = repArray(iv ? notifyIvTitle : notifyNoIvTitle, find, replace);
        var dist = new Date(item['disappear_time']).toLocaleString([], {
            hour: '2-digit',
            minute: '2-digit',
            second: '2-digit',
            hour12: false
        });
        var until = getTimeUntil(item['disappear_time']);
        var udist = until.hour > 0 ? until.hour + ':' : '';
        udist += lpad(until.min, 2, 0) + 'm' + lpad(until.sec, 2, 0) + 's';
        find = ['<dist>', '<udist>'];
        replace = [dist, udist];
        var ntext = repArray(notifyText, find, replace);

        return {
            'fav_title': ntitle,
            'fav_text': ntext
        };
    };
    sendNotification = function(title, text, icon, lat, lng) {
        if (!('Notification' in window)) {
            return false; // Notifications are not present in browser
        }
        var wppurlprefix = "https://api.whatsapp.com/send?text=";
        var url = 'http://www.google.com/maps/place/' + lat + ',' + lng;

        var message = title + ", " + text + "\n" + url;
        var wppurl = encodeURI(wppurlprefix + message);

        if (Push.Permission.has()) {
            Push.create(title, {
                icon: icon,
                body: text,
                vibrate: 1000,
                onClick: function onClick() {
                    window.focus();
                    this.close();
                    //centerMap(lat, lng, 20);
                    window.open(wppurl, '_blank');
                }
            });
        }
    };

    function createElementFromHTML(htmlString) {
        var div = document.createElement('div');
        div.innerHTML = htmlString.trim();

        // Change this to div.childNodes to support multiple top-level nodes
        return div.firstChild;
    }

    function createRefreshButton() {
        setTimeout(function(){
            var refreshButton = '<div style="z-index: 0; position: absolute; bottom: 119px; right: 0px;"><button style="background-color: rgb(255, 255, 255); border: none; outline: none; width: 28px; height: 28px; border-radius: 2px; box-shadow: rgba(0, 0, 0, 0.3) 0px 1px 4px; cursor: pointer; margin-right: 10px; padding: 0px;" onclick="updateMap(); console.log(\'Reloading\')"><div style="margin: 5px; width: 18px; height: 18px;"><span style="color: black;">*</span></div></button></div>';
            var locationButton = document.getElementById('current-location');
            if(locationButton != null) {
                locationButton.parentNode.parentNode.parentNode.insertBefore(createElementFromHTML(refreshButton), document.getElementById('current-location').parentNode.parentNode.nextSibling);
            }
            else {
                createRefreshButton();
            }
        }, 1000);
    }
    createRefreshButton();
/*
    sendNotification = function(title, text, icon, lat, lng) {
        var wppurlprefix = "https://api.whatsapp.com/send?text=";
        var url = 'http://www.google.com/maps/place/' + lat + ',' + lng;

        var message = title + ", " + text + "\n" + url;
        var wppurl = encodeURI(wppurlprefix + message);
        window.open(wppurl, '_blank');
    };
*/
    // For pogovision the path for main file is pogovision.xyz/map/static/dist/js/map.built.js
})();