Skip to content

Instantly share code, notes, and snippets.

@LoneBoco
Forked from Gavitron/waffleimages.user.js
Created February 20, 2017 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LoneBoco/20f17173781f0e535bf14ef87e084b74 to your computer and use it in GitHub Desktop.
Save LoneBoco/20f17173781f0e535bf14ef87e084b74 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name WaffleImage Grabber
// @namespace http://www.imcrapproductions.com
// @description sup
// @include *forums.somethingawful.com/*
// @include *archives.somethingawful.com/*
// @version 1.0
// @grant none
// ==/UserScript==
// Generated by LiveScript 1.3.1
var getNewLink, deadImages, i$, len$, deadImage, deadImagePath;
getNewLink = function(url){
var parser, segments, imagePath, imageFiletype;
parser = document.createElement('a');
parser.href = url;
segments = parser.pathname.replace(/^\//, '').split('/');
imagePath = segments[0];
//alert(imagePath);
imageFileType = segments[segments.length-1].split(".")[1];
//alert(imageFileType);
//alert('http://randomwaffle.gbs.fm/images/' + imagePath.substring(0, 2) + '/' + imagePath + '.' + imageFileType);
//alert(url + ' ' + imagePath + ' ' + imageFileType);
return 'http://randomwaffle.gbs.fm/images/' + imagePath.substring(0, 2) + '/' + imagePath + '.' + imageFileType;
};
deadImages = $("img[src*='waffleimages']");
//alert('found '+deadImages.length+' images');
for (i$ = 0, len$ = deadImages.length; i$ < len$; ++i$) {
deadImage = deadImages[i$];
deadImagePath = deadImage.src;
var newLink = getNewLink(deadImagePath);
deadImage.src = newLink;
//console.log(i + ' : ' + deadImagePath + ' : ' + newLink);
}
var deadLinks = $("a[href*='waffleimages']");
for (i$ = 0, len$ = deadLinks.length; i$ < len$; ++i$) {
var deadLink = deadLinks[i$];
var deadLinkPath = $(deadLink).attr('href');
var newLink = getNewLink(deadLinkPath);
$(deadLink).attr('href', newLink);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment