Greasy Fork

Greasy Fork is available in English.

爱上ASMR - Plus

删除黑名单用户的评论、收藏夹备注、显示评分投票、标题封面完全显示

当前为 2023-08-11 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         爱上ASMR - Plus
// @namespace    https://www.asasmr.top/
// @version      2.5
// @description  删除黑名单用户的评论、收藏夹备注、显示评分投票、标题封面完全显示
// @match        https://www.asasmr2.com/sound/*.html*
// @match        https://www.asasmr2.com/video/*.html*
// @match        https://www.asasmr2.com/author/*
// @license MIT
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function() {
    'use strict';

    // 初始化黑名单列表
    let blacklist = GM_getValue('blacklist', []);
    let notes = GM_getValue('notes', {});

    if (window.location.href.startsWith("https://www.asasmr2.com/author/") && window.location.href.match(/\?tab=collect.*/)) {
        // 添加备注区域
        const archiveContainers = document.querySelectorAll('#author-page .archive');
        archiveContainers.forEach(container => {
            const articleLink = container.querySelector('article > a');
            const notesArea = document.createElement('textarea');
            notesArea.classList.add('hmd-notes-area');
            notesArea.placeholder = '添加备注';
            notesArea.value = getNotes(articleLink.href) || '';

            notesArea.addEventListener('input', () => {
                setNotes(articleLink.href, notesArea.value);
            });

            const saveNotesButton = document.createElement('button');
            saveNotesButton.textContent = '保存备注';
            saveNotesButton.classList.add('hmd-save-notes-button');
            saveNotesButton.addEventListener('click', () => {
                setNotes(articleLink.href, notesArea.value);
                alert('备注已保存!');
            });

            container.appendChild(notesArea);
            container.appendChild(saveNotesButton);
        });
    }

    function getNotes(id) {
        if (!notes[id]) {
            notes[id] = [];
        }
        return notes[id].join('\n');
    }

    function setNotes(id, value) {
        notes[id] = value.split('\n');
        GM_setValue('notes', notes);
    }

    // 创建<style>元素来保存CSS规则
    const styleElement = document.createElement('style');
    // 将<style>元素添加到文档的<head>部分
    document.head.appendChild(styleElement);
    // 定义CSS规则
    const cssRules = `

    /* 黑名单 */
  .hmd-fbq {bottom: 60px;right: 10px;cursor: pointer;padding: 10px;background-color: #5d5d5d17;border-radius: 50px;z-index: 105;position: fixed;display: flex;align-items: center;}
  .hmd-fbq:before {content: "黑名单";color: #a7a7a7;}
  .hmd-blacklist {box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.05);overflow: auto;display: none;height: -webkit-fill-available;z-index: 105;position: fixed;top: 9.5%;background: #eaeaeae0;padding: 10px !important;}
  .hmd-blacklist-item > a {padding: 0px 5px;}
  .hmd-blacklist-item {padding: 8px;}
  .hmd-del {background: #fff;border: solid #aaa 1px;border-radius: 4px;}
  .hmd-add-to-blacklist {font-size: 10px !important;padding: 6px 8px !important;border-radius: 4px !important;float: right !important;margin-left: 5px !important;}

  /* 二次确认 */
  .hmd-popup {position: fixed;top: 0;left: 0;width: 100%;height: 100%;background-color: rgba(0, 0, 0, 0.5);display: none;justify-content: center;align-items: center;z-index: 9999;}
  .hmd-popup-content {background-color: #fff;padding: 20px;border-radius: 5px;text-align: center;}
  .hmd-popup h3 {margin-top: 0;}
  .hmd-popup p {margin-bottom: 20px;}
  .hmd-confirm-button,.hmd-cancel-button {padding: 8px 16px;border-radius: 4px;cursor: pointer;border: solid 1px #555;}
  .hmd-confirm-button {background-color: #007bff;color: #fff;margin-right: 10px;}
  .hmd-cancel-button {background-color: #ccc;}

  /* 备注 */
  .hmd-save-notes-button {float: right;margin-top: 20px;}
  .hmd-notes-area {width: -webkit-fill-available;padding: 8px;max-width: 75%;height: 60px;border: 1px solid rgb(204, 204, 204);font-size: 14px;color: rgb(51, 51, 51);}
  .archive-excerpt > p {height: 48px;}

  /* 音视频 */
  .starstruck-wrap {display: block;}
  #single > .content > .sheader > .data {margin: 0;width: auto;}
  #single > .content > .sheader > .poster {width: auto;padding-bottom: 8px;}
  #single > .content > .sheader > .poster > img {width: auto;}
  #single > .content > .sheader {display: flex;flex-direction: column;}
  #info > .wp-content > a {padding-right: 8px;}

`;
    // 将CSS规则添加到<style>元素中
    styleElement.appendChild(document.createTextNode(cssRules));

    // 在页面顶部创建黑名单显示区域
    var butblackListArea = document.createElement('label');
    butblackListArea.setAttribute("id", "hmd-fz");
    butblackListArea.classList.add('hmd-fbq');

    var blackListArea = document.createElement('div');
    blackListArea.classList.add('hmd-blacklist');

    //二次确定
    const popupContainer = document.createElement("div");
    popupContainer.id = "hmd-popup";
    popupContainer.className = "hmd-popup";

    const popupContent = document.createElement("div");
    popupContent.className = "hmd-popup-content";

    const heading = document.createElement("h3");
    heading.textContent = "确认";

    const paragraph = document.createElement("p");
    paragraph.textContent = "确定要将该用户加入黑名单吗?";

    const confirmButton = document.createElement("button");
    confirmButton.id = "hmd-confirm-button";
    confirmButton.className = "hmd-confirm-button";
    confirmButton.textContent = "确认";

    const cancelButton = document.createElement("button");
    cancelButton.id = "hmd-cancel-button";
    cancelButton.className = "hmd-cancel-button";
    cancelButton.textContent = "取消";

    // 将所有元素追加到它们各自的父元素中
    popupContent.appendChild(heading);
    popupContent.appendChild(paragraph);
    popupContent.appendChild(confirmButton);
    popupContent.appendChild(cancelButton);
    popupContainer.appendChild(popupContent);

    // 将黑名单区域添加到页面顶部
    document.body.prepend(butblackListArea);
    document.body.prepend(blackListArea);
    document.body.prepend(popupContainer);

   //点击事件
    const fbqElement = document.querySelector('.hmd-fbq');
    const blacklistElement = document.querySelector('.hmd-blacklist');

    let isBlacklistVisible = false;

    fbqElement.addEventListener('click', function() {
        if (isBlacklistVisible) {
            blacklistElement.style.display = 'none';
        } else {
            blacklistElement.style.display = 'block';
        }

        isBlacklistVisible = !isBlacklistVisible;
    });

    // 渲染黑名单列表
    renderBlacklist();

    // 监听 #wcThreadWrapper 的变化
    const threadWrapper = document.getElementById('wcThreadWrapper');
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.type === 'childList') {
                addBlacklistButtonToComments();
                blockLinks()
            }
        });
    });

    observer.observe(threadWrapper, { childList: true });

    // 添加“加入黑名单”按钮到评论中
    function addBlacklistButtonToComments() {
        const comments = document.querySelectorAll('.wc-comment-right');

        comments.forEach(comment => {
            const commentHeader = comment.querySelector('.wc-comment-header');
            const commentHeaderadd = comment.querySelector('.wc-comment-link');

            const addToBlacklistButton = commentHeader.querySelector('.hmd-add-to-blacklist');
            if (addToBlacklistButton) return; // 避免重复添加按钮

            const username = commentHeader.querySelector('.wc-comment-author > a').innerText;
            const link = commentHeader.querySelector('.wc-comment-author > a').href;

            const button = document.createElement('button');
            button.textContent = '加入黑名单';
            button.classList.add('hmd-add-to-blacklist');
            button.addEventListener('click', () => {
                const popup = document.getElementById('hmd-popup');
                const confirmButton = document.getElementById('hmd-confirm-button');
                const cancelButton = document.getElementById('hmd-cancel-button');

                popup.style.display = 'flex';

                confirmButton.addEventListener('click', () => {
                    blacklist.push({ username, link });
                    GM_setValue('blacklist', blacklist);
                    blockLinks();
                    renderBlacklist();
                    popup.style.display = 'none';
                    location.reload()
                });

                cancelButton.addEventListener('click', () => {
                    popup.style.display = 'none';
                });
            });

            commentHeaderadd.appendChild(button);
        });
    }

    // 渲染黑名单列表
    function renderBlacklist() {
        blackListArea.innerHTML = '';

        blacklist.forEach(item => {
            const blacklistItem = document.createElement('div');
            blacklistItem.classList.add('hmd-blacklist-item');

            const username = document.createElement('span');
            username.textContent = item.username;
            const link = document.createElement('a');
            link.href = item.link;
            link.textContent = item.link;

            blacklistItem.appendChild(username);
            blacklistItem.appendChild(link);

            const deleteButton = document.createElement('button');
            deleteButton.textContent = '删除';
            deleteButton.classList.add('hmd-del');
            deleteButton.addEventListener('click', () => {
                blacklist = blacklist.filter(i => i.link !== item.link);
                GM_setValue('blacklist', blacklist);
                renderBlacklist();
                blockLinks();
            });

            blacklistItem.appendChild(deleteButton);
            blackListArea.appendChild(blacklistItem);
        });
    }

    // 屏蔽黑名单中的链接
    function blockLinks() {
        const links = document.querySelectorAll('.wc-comment-author > a');

        links.forEach(link => {
            const parentElement = link.parentElement.parentElement.parentElement.parentElement;
            const isBlocked = blacklist.some(item => item.link === link.href);

            if (isBlocked) {
                parentElement.style.display = 'none';
            } else {
                parentElement.style.display = '';
            }
        });
    }

    // 页面加载完毕时执行一次
    window.onload = function() {

        // 获取<meta property="og:image">元素的内容
        const ogImageMeta = document.querySelector('meta[property="og:image"]');
        const ogImageUrl = ogImageMeta ? ogImageMeta.getAttribute('content') : '';

        // 替换图片链接
        const dplayerVideo = document.querySelector('#single > .content > .sheader > .poster > img');
        if (dplayerVideo && ogImageUrl) {
            dplayerVideo.setAttribute('src', ogImageUrl);
        }

        // 获取.wp-content下的所有<p>元素
        const paragraphs = document.querySelectorAll('.wp-content p');

        // 创建一个空数组来存储结果
        const youtuberesult = [];

        // 遍历每个<p>元素
        paragraphs.forEach((p) => {
            // 检查元素是否包含"油管:"
            if (p.textContent.includes('油管:')) {
                // 使用正则表达式匹配包含"油管:"的那一行
                const regex = /油管:(.*)/;
                const match = p.textContent.match(regex);

                if (match && match[1].trim() !== '') {
                    // 获取匹配到的文本
                    const matchedText = match[1];

                    // 分割文本为单词
                    const words = matchedText.split(' ');

                    // 遍历每个单词
                    words.forEach((word) => {
                        // 检查单词是否为空字符串
                        if (word.trim() !== '') {
                            // 创建<a>标签并设置href属性为单词链接
                            const link = document.createElement('a');
                            link.href = "https://www.youtube.com/watch?v=" + word;
                            link.target="_blank"

                            // 设置<a>标签的文本为单词
                            link.textContent = word;

                            // 将<a>标签添加到结果数组中
                            youtuberesult.push(link);
                        }
                    });
                }
            }
        });

        const activityBtn = document.querySelector('#info > .wp-content > .activity-btn');
        youtuberesult.forEach((link) => {
            activityBtn.parentNode.insertBefore(link, activityBtn);
        });



        addBlacklistButtonToComments();
        blockLinks();
    };

    // 监听页面刷新事件,在刷新时保留黑名单列表
    window.addEventListener('beforeunload', () => {
        localStorage.setItem('blacklist', JSON.stringify(blacklist));
    });
})();