方案二:不弄延时,而是做一个按钮,点击才做替换操作。
最新见 44#,这里就不改了,留个印。
网上搜索到创建悬浮按钮的方法 https://blog.csdn.net/qq_41298974/article/details/108434838,学习完引入这里,变成:
// ==UserScript==
// @name zihu_ltx_cpy
// @namespace http://tampermonkey.net/
// @version 0.4
// @description for zihu ltx cpy
// @author kk
// @match https://www.zhihu.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
//按钮部分来自https://blog.csdn.net/qq_41298974/article/details/108434838
var mybutton,beasetag;
mybutton = document.createElement("div");
beasetag = document.querySelector("body");
beasetag.appendChild(mybutton);
mybutton.innerHTML = "$代码$";
mybutton.style = "position:fixed;bottom:30px;left:30px;width:100px;height:100px;background:black;opacity:0.5;color:white;text-align:center;line-height:100px;cursor:pointer;";
mybutton.onclick = function(){
let classDom = document.getElementsByClassName('RichContent-inner');
for (let item of classDom)
{
item.innerHTML = item.innerHTML.replace(/ loading="lazy"/g,'').replace(/alt="\[公式\]" eeimg="1" data-formula="([^"]+)"/g,'eeimg="1" alt="$$$1$"');
};
let classDom2 = document.getElementsByClassName('QuestionRichText QuestionRichText--expandable');
for (let item of classDom2)
{
item.innerHTML = item.innerHTML.replace(/ loading="lazy"/g,'').replace(/alt="\[公式\]" eeimg="1" data-formula="([^"]+)"/g,'eeimg="1" alt="$$$1$"');
};
};
})();
这样的话,就可以等网页加载完再点按钮,不用担心长帖子 7 秒够不够的问题。
对于自己的回答列表,也可以全部展开内容再点按钮,就可以一次过复制一堆,这是之前做不到的,所以这次网址就不限于 question 了。 |