Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Fish Wrangler Wiki Parser</title>
- <style>
- body {
- font-family: sans-serif;
- max-width: 1000px;
- margin: 0 auto;
- padding: 20px;
- line-height: 1.6;
- }
- textarea {
- width: 100%;
- height: 200px;
- margin-bottom: 20px;
- padding: 10px;
- font-family: monospace;
- }
- button {
- padding: 10px 15px;
- background-color: #4CAF50;
- color: white;
- border: none;
- cursor: pointer;
- font-size: 16px;
- margin-right: 10px;
- }
- button:hover {
- background-color: #45a049;
- }
- .controls {
- margin-bottom: 20px;
- }
- .results {
- margin-top: 30px;
- border-top: 1px solid #ccc;
- padding-top: 20px;
- }
- .fish-result {
- margin-bottom: 30px;
- padding: 15px;
- border: 1px solid #ddd;
- background-color: #f9f9f9;
- border-radius: 5px;
- }
- .wiki-code {
- white-space: pre-wrap;
- background-color: #f5f5f5;
- padding: 10px;
- border: 1px solid #ddd;
- overflow-x: auto;
- font-family: monospace;
- border-radius: 3px;
- }
- .copy-btn {
- background-color: #3498db;
- padding: 5px 10px;
- font-size: 14px;
- margin-top: 5px;
- }
- .copy-btn:hover {
- background-color: #2980b9;
- }
- .error {
- color: #e74c3c;
- }
- </style>
- </head>
- <body>
- <h1>Fish Wrangler Wiki Parser</h1>
- <p>Paste the HTML containing fish information below:</p>
- <textarea id="htmlInput" placeholder="Paste HTML here..."></textarea>
- <div class="controls">
- <button onclick="parseFishData()">Parse Fish Data</button>
- <button onclick="clearAll()" style="background-color: #e74c3c;">Clear All</button>
- </div>
- <div class="results" id="results">
- <!-- Results will appear here -->
- </div>
- <script>
- function parseFishData() {
- const htmlInput = document.getElementById('htmlInput').value;
- if (!htmlInput) {
- alert('Please paste some HTML first');
- return;
- }
- // Create a temporary div to parse the HTML
- const tempDiv = document.createElement('div');
- tempDiv.innerHTML = `<table>${htmlInput}</table>`;
- // Find all fish rows
- const fishRows = tempDiv.querySelectorAll('tr.pad.choice, tr.pad.choice.shade_bg, tr[id]');
- const resultsDiv = document.getElementById('results');
- resultsDiv.innerHTML = '';
- if (fishRows.length === 0) {
- resultsDiv.innerHTML = '<p class="error">No fish data found. Make sure you\'re pasting the complete <tr> elements.</p>';
- return;
- }
- fishRows.forEach(row => {
- try {
- const fishData = extractFishData(row);
- displayFishData(fishData, resultsDiv);
- } catch (e) {
- console.error('Error parsing fish row:', e);
- resultsDiv.innerHTML += `<p class="error">Error parsing fish row: ${e.message}</p>`;
- }
- });
- }
- function extractFishData(row) {
- // Extract basic info
- const nameLink = row.querySelector('h2 a, h2.mv2_h1 a');
- const name = nameLink ? nameLink.textContent.trim() : '';
- const fishId = nameLink ? nameLink.getAttribute('href').split('/').pop() : '';
- // Extract image URL
- const img = row.querySelector('td.img img[src*="fishnew"], td.img a img[src*="fishnew"]');
- const imageUrl = img ? img.src : '';
- const imageName = name.replace(/\s+/g, '_') + '.jpg';
- const imageComment = `${name} Fish ID ${fishId}`;
- // Extract description
- let description = '';
- const descriptionDiv = row.querySelector('div.pad.bb.lh');
- if (descriptionDiv) {
- const clearBoth = descriptionDiv.querySelector('.clear_both');
- if (clearBoth) {
- let nextNode = clearBoth.nextSibling;
- while (nextNode) {
- if (nextNode.nodeType === Node.TEXT_NODE && nextNode.textContent.trim()) {
- description = nextNode.textContent.trim();
- break;
- }
- nextNode = nextNode.nextSibling;
- }
- }
- if (!description) {
- const textNodes = [];
- const walker = document.createTreeWalker(
- descriptionDiv,
- NodeFilter.SHOW_TEXT,
- { acceptNode: node => node.textContent.trim() ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT },
- false
- );
- let node;
- while (node = walker.nextNode()) {
- textNodes.push(node.textContent.trim());
- }
- if (textNodes.length > 0) {
- description = textNodes[0];
- }
- }
- description = description.replace(/\s+/g, ' ').trim();
- const wikiLinkIndex = description.indexOf('View on Wiki?');
- if (wikiLinkIndex > -1) {
- description = description.substring(0, wikiLinkIndex).trim();
- }
- }
- // Extract reward info
- let gold = '?';
- let points = '?';
- const rewardText = row.textContent;
- const goldMatch = rewardText.match(/(\d{1,3}(?:,\d{3})*)\s*gold/i);
- const pointsMatch = rewardText.match(/(\d{1,3}(?:,\d{3})*)\s*points/i);
- gold = goldMatch ? goldMatch[1].replace(/,/g, '') : '?';
- points = pointsMatch ? pointsMatch[1].replace(/,/g, '') : '?';
- // Extract weight
- let weight = '';
- const weightImg = row.querySelector('img[src*="weight.gif"]');
- if (weightImg) {
- const weightTd = weightImg.closest('td').nextElementSibling;
- if (weightTd) {
- const weightText = weightTd.textContent.trim();
- if (weightText.includes('kg')) {
- const kgMatch = weightText.match(/(\d+\.?\d*)\s*kg/);
- if (kgMatch) {
- const kg = parseFloat(kgMatch[1]);
- const lb = (kg * 2.20462).toFixed(2);
- weight = `${lb} lb / ${kg} kg`;
- }
- } else if (weightText.includes('g')) {
- const gMatch = weightText.match(/(\d+)\s*g/);
- if (gMatch) {
- const g = parseInt(gMatch[1]);
- const lb = (g / 453.592).toFixed(2);
- weight = `${lb} lb / ${g} g`;
- }
- } else {
- weight = weightText;
- }
- }
- }
- // Extract prefers chum
- let prefers = '?';
- const chumImg = row.querySelector('img[src*="chumnew"]');
- if (chumImg) {
- const prefersTd = chumImg.closest('td').nextElementSibling;
- if (prefersTd) {
- prefers = prefersTd.textContent.trim();
- }
- }
- // Extract habitat
- let habitat = '?';
- const habitatLinks = row.querySelectorAll('a[href*="map-travel"]');
- const popLinks = row.querySelectorAll('a[href*="fish?town="]');
- if (habitatLinks.length > 0 && popLinks.length > 0) {
- const habitats = [];
- for (let i = 0; i < Math.min(habitatLinks.length, popLinks.length); i++) {
- const town = habitatLinks[i].querySelector('u')?.textContent.trim() ||
- habitatLinks[i].textContent.trim();
- const pop = popLinks[i].textContent.trim();
- habitats.push(`[[${town}]] (${pop})`);
- }
- habitat = habitats.join(', ');
- }
- // Extract pole requirement
- let pole = '?';
- const poleTd = row.querySelector('td.red, td:has(img[src*="cog.gif"]) + td, td:has(img[src*="jn.png"]) + td');
- if (poleTd) {
- let levelText = '';
- const levelMatch = poleTd.textContent.match(/Level\s+(TBD|\d+)/i);
- if (levelMatch) {
- levelText = levelMatch[0];
- const jumpMatch = poleTd.textContent.match(/\(Jump#.*?\)/i);
- if (jumpMatch) {
- levelText += ` ${jumpMatch[0]}`;
- }
- }
- const poleLinks = poleTd.querySelectorAll('a[href*="/customize/poles"]');
- const poleNames = Array.from(poleLinks).map(link => {
- return `[[${link.textContent.trim().replace(/^#/, '')}]]`;
- });
- const isMultipole = row.textContent.includes('MULTI-POLE');
- if (isMultipole && poleNames.length > 1) {
- pole = `${levelText} ${poleNames.join(" '''and''' ")}`;
- } else if (poleNames.length > 1) {
- pole = `${levelText} ${poleNames.join(" '''or''' ")}`;
- } else if (poleNames.length > 0) {
- pole = `${levelText} ${poleNames[0]}`;
- } else if (levelText) {
- pole = levelText;
- }
- }
- // Determine if it's a multipole fish
- const fishtype = row.textContent.includes('MULTI-POLE') ? 'multipole' : '';
- const strength = row.textContent.includes('MULTI-POLE') ? '(Multi-pole)' : '';
- // Extract notes - fixed TIP selector
- let notes = '';
- // Find TIP in tiny divs
- const tinyDivs = row.querySelectorAll('div.tiny');
- for (const div of tinyDivs) {
- const bold = div.querySelector('b');
- if (bold && bold.textContent.includes('TIP:')) {
- let tipText = div.textContent.trim();
- tipText = tipText.replace(/TIP:\s*/i, '').trim();
- tipText = tipText.replace(/\s+/g, ' ');
- const collectableLink = div.querySelector('a[href*="/collectable/"]');
- if (collectableLink) {
- const collectableName = collectableLink.textContent.trim();
- tipText = tipText.replace(collectableName, `[[${collectableName}]]`);
- }
- notes = `TIP: ${tipText}`;
- break;
- }
- }
- // Check for task fish note (kept separate from TIP)
- const taskDiv = row.querySelector('div[id$="_task"]');
- if (taskDiv) {
- notes = `The ${name} is part of a Task:<br>\n\n${taskDiv.textContent.trim()}`;
- if (row.textContent.includes('Liquid Gold')) {
- notes += "\n\nNOTE: As with any Multi-Pole Fish, one ''must'' harness [[Liquid Gold]] on it plus enable (turn it 'on') LG in order to catch this fish.";
- }
- }
- return {
- name,
- imageUrl,
- imageName,
- imageComment,
- fishId,
- description,
- gold,
- points,
- weight,
- prefers,
- habitat,
- pole,
- fishtype,
- strength,
- notes
- };
- }
- function displayFishData(fishData, container) {
- const prefersDisplay = fishData.prefers === '?' ? '?' : `[[${fishData.prefers}]]`;
- const wikiCode = `[[${fishData.name} Fish]]
- {{FishInfo
- |param = {{{param}}}
- |image = ${fishData.imageName}
- |gold = ${fishData.gold}
- |points = ${fishData.points}
- |tourney_pts = ?
- |skill =
- |prefers = ${prefersDisplay}
- |pole = ${fishData.pole}
- |habitat = ${fishData.habitat}
- |name = ${fishData.name} Fish
- |fishtype = ${fishData.fishtype}
- |strength = ${fishData.strength}
- |weight = ${fishData.weight}
- |game_ext = ${fishData.fishId}
- |description = ${fishData.description}
- |notes = ${fishData.notes}
- }}`;
- const imageInfo = `The image url: ${fishData.imageUrl}
- The image name will be: ${fishData.imageName}
- The comment will be: ${fishData.imageComment}`;
- const fishDiv = document.createElement('div');
- fishDiv.className = 'fish-result';
- fishDiv.innerHTML = `
- <h2>${fishData.name} Fish</h2>
- <h3>Wiki Code:</h3>
- <div class="wiki-code" id="wiki-code-${fishData.fishId}">${wikiCode}</div>
- <button class="copy-btn" onclick="copyToClipboard('wiki-code-${fishData.fishId}')">Copy Wiki Code</button>
- <div class="image-info">
- <h3>Image Upload Info:</h3>
- <pre id="image-info-${fishData.fishId}">${imageInfo}</pre>
- <button class="copy-btn" onclick="copyToClipboard('image-info-${fishData.fishId}')">Copy Image Info</button>
- </div>
- `;
- container.appendChild(fishDiv);
- }
- function copyToClipboard(elementId) {
- const element = document.getElementById(elementId);
- const range = document.createRange();
- range.selectNode(element);
- window.getSelection().removeAllRanges();
- window.getSelection().addRange(range);
- document.execCommand('copy');
- window.getSelection().removeAllRanges();
- alert('Copied to clipboard!');
- }
- function clearAll() {
- document.getElementById('htmlInput').value = '';
- document.getElementById('results').innerHTML = '';
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment