Greasy Fork

Greasy Fork is available in English.

豆瓣界面优化

用于美化豆瓣小组界面

当前为 2022-07-17 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         豆瓣界面优化
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  用于美化豆瓣小组界面
// @license      BSD-3
// @author       AnyDoor
// @match        https://www.douban.com/group/*
// @icon         https://img3.doubanio.com/dae/accounts/resources/3e96b44/shire/assets/nav_doubanapp_6.png
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// @grant        GM_listValues
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';
    // Your code here...
    //var kk=["1","2","3"]
    //GM_setValue("key",kk);
    //console.log(GM_listValues());
    //console.log(GM_getValue("key"));
    $("head").append(
        `
    <style>
    .DrawTag {
        font-size: 12px;
        display: inline-block;
        color: white;
        margin-right: 4px;
        background-color: #7c4df0;
        border: 1px solid rgba(0, 0, 0, 0.1);
        padding: 1px 3px;
        border-radius: 2px;
        line-height: 18px;
    }
    </style>
    `);
    $("head").append(
        `
    <style>
        .ZeroreplyTag{
            font-size: 12px;
            display: inline-block;
            color: white;
            margin-right: 4px;
            background-color: #3b9f75;
            border: 1px solid rgba(0,0,0,0.1);
            padding: 1px 3px;
            border-radius: 2px;
            line-height: 18px;
        }
    </style>
    `);
    //获取所有帖子目标 排除第一行的标题栏
    var TitleObject = document.querySelectorAll('table.olt tbody tr:not(.th)');
    //抽奖贴子关键词 可以自行添加
    var KeyWordList = ["抽奖","抽个","抽一个","抽两个","抽三个"]
    //抽奖帖子黑名单 可以自行添加
    var BlackList = ["插件"]
    //对每一个帖子进行巡逻
    TitleObject.forEach(to =>{
        var TitleInfo = to.children[0];//标题信息 可能包含置顶标签、精华标签和标题
        var AuthorInfo = to.children[1];//作者信息 作者的昵称
        var ReplyInfo = to.children[2];//回复信息 回复数量 无回复时为空
        var TimeInfo = to.children[3];//时间信息 最后回复的时间
        //对标题信息进行处理
        var TitleInfo_Children = TitleInfo.children;//获取所有子元素
        var TitleInfo_len = TitleInfo_Children.length;//获取子元素个数
        var TitleInfo_text=TitleInfo_Children[TitleInfo_len-1].innerText;//获取标题文本
        //console.log(TitleInfo_text);
        //抽奖标签判断机制
        var DrawTag = document.createElement("span");//创建抽奖标签
        DrawTag.className = 'DrawTag';
        DrawTag.textContent = "抽奖";
        KeyWordList.forEach(kwl =>{
            //半段标题是否包含黑名单关键词
            BlackList.forEach(bl =>{
                if(TitleInfo_text.includes(kwl) && (!TitleInfo_text.includes(bl))){
                    TitleInfo.insertBefore(DrawTag,TitleInfo_Children[TitleInfo_len-1]);
                }
            });
        });
        //0同接判断机制
        var ReplyInfo_num =ReplyInfo.innerText;//获取的时字符串 并非数值
        if(ReplyInfo_num==''){
            //构建回复标签
            var ZeroreplyTag = document.createElement("span");
            ZeroreplyTag.className = 'ZeroreplyTag';
            ZeroreplyTag.textContent = "0回复";
            //在标题前插入回复标签
            TitleInfo.insertBefore(ZeroreplyTag,TitleInfo_Children[TitleInfo_len-1]);
        }

    });

    //首页去广告
    try{
        document.getElementById('dale_each_group_home_bottom_right').remove();
        document.getElementById('dale_group_home_middle_right').remove();
        document.getElementById('dale_group_topic_new_bottom_right').remove();
        document.getElementById('dale_group_topic_new_inner_middle').remove();
        document.getElementById('dale_group_topic_new_top_right').remove();
    }catch(err) {}
    //优化菜单
    try{
        var menu = document.querySelectorAll('div.more-items');
        //消息栏样式
        $("head").append(
        `
        <style>
        .infomenu{
            height: 100px;
            text-align: center;
            color: blue;
        }
        </style>
        `
        );
        //重写菜单
        menu[0].innerHTML=`
                            <div class="infomenu">
                                <p class="infotext">脚本设置面板装修中……<br>敬请期待</p>
                                <p class="infotext"><input type="checkbox" id="card-switch">拉姐生日会宣传页(仅正组有效)</p>
                            </div>
                            <table cellpadding="0" cellspacing="0">
                                <tbody>
                                    <tr>
                                        <td><a href="https://www.douban.com/mine/">个人主页</a></td>
                                        <td>
                                            <a target="_blank" href="https://www.douban.com/mine/orders/">我的订单</a>
                                        </td>
                                        <td>
                                            <a target="_blank" href="https://www.douban.com/mine/wallet/">我的钱包</a>
                                        </td>
                                        <td>
                                            <a target="_blank" href="https://accounts.douban.com/passport/setting/">帐号管理</a>
                                        </td>
                                        <td>
                                            <a href="https://www.douban.com/accounts/logout?source=group&amp;ck=Qp49">退出</a>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        `
    }catch(err){}
    //拉姐宣传页 仅正组有效
    if(document.location.href.includes("728957")){
        let cardSwitch = unsafeWindow.document.getElementById('card-switch');
        let showCard = GM_getValue('show_card', true);
        var FloatTag = document.getElementsByClassName("mod side-nav")[0]
        FloatTag.innerHTML+="<a href='https://live.bilibili.com/22632424' title='点我飞到拉姐直播间∠🐮\n点击右上角我的账号即可关闭'><img class ='adimg' src='https://i0.hdslb.com/bfs/new_dyn/a3170d28a261154d2b4d899520519aa7672353429.jpg'></a>";//创建宣传图
        var ADimg = document.getElementsByClassName("adimg")[0]
        ADimg.style.width="-webkit-fill-available"//宽度约束
        ADimg.style.borderRadius="15px"//宽度约束
        cardSwitch.checked = showCard;//获取宣传页状态
        if(cardSwitch.checked){ADimg.style.display="block"}else{ADimg.style.display="none"}
        cardSwitch.addEventListener('click', () => {
            GM_setValue('show_card', cardSwitch.checked);
            if(cardSwitch.checked){ADimg.style.display="block"}else{ADimg.style.display="none"}
        })
    }
    // let id=GM_registerMenuCommand ("测试(不要点击)", function(){
    //     //alert('菜单点击');
    //     //GM_unregisterMenuCommand(id);//删除菜单
    // }, "h");
})();