Greasy Fork

Greasy Fork is available in English.

链滴社区优化

优化内容:1. 标记打赏用户和黑名单用户;2. 当前窗口打开链接;3.首页标签增加优选、最新回帖、代码片段、创造、新发布、EN等按钮;4.标签列表页显示文档数和分页分割线;5.链滴自动跳转;6. 聊天页面字体大小;7.聊天页面按日期增加分割线和;8.聊天页面右侧按日期增加跳转日期列表

当前为 2025-04-16 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         链滴社区优化
// @namespace    http://tampermonkey.net/
// @version      2025-04-16
// @description  优化内容:1. 标记打赏用户和黑名单用户;2. 当前窗口打开链接;3.首页标签增加优选、最新回帖、代码片段、创造、新发布、EN等按钮;4.标签列表页显示文档数和分页分割线;5.链滴自动跳转;6. 聊天页面字体大小;7.聊天页面按日期增加分割线和;8.聊天页面右侧按日期增加跳转日期列表
// @author       Wilson
// @match        https://ld246.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ld246.com
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 打赏用户列表,多个用英文逗号隔开即可,没有保持空即可,这个列表的用户头像上会有爱心标志
    var loveUsers = '';

    // 打赏用户列表,多个用英文逗号隔开即可,没有保持空即可(通常用于标记垃圾广告及骗子用户),这个用户的头像上会有红色x号
    var blackUsers = '';

    // 打赏用户
    loveUsers = loveUsers.split(',').map(i=>i.trim()).filter(i=>i);
    var loveSelector = loveUsers.map(username => `[href$='${username}'], [pjax-title^='${username}']`).join(',\n');

    // 链滴黑名单列表
    blackUsers = blackUsers.split(',').map(i=>i.trim()).filter(i=>i);
    var blackSelector = blackUsers.map(username => `[href$='${username}'], [pjax-title^='${username}']`).join(',\n');

    GM_addStyle(`
        /* 打赏用户 */
        a:is(
            ${loveSelector}
        ) {
           &::before{
                content: "♥️";
                left: 1px;
                position: relative;
                z-index: 10;
                top: 1px;
                color: green;
            }
            &:has(:is(.article-list__participant,.tooltipped__user))::before{
                left: 15px;
                margin-left: -15px;
            }
            .article__meta &::before {
                left: -25px;
            }
        }
        /* 黑名单 */
        a:is(
            ${blackSelector}
        ) {
           &::before{
                content: "❌";
                left: 1px;
                position: relative;
                z-index: 10;
                top: 1px;
                color: red;
            }
            &:has(:is(.article-list__participant,.tooltipped__user))::before{
                left: 15px;
                margin-left: -15px;
            }
            .article__meta &::before {
                left: -25px;
            }
        }
    `);
    setTimeout(()=>{
        // 当前窗口打开
        var links = document.querySelectorAll('a[target="_blank"]');
        for (var i = 0; i < links.length; i++) {
            links[i].removeAttribute('target');
        }
        // 首页标签按钮
        var createButton = function(name, url, blank){
            var newSpan = document.createElement("span");
            newSpan.className = "tabs-sub__item tabs-sub__item"; // 注意这里可能有一个类名书写错误,实际使用中请检查你的类名定义
            newSpan.innerHTML = name;
            newSpan.onclick = function() {
                if(blank) window.open(url); else location.href = url;
            };
            // 获取目标元素
            var chatBtn = document.getElementById("chatBtn");
            // 检查是否存在父节点以便插入新元素
            if (chatBtn) {
                // 在#chatBtn之前插入新的span元素
                chatBtn.parentNode.insertBefore(newSpan, chatBtn);
            }
        }
        createButton('优选', 'https://ld246.com/recent/perfect');
        createButton('最新回帖', 'https://ld246.com/recent/reply');
        createButton('代码片段', 'https://ld246.com/tag/code-snippet');
        createButton('创造', 'https://ld246.com/tag/creation');
        createButton('新发布', 'https://github.com/siyuan-note/siyuan/releases', true);
        createButton('EN', 'https://liuyun.io/', true);
        // 标签列表页显示文档数和分页分割线
        if(location.href.indexOf("ld246.com/tag/")!==-1){
            GM_addStyle(`
                .listAjax li:nth-child(32n){border-bottom: 2px solid black;}
                [html--dark] .listAjax li:nth-child(32n){border-bottom: 2px solid white;}
                .listAjax{counter-reset: item-counter;}
                .listAjax li::before {
                    content: counter(item-counter);
                    counter-increment: item-counter;
                    position: absolute;
                    left: 146px;
                    margin-top: 15px;
                    text-align: right;
                    color: var(--text-color);
                }
                .tabs-sub {
                    --before-left: 54px;
                }
                .tabs-sub::before {
                    content: attr(data-total);
                    position: absolute;
                    left: var(--before-left);
                    text-align: right;
                    color: var(--text-color);
                }
            `);
            (async ()=>{
                var pageSize = 32;
                var result = await fetch(location.href + "?ajax=true&p=1");
                result = await result.json();
                var page1Length = document.querySelector(".listAjax").children.length;
                if(page1Length < pageSize) document.querySelector(".tabs-sub").style.setProperty('--before-left', '146px');
                document.querySelector(".tabs-sub").setAttribute('data-total', page1Length < pageSize ? page1Length : '~ ' + ((result.paginationPageCount+1) * pageSize +16)+' ±16');
            })();
        }
    }, 1000);

    // 链滴自动跳转
    if (location.href.indexOf("ld246.com/forward")!==-1) {
        document.querySelector(".text button").click();
    }
    // 聊天页面字体大小
    if (location.href.indexOf("ld246.com/chats/")!==-1) {
        GM_addStyle(`.chats__content .ft-13{font-size: 16px;}.chats__content .ft__fade{font-size:14px;}`);
    }

    // 聊天界面添加分割线和右侧按日期跳转列表
    if (location.href.indexOf("ld246.com/chats/")!==-1) {
        // ================= 原有分割线功能 =================
        GM_addStyle(`
    /* 分隔符样式 */
    .new-day-separator {
        border-top: 2px solid #ccc;
        padding-top: 10px;
        position: relative;
    }

    /* 新增悬浮列表样式 */
    #date-floating-list {
        position: fixed;
        right: 41px;
        top: 50%;
        transform: translateY(-50%);
        background-color: var(--background-color); /*rgba(255, 255, 255, 0.95);*/
        /*border: 1px solid #ddd;*/
        border: 1px solid var(--layer-border-color);
        border-radius: 3px;
        padding: 12px 16px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        max-height: 80vh;
        overflow-y: auto;
        z-index: 9999;
        font-family: Arial, sans-serif;
    }

    .date-item {
        padding: 6px 12px;
        margin: 4px 0;
        border-radius: 4px;
        cursor: pointer;
        transition: all 0.2s;
        font-size: 14px;
        color: var(--layer-color); /*#666;*/
        white-space: nowrap;
    }

    .date-item:hover {
        /*background: #f0f0f0;
        color: #333;*/
        background-color: var(--background-secondary-color);
        color: var(--toc-hover-color);
        transform: translateX(-4px);
    }

    .highlight {
        animation: highlight-fade 1s ease-out;
    }

    @keyframes highlight-fade {
        0% { background: rgba(255,235,59,0.3); }
        100% { background: transparent; }
    }
    `);

        // ================= 原有分割线逻辑 + 新增悬浮列表数据收集 =================
        const chatItems = document.querySelectorAll('.chats__list .chats__item');
        const dateMap = new Map();
        let previousDate = null;

        chatItems.forEach((item, index) => {
            // 原有分割线逻辑
            const timeElement = item.querySelector('.ft__smaller.ft__fade.fn__right');
            if (!timeElement) return;

            const timeString = timeElement.textContent.trim();
            const currentDate = new Date(timeString);
            currentDate.setHours(0, 0, 0, 0);

            // 收集日期数据用于悬浮列表
            const dateKey = currentDate.toISOString().split('T')[0];
            if (!dateMap.has(dateKey)) {
                dateMap.set(dateKey, {
                    element: item,
                    dateStr: timeString.split(' ')[0]
                });
            }

            // 原有日期比较逻辑
            if (index > 0 && !isSameDay(currentDate, previousDate)) {
                item.classList.add('new-day-separator');
            }
            previousDate = currentDate;
        });

        // ================= 新增悬浮列表功能 =================
        const dateList = document.createElement('div');
        dateList.id = 'date-floating-list';

        // 按日期排序(从新到旧)
        const sortedDates = [...dateMap.entries()].sort((a, b) => new Date(b[0]) - new Date(a[0]));

        sortedDates.forEach(([dateKey, data]) => {
            const dateItem = document.createElement('div');
            dateItem.className = 'date-item';
            dateItem.textContent = data.dateStr;

            dateItem.addEventListener('click', () => {
                data.element.scrollIntoView({
                    behavior: 'smooth',
                    block: 'start'
                });
                data.element.classList.add('highlight');
                setTimeout(() => data.element.classList.remove('highlight'), 1000);
            });

            dateList.appendChild(dateItem);
        });

        document.body.appendChild(dateList);

        // ================= 原有辅助函数 =================
        function isSameDay(date1, date2) {
            if (!date1 || !date2) return false;
            return (
                date1.getFullYear() === date2.getFullYear() &&
                date1.getMonth() === date2.getMonth() &&
                date1.getDate() === date2.getDate()
            );
        }
    }
})();