百度知道baiduzhidao去除复制答案的垃圾文字,自动展开答案

展开百度知道答案,去除答案里面各种垃圾文字,方便复制

目前為 2021-04-22 提交的版本,檢視 最新版本

// ==UserScript==
// @name         百度知道baiduzhidao去除复制答案的垃圾文字,自动展开答案
// @namespace    http://tampermonkey.net/
// @version      0.3.1
// @description  展开百度知道答案,去除答案里面各种垃圾文字,方便复制
// @author       jeterlee
// @match        https://zhidao.baidu.com/question/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    setTimeout(function () {
        var e = document.createEvent("MouseEvents");
        e.initEvent("click", true, true);
        var zhankai = document.getElementsByClassName('wgt-answers-showbtn');
        for (var ii = 0; ii < zhankai.length; ii++) {
            zhankai[ii].dispatchEvent(e);
        }
        document.getElementById("show-answer-hide").dispatchEvent(e);
        document.getElementsByClassName('wgt-best-showbtn')[0].dispatchEvent(e);
        var spanList = document.getElementById('qb-content').getElementsByTagName('span');
        var sumAtt = 0;
        for (var i = 0; i < spanList.length; i++) {
            if (spanList[i].offsetHeight <= 1) { //判定垃圾文字容器
                spanList[i].innerHTML = '';
                spanList[i].remove(); //删除垃圾文字
                sumAtt++;
            }
        }
        console.log('发现垃圾文字' + sumAtt + '个,已处理');
    }, 1600);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址