Skip to content

Instantly share code, notes, and snippets.

@rooftopchicken
Last active February 2, 2018 06:02
Show Gist options
  • Select an option

  • Save rooftopchicken/a4a9a3b18fca011f09ca0f99683c733a to your computer and use it in GitHub Desktop.

Select an option

Save rooftopchicken/a4a9a3b18fca011f09ca0f99683c733a to your computer and use it in GitHub Desktop.
Formats image links real quick
// ==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