Raw Source
gtranter62 / PhotoBucketImageReplacer

// ==UserScript==
// @name         PhotoBucketImageReplacer
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Replace Photobucket images with a link to the image on PhotoBucket. Optionally remove the images even when they already have a link back to PhotoBucket.
// @author       G. Tranter
// @match        *://*.diystompboxes.com/*
// @match        *://*.freestompboxes.org/*
// @match        *://*.electricalaudio.com/*
// @grant        none
// @updateURL    https://openuserjs.org/meta/gordtrantergmail.com/PhotoBucketImageReplacer.meta.js
// @copyright    2017, G. Tranter
// ==/UserScript==

(function() {
    'use strict';

	var replaceLinkedBackImages = false; // set to true if you want to also replace images that link back to the image on PhotoBucket.com

    var imgTags = document.getElementsByTagName('img');
    for (var i = 0; i < imgTags.length; i++) {
        var img = imgTags.item(i);
        var url = img.getAttribute('src');
        if (url.indexOf('photobucket.com/') > 0) {
            var link = document.createElement('a');
            link.setAttribute('href', url);
            link.setAttribute('target', 'notPhotoBucket');
            link.innerHTML = url;
            var parent = img.parentElement;
            if (parent.tagName != 'A') {
                // not in a link - replace image with link to photobucket and text
                parent.insertBefore(link, img);
                img.remove();
                i--;
                console.log('PhotoBucket 3rd Party Hosting Upgrade Notice replaced with link: ' + url + ' parent is not a link');
            } else {
				if (parent.getAttribute('href').indexOf('photobucket.com/') < 0 ) {
					// image is in a link to somewhere else - append a photobucket link
					parent.insertAdjacentElement('afterEnd', document.createElement('br'));
					parent.insertAdjacentElement('afterEnd', link);
					img.remove();
					i--;
					console.log('PhotoBucket 3rd Party Hosting Upgrade Notice replaced with link: ' + url + ' parent link is not to photobucket');
				} else if (replaceLinkedBackImages) {
					var span = document.createElement('span');
					span.innerHTML = url;
                    parent.insertBefore(span, img);
					img.remove();
					i--;
					console.log('PhotoBucket 3rd Party Hosting Upgrade Notice replaced with link: ' + url + ' parent is a link to photobucket');
				}
            }
        }
    }
})();