Greasy Fork

来自缓存

Greasy Fork is available in English.

自动展开知识星球帖子+替换图片为原图显示

知识星球:阿虚的问答社区

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         自动展开知识星球帖子+替换图片为原图显示
// @namespace    https://axutongxue.com/
// @version      0.1
// @license      MIT
// @description  知识星球:阿虚的问答社区
// @author       阿虚同学
// @match        https://wx.zsxq.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to simulate a mouse click event
    function simulateClick(element) {
        var evt = new MouseEvent("click", {
            bubbles: true,
            cancelable: true,
            view: window
        });
        element.dispatchEvent(evt);
    }

    // Function to click all elements with the 'showAll' class
    function clickAllShowAll() {
        var elements = document.querySelectorAll('p.showAll');
        elements.forEach(function(el) {
            simulateClick(el);
        });
    }

    // Run the click function when the page loads
    window.addEventListener('load', function() {
        // Wait a bit for elements to load (adjust the timeout as necessary)
        setTimeout(clickAllShowAll, 2000); // Waits for 2 seconds
    });

      // Function to replace the src attribute of images with the href of the corresponding original image links
    function replaceImageSrc() {
        // Select all the containers
        var containers = document.querySelectorAll('.image-container');
        containers.forEach(function(container) {
            // For each container, find the image and the link
            var image = container.querySelector('img.image');
            var link = container.querySelector('a.original-image');
            // If both the image and the link exist, replace the image's src with the link's href
            if (image && link && link.href) {
                image.src = link.href;
            }
        });
    }

    // Run the replace function when the page loads
    window.addEventListener('load', replaceImageSrc);

    // If the content is dynamically loaded, you might need to run the function after a certain interval
    setInterval(replaceImageSrc, 5000); // Runs every 5 seconds
})();