Local drupal images

Fix local drupal image issue

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Local drupal images
// @namespace    http://regretless.com/
// @version      0.1.1
// @description  Fix local drupal image issue
// @author       Ying Zhang
// @require      http://code.jquery.com/jquery-latest.js
// @match        http://local.parents.com:1235/*
// @grant        none
// ==/UserScript==
var didNotFindImagesToReplace = 0;

function fixImageSrc(url, replaceUrl) {
    var $totalImagesNeedFixing = $('img[src^="' + url + '"], img[data-src^="' + url + '"]');
    if($totalImagesNeedFixing.length) {
        $totalImagesNeedFixing.each(function() {
            var imageSrc = $(this).attr('src') || $(this).attr('data-src');
            if(imageSrc) {
                if(imageSrc.indexOf('/sites/parents') !== -1) {
                    var newImageSrc = imageSrc.replace(url, replaceUrl);
                    $(this).attr('data-src', newImageSrc).attr('src', newImageSrc).data('src', newImageSrc);
                  
                    console.log('%c replaced img src ' + imageSrc + ' with ' + newImageSrc + ' ', 'background: #222; color: #bada55');
                }
            }
        });
    } else {
        console.log('%c did not find images to replace ', 'background: #222; color: #bada55');
        didNotFindImagesToReplace++;
    }
    $('*').filter(function() {
        var backgroundImage = '';
        if (this.currentStyle) {
            backgroundImage = this.currentStyle['backgroundImage'];
        } else if (window.getComputedStyle) {
            backgroundImage = document.defaultView.getComputedStyle(this,null)
            .getPropertyValue('background-image');
        }
        if(backgroundImage !== 'none' && backgroundImage.indexOf('/sites/parents') !== -1 && backgroundImage.indexOf(replaceUrl) === -1) {
            var newBackgroundImage = backgroundImage.replace(url, replaceUrl);
            $(this).css('background-image', newBackgroundImage);
            console.log('%c replaced background-image ' + backgroundImage + ' with ' + newBackgroundImage + ' ', 'background: #222; color: #bada55');
        }
    });
}



var intervalID = window.setInterval(function() {
    
    
    fixImageSrc('http://9020-jy6dj02.ad.mdp.com:1235', 'http://www.parents.com');
    fixImageSrc('http://local.parents.com:1235', 'http://www.parents.com');
    

}, 1000);