User blog:Rmkane/Easy Way to Create a New Pokemon Page

Greetings,

I have created an automated Pokémon wiki text generator. By visiting a Pokémon's page on the Official Pokédex, a console log will spit out the text of a basic wiki page. The GAME_MASTER data is provided by Celandro's PokéBattler GitHub project. I will be using this as I start to add the remaining Gen II Pokemon.

Words of caution
Be advised that moves are not sorted by damage, and not all moves will translate over correctly. This will require some minimal effort.

Some examples of such moves are:


 * V0100_MOVE_X_SCISSOR is converted to X Scisor, but should be X-Scisor.
 * V0275_MOVE_FUTURESIGHT is converted to Futuresight, but should be Future Sight.

Prerequisites

 * If you are using Chrome, download: Tampermonkey.
 * If you are using Firefox, download: Greasemonkey.

I have not tested this on Firefox yet, so Chrome is a sure bet.

Installation
Once you have installed the usersript plugin for your browser, simply open up the plugin's dashboard and add a new script. Copy and paste the script at the end of this page and hit save. The next time you go to a Pokédex entry, you will see the wiki text logged in the console.

Userscript
Copy the script and paste it into the plugin's editor. If you edit the script, please increment the version number accordingly.

// ==UserScript== // @name        Pokedex Grabber // @namespace   pokemon // @version     1.0.4 // @description Grab all the data! // @author      rmkane // @match       http://www.pokemon.com/us/pokedex/* // @require     https://code.jquery.com/jquery-latest.min.js // @grant        GM_log // ==/UserScript==

(function {   'use strict';    String.prototype.toTitleCase = function  {        return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase + txt.substr(1).toLowerCase;});    };

const jsonUrl = 'https://rawgit.com/celandro/pokebattler-fight/master/src/main/resources/com/pokebattler/fight/data/pokemongo.json';

var title = $('.pokedex-pokemon-pagination-title').children.get(0).childNodes; var data = { index : title[1].innerHTML.trim.substr(1), name : title[0].textContent.trim, description: $('p.version-y').text.trim.split(/\s+/g).join(' ') };

data['cursor'] = []; $('.pokedex-pokemon-pagination .pokedex-pokemon-pagination-wrapper').each((i, wrapper) => {       data['cursor'][i] = {            index : $(wrapper).find('.pokemon-number').text.trim.substr(1),            name : $(wrapper).find('.pokemon-name').text.trim        };    });

data['evo'] = []; $('.pokedex-pokemon-evolution h3.match').map((i, evo) => {       data['evo'].push(evo.childNodes[0].textContent.trim);    });

$('span.attribute-title').each((i, attr) => {       var attrValue = $(attr).parent.children.get(1);        var key = $(attr).text.toLowerCase;        var value = null;

if (data[key] != null) { return; }

switch (key) { case 'gender': value = $(attrValue).children.map((j, child) => {                   return child.className.match(/((?:fe)?male)/g)[0];                }).toArray; break; default: value = $(attrValue).text.trim; }       switch (key) { case 'height': value = (value.match(/^(\d+)'\s*(\d+)\"$/).slice(1).map((x, i) => parseInt(x, 10) * Math.pow(12, 1 - i)).reduce((r, x) => r + x) * 0.0254).toFixed(1) + ' m';               break;            case 'weight':                value = (parseFloat(value.match(/^(\d+\.\d+)\s*lbs$/)[1]) * 0.453592).toFixed(1) + ' kg';                break;            default:                value = $(attrValue).text.trim;        }        data[key] = value;    });

$('.dtm-type ul li a').each((i, type) => {       if (i < 2) data['type' + (i + 1)] = $(type).text.trim;    });

data['weaknesses'] = $('.dtm-weaknesses ul li a').map((i, type) => {       return $(type).text.trim;    }).toArray;

//GM_log(JSON.stringify(data, null, 2));

$.getJSON(jsonUrl, function(jsonData) {       var gameData = jsonData['itemTemplates'].filter(tpl => { return tpl['templateId'].match(new RegExp('^V0' + data['index'] + '_POKEMON_' + data['name'].replace(/\W+/, '').toUpperCase + '$')); });

if (gameData.length !== 1) { alert('Error: Cannot retrieve data for: ' + data['name']); }

printWikiText(data, gameData[0]); });

function ifUndef(value, replacement) { return (value == null || value == 'undefined') ? replacement : value; }

function printWikiText(dexData, gameData) { GM_log([           ,            ,            ,            '==Description==',            '\'\'\ + dexData['category'] + ' Pokémon\'\'\,            ,            dexData['description'],            ,            '==Possible Attacks==',            '\'\'\'Fast Attacks\'\'\,            gameData['pokemonSettings']['quickMoves'].map(m => '* ').join('\n'),            '\'\'\'Special Attacks\'\'\,            gameData['pokemonSettings']['cinematicMoves'].map(m => '* ').join('\n'),            ,            '==Extra Info==',            ,            '==Links==',            '* ',            '* ',            ,            '==History==',            ,            '==Gallery==',            ,            ,            ,            ,             + (dexData['type2'] != null ? '\n' : ),           dexData['weaknesses'].map(w => ).join('\n'),        ].join('\n')); } });

Feedback
If you receive any errors or see a problem with the script, leave a reply.

&mdash; Thanks Rmkane (talk) 03:31, February 25, 2017 (UTC)