方案二:不弄延时,而是做一个按钮,点击才做替换操作。
网上搜索到创建悬浮按钮的方法 https://blog.csdn.net/qq_41298974/article/details/108434838 ,学习完引入这里,变成:
// ==UserScript==
// @name zihu_ltx_cpy
// @namespace http://tampermonkey.net/
// @version 0.2
// @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 = "alt=`代码`";
mybutton.style = "position:fixed;bottom:50px;left:50px;width:100px;height:100px;background:black;opacity:0.5;color:white;text-align:center;line-height:100px;cursor:pointer;";
mybutton.onclick = function(){
var j,temp;
var classDom = document.getElementsByClassName('RichContent-inner');
for (j = 0; j < classDom.length; j++)
{
temp = classDom[j].innerHTML;
temp = temp.replace(/alt="\[公式\]" eeimg="1" data-formula="([^"]+)"/g,'eeimg="1" alt="`$1`"');
classDom[j].innerHTML = temp;
}
};
})();
这样的话,就可以等网页加载完再点按钮,不用担心长帖子 7 秒够不够的问题。
对于自己的回答列表,也可以全部展开内容再点按钮,就可以一次过复制一堆,这是之前做不到的,所以这次网址就不限于 question 了。 |