Skip to content

Instantly share code, notes, and snippets.

@manu354
Forked from JustusW/pokevision_filter.user.js
Last active July 25, 2016 10:47
Show Gist options
  • Select an option

  • Save manu354/4b8d87c6ed107e456215ee2fe20f833e to your computer and use it in GitHub Desktop.

Select an option

Save manu354/4b8d87c6ed107e456215ee2fe20f833e to your computer and use it in GitHub Desktop.
Filter Script for Pokevision.com
// ==UserScript==
// @name Enhanced Pokevision
// @namespace pokevision.com
// @author Justus
// @include https://pokevision*
//
// @run-at document-ready
// @include-jquery true
// @version 1.0.1
// ==/UserScript==
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length,c.length);
}
}
return "";
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
// On to the part that allows you to filter stuff:
$('#style_helper').remove();
$('#togglecontainer').remove();
$('<style id="style_helper" type="text/css">').appendTo(document.head);
$('<div id="togglecontainer">').appendTo(document.body);
// Load Pokemon from Cookies if possible.
var preloaded_pokemon = getCookie('pokevision_stored_filters');
var pokemon = [];
if (preloaded_pokemon) {
pokemon = JSON.parse(preloaded_pokemon);
preloaded_pokemon = true;
} else {
preloaded_pokemon = false;
}
var pre_hidden=[1,2,4,5,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,29,30,32,33,35,36,37,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,60,61,63,64,66,67,69,70,71,72,73,74,75,76,77,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,124,127,128,129,132,133,138,140,146,147];
for (var i = 1; i <= 150; i += 1) {
$(
'<img data-id="' + i + '" id="pokemon_' + i + '" title="Pokemon: ' + i + '" src="//ugc.pokevision.com/images/pokemon/' + i + '.png">'
).appendTo('#togglecontainer')
.click(function () {
var pid = $(this).attr('data-id');
pokemon[pid-1].active = !pokemon[pid-1].active;
updateCss();
setCookie('pokevision_stored_filters', JSON.stringify(pokemon), 365);
});
var state = true;
if (pre_hidden.indexOf(i) > -1) {
state = false;
}
if (!preloaded_pokemon) {
pokemon.push({pid: i, active: state});
}
}
function replacer(pid, display) {
if (display) {
return '';
}
display = 'none';
var border = 'border: 1px solid grey; border-radius: 20px;';
return `.home-map img.leaflet-marker-icon[src$='pokemon/{{id}}.png'] ~ *,
.home-map img.leaflet-marker-icon[src$='pokemon/{{id}}.png'] {
display: {{display}};
}
#togglecontainer img#pokemon_{{id}} {
{{border}}
}`
.replace(new RegExp('{{id}}', 'g'), pid)
.replace(new RegExp('{{display}}', 'g'), display)
.replace(new RegExp('{{border}}', 'g'), border);
}
function updateCss() {
var css = `
#togglecontainer {
position: absolute;
top: 0; left: 0;
width: 40px;
height: 40px;
background: white;
overflow: hidden;
z-index: 9999999999999;
border: 1px solid black;
border-radius: 5px;
}
#togglecontainer:hover, #togglecontainer:focus {
width: 240px;
height: 480px;
overflow: auto;
}
#togglecontainer img {
float: left; width: 40px; height: 40px;
}`;
pokemon.forEach(function (obj) {
css += replacer(obj.pid, obj.active);
});
$('#style_helper').empty().append(
css
);
}
updateCss();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment