Search code examples
javascriptblogger

Using statically for blogger images


Currently, blogger images are loaded from 1.bp.blogspot.com or 2.bp.blogspot.com or 3.bp.blogspot.com

Is there a way, to load the uploaded images from statically.

Example: https://2.bp.blogspot.com/-zz2hQ1thv8w/V_YilPYNecI/AAAAAAAABFQ/OwC5dN0Rbo4eoXTrQ82E4k3arwfzxeBqwCK4B/s1600-e365/Figure-1-New-Ballard-score-Reprinted-with-permission-from-Ballard-JL-Khoury-JC-Wedig.png

CONVERTED AUTOMATICALLY TO

https://cdn.statically.io/img/2.bp.blogspot.com/-zz2hQ1thv8w/V_YilPYNecI/AAAAAAAABFQ/OwC5dN0Rbo4eoXTrQ82E4k3arwfzxeBqwCK4B/s1600-e365/Figure-1-New-Ballard-score-Reprinted-with-permission-from-Ballard-JL-Khoury-JC-Wedig.png

I mean: any script to automatically add cdn.statically.io/img/ before the image url?


Solution

  • Here is a simple javascript code to replace the start of all images, don't forget to wrap it within a <script> tag:

    document.querySelectorAll('img').forEach(function(img){
        img.src = img.src.replace(/(http|https):\/\//,'https://cdn.statically.io/img/');
    });