昨天发的谷歌博客的代码给大家分享!图片什么的国内完全正常显示

ikuncn (UID: 5795) [复制链接]
帖子链接已复制到剪贴板
帖子已经有人评论啦,不支持删除!

337 4

<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>里面,网站访问速度 图片加载速度杠杠的,模板还可以随便修改,完全免费的无限储存空间。

这家伙太懒了,什么也没留下。
已有评论 ( 4 )
提示:您必须 登录 才能查看此内容。
创建新帖
自助推广点击空位自助购买TG联系
确认删除
确定要删除这篇帖子吗?删除后将无法恢复。
删除成功
帖子已成功删除,页面将自动刷新。
删除失败
删除帖子时发生错误,请稍后再试。