Last active
February 2, 2018 06:02
-
-
Save rooftopchicken/a4a9a3b18fca011f09ca0f99683c733a to your computer and use it in GitHub Desktop.
Formats image links real quick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name FV New Items Formatter | |
| // @author msjanny (7302) | |
| // @description Given an item image index sorted by recent, returns linked images | |
| // @version 0.1 | |
| // @include /http://www\.furvilla\.com/img/items/\d+/\?MD/ | |
| // ==/UserScript== | |
| (function() { | |
| // gets array of links | |
| var html = document.getElementsByTagName("a"); | |
| var links = Array.prototype.slice.call(html); | |
| links.splice(0, 5); | |
| // prompts for range | |
| var lastItem = links[0].href.split(/img\/items\/\d+\//)[1].split('-')[0]; | |
| var minimum = links[links.length - 1].href.split(/img\/items\/\d+\//)[1].split('-')[0]; | |
| var firstItem = prompt("First item ID"); | |
| var valid = firstItem <= lastItem && minimum <= firstItem; | |
| while (!valid) { | |
| firstItem = prompt("First item ID must be less than or equal to " + lastItem + " and greater than or equal to " + minimum + "."); | |
| valid = firstItem <= lastItem && minimum <= firstItem; | |
| } | |
| // finds image URLs and IDs | |
| links = links.slice(0, lastItem - firstItem + 1); | |
| var images = []; | |
| var itemIDs = []; | |
| for ( x = 0; x < links.length ; x++ ) { | |
| images.unshift(links[x].href); | |
| itemIDs.unshift(links[x].href.split(/img\/items\/\d+\//)[1].split('-')[0]); | |
| } | |
| // bbcode concantenation | |
| var bbcode = ""; | |
| for ( x = 0; x < images.length ; x++) { | |
| bbcode = bbcode + "[url=http://www.furvilla.com/museum/items?id=" + itemIDs[x] + "][img]" + images[x] + "[/img][/url]"; | |
| } | |
| document.getElementsByTagName("h1")[0].innerHTML = document.getElementsByTagName("h1")[0].innerHTML + '<textarea style="float: right;">' + bbcode + "</textarea>"; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment