微信公众号图集一键展示

让世界更美好!

// ==UserScript==
// @name         微信公众号图集一键展示
// @namespace    http://tampermonkey.net/
// @version      2024.02.08
// @description  让世界更美好!
// @author       sbdx
// @match        https://mp.weixin.qq.com/s/*
// @match        https://mp.weixin.qq.com/s?*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=qq.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    //图集页面的修改
    function showAlbum()
    {
        console.log("开始打开图集事件......");
        var html="";
        window.picture_page_info_list.forEach((i)=>{
            let url=i.cdn_url.replace("/640?","/0?");
            html+=`<img src="${url}" /><br>`;
        });
        document.getElementById('js_article').innerHTML=(html);
    }
    //普通页面图片替换为高清图片
    function replaceHighQualityImage()
    {
        let img=document.querySelector(".rich_media_content").getElementsByTagName("img");
        img.forEach((i)=>{
            let url=i.src.replace("/640?","/0?");
            console.log(url);
            i.dataset.src=url;
            i.src=url;
            window.scrollTo(0, document.body.scrollHeight);
            window.scrollTo(0, 0);
        });
    }
    //优化图片布局显示
    function formatDisplayImage()
    {
        let html='';
        let imgs=document.getElementById('js_content').getElementsByTagName("img");
        imgs.forEach((i)=>console.log(html+=`<img src="${i.dataset.src}" /><br></br>`));html=html.replace("/640?","/0?");
        document.getElementById("js_content").innerHTML=html;
    }
    if(document.getElementById('img_swiper_placeholder'))
    {
        let btn=document.createElement("button");
        btn.innerText="打开图集";
        btn.addEventListener('click',function(){
            showAlbum();
            document.getElementById("js_article").style.display='block';
            document.getElementById("js_article").style.height='inherit';
            document.getElementById("js_article").style.maxHeight='none';
            document.getElementById("js_article").style.overflow='scroll';
        });
        document.querySelector(".rich_media_title").append(btn);
        console.log("确认过眼神,是对的人!");
    }
    else if(document.getElementById('js_content'))
    {
        let btn=document.createElement("button");
        btn.innerText="切换高清图";
        btn.addEventListener('click',function(){
            replaceHighQualityImage();
            document.getElementById("js_article").style.display='block';
            document.getElementById("js_article").style.height='inherit';
            document.getElementById("js_article").style.maxHeight='none';
            document.getElementById("js_article").style.overflow='scroll';
        });
        let btn2=document.createElement("button");
        btn2.innerText="优化布局显示";
        btn2.addEventListener('click',function(){
            formatDisplayImage();
        });
        document.querySelector(".rich_media_meta_list").append(btn);
        document.querySelector(".rich_media_meta_list").append(btn2);
    }
})();