<script type='text/javascript'>
//<![CDATA[
setTimeout(function() {
// 1. 保留:处理 <img> 标签(文章内图片)
const googleImages = document.querySelectorAll('img[src*="googleusercontent.com"], img[src*="ggpht.com"]');
googleImages.forEach(img => {
if (!img.src.includes('images.weserv.nl')) {
img.src = 'https://images.weserv.nl/?url=' + encodeURIComponent(img.src);
img.onerror = () => img.src = 'https://picsum.photos/400/300';
}
});
// 2. 保留:处理 <meta> 标签(首页预览图)
const googleMetaImages = document.querySelectorAll('meta[content*="googleusercontent.com"], meta[content*="ggpht.com"]');
googleMetaImages.forEach(meta => {
const content = meta.getAttribute('content');
if (content && !content.includes('images.weserv.nl')) {
meta.setAttribute('content', 'https://images.weserv.nl/?url=' + encodeURIComponent(content));
}
});
// 3. 新增:处理 CSS 背景图(首页轮播图等)
const elementsWithBg = document.querySelectorAll ('*'); // 遍历所有元素
elementsWithBg.forEach(el => {
const bgStyle = window.getComputedStyle(el).backgroundImage;
// 匹配包含谷歌图片链接的背景图
if (bgStyle.includes('googleusercontent.com') || bgStyle.includes('ggpht.com')) {
// 提取背景图 URL(处理 URL 引号包裹的情况)
const urlMatch = bgStyle.match(/url\(['"]?(.*?)['"]?\)/);
if (urlMatch && urlMatch[1] && !urlMatch[1].includes('images.weserv.nl')) {
const originalUrl = urlMatch[1];
const proxiedUrl = 'https://images.weserv.nl/?url=' + encodeURIComponent(originalUrl);
// 重新设置背景图
el.style.backgroundImage = `url('${proxiedUrl}')`;
}
}
});
}, 1000); // 延长延迟到 1000ms,确保 CSS 样式完全加载
//]]>
</script>
把这段代码放在谷歌博客的任意模板头部 < head > 里面,网站访问速度 图片加载速度杠杠的,模板还可以随便修改,完全免费的无限储存空间。