Greasy Fork

Greasy Fork is available in English.

生财有术官网页面优化

优化生财有术官网页面显示

当前为 2024-07-05 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         生财有术官网页面优化
// @namespace    http://tampermonkey.net/
// @version      1.4.1
// @description  优化生财有术官网页面显示
// @author       骄阳
// @match        https://scys.com/home*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 定义修改标签属性的函数
    function modifyStyles() {

        // 修改class="contentArticle"的max-width属性为800px
        var contentArticles = document.querySelectorAll('.contentArticle');
        contentArticles.forEach(function(contentArticle) {
            contentArticle.style.maxWidth = '800px';
        });

    }

    // 使用MutationObserver监听class属性的变化
    function observeClassChanges() {
        var observer = new MutationObserver(function(mutations) {
            console.log("233")
            mutations.forEach(function(mutation) {
                if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
                    // 确保mutation.target与预期的选择器匹配
                    console.log("23311")
                    var isTargetItem = mutation.target.matches && mutation.target.matches('div.bottom-pagination > div > div.item');
                    console.log("233234")
                    console.log(isTargetItem)
                    if (isTargetItem) {

                        // 使用setTimeout增加延迟执行
                        setTimeout(function() {
                            console.log("modifyStyles");
                            modifyStyles();
                            addDoubleClickListener();
                            addHoverListener();
                            // 此处可以添加更多的样式修改操作
                        }, 1000); // 数字0表示延迟到当前执行栈清空之后执行
                        console.log("modifyStyles end")
                    }
                }
            });
        });

        // 配置MutationObserver观察的节点和属性
        var config = {
            attributes: true, // 观察属性变动
            childList: false, // 不观察子节点的增减
            subtree: true      // 观察整个文档树
        };

        // 开始观察整个文档树中的所有节点
        observer.observe(document, config);
    }

    // 为特定的元素添加双击事件监听器
    function addDoubleClickListener() {
        // 获取所有满足条件的span元素
        var dates = document.querySelectorAll('div.content > div > div.streamline > div > div.date > span');

        // 为每个span元素添加双击事件监听器
        dates.forEach(function(span) {
            span.addEventListener('dblclick', function() {
                // 获取span的父级元素中的contentArticle的div
                var contentArticleDiv = span.closest('div.streamline').querySelector('div.contentArticle > div');

                // 检查是否存在对应的contentArticle的div
                if (contentArticleDiv) {
                    // 复制contentArticle的div内容
                    var contentToCopy = contentArticleDiv.innerText || contentArticleDiv.textContent;

                    // 使用浏览器的execCommand方法将内容复制到剪贴板
                    if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
                        var textarea = document.createElement('textarea');
                        textarea.textContent = contentToCopy.replaceAll("​","").replaceAll("​","").trim();
                        textarea.style.position = 'fixed';  // Prevent scrolling
                        document.body.appendChild(textarea);
                        textarea.select();

                        try {
                            var successful = document.execCommand('copy');
                            var msg = successful ? 'successful' : 'unsuccessful';
                            console.log('Copying text command was ' + msg);
                        } catch (err) {
                            console.error('Unable to copy: ', err);
                        }

                        document.body.removeChild(textarea);
                    }
                }
            });
        });
    }

    // 为特定的元素添加鼠标悬停事件
    function addHoverListener() {
        // 获取所有满足条件的span元素
        var dates = document.querySelectorAll('div.content > div > div.streamline > div > div.date > span');

        // 为每个span元素设置CSS伪类:hover样式
        dates.forEach(function(span) {
            span.addEventListener('mouseenter', function() {
                span.style.cursor = 'pointer'; // 设置鼠标悬停时鼠标样式为小手
            });
            span.addEventListener('mouseleave', function() {
                span.style.cursor = 'auto'; // 鼠标离开时恢复默认鼠标样式
            });

            // 添加title提示
            span.title = '双击复制标题';
        });
    }

    // 创建悬浮按钮的函数
    function createFloatingButtons() {
        // 创建“优化页面”按钮
        var optimizeButton = document.createElement('button');
        optimizeButton.innerText = '优化页面';
        optimizeButton.style.cssText = 'position: fixed; top: 50%; left: 20px; z-index: 1000;background-color:#3d76fb;height:40px;font-size:16px;';
        optimizeButton.addEventListener('click', modifyStyles);

        // 创建“隐藏按钮”按钮
        var hideButton = document.createElement('button');
        hideButton.innerText = '隐藏按钮';
        hideButton.style.cssText = 'position: fixed; top: 55%; left: 20px; z-index: 1000;;background-color:#3d76fb;height:40px;font-size:16px;';
        hideButton.addEventListener('click', function() {
            optimizeButton.remove();
            hideButton.remove();
        });

        // 将按钮添加到页面中
        document.body.appendChild(optimizeButton);
        document.body.appendChild(hideButton);
    }

    // 页面加载完成后执行
    window.addEventListener('load', function() {
        //createFloatingButtons();
        setTimeout(function() {
            console.log("modifyStyles");
            modifyStyles();
            addDoubleClickListener();
            addHoverListener();
            // 此处可以添加更多的样式修改操作
        }, 1000); // 数字0表示延迟到当前执行栈清空之后执行
        observeClassChanges(); // 添加点击事件监听器
    });
})();