Local drupal images

Fix local drupal image issue

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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);