快手元素插入问题求助
在快手作者个人页面插入元素总会出现目标元素为空,但是我在控制输入查找目标元素的代码可以找得到呀,请问这怎么解决?个人代码:
```
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @descriptiontry to take over the world!
// @author You
// @match https://www.kuaishou.com/profile/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=kuaishou.com
// @grant none
// @run-at document-start
// ==/UserScript==
let getVedioBtn = document.createElement("button")
getVedioBtn.innerText = "复制视频"
getVedioBtn.className = "getVedio"
getVedioBtn.style.background = "#757575";
getVedioBtn.style.color = "#fff";
let ops = document.querySelector(".follow-button.user-info-follow");
ops.addEventListener("DOMNodeInserted", function (event) {
ops.insertAdjacentElement("afterend", getVedioBtn)
})
```
(问题下图)
!(data/attachment/forum/202310/09/230719wcrqvqvxrn4axzxv.png)
!(data/attachment/forum/202310/09/230803esr4zsmsi4qu402m.png)
李恒道 发表于 2023-10-9 23:51
https://learn.scriptcat.org/docs/question/%E5%B8%B8%E8%A7%81%E8%AF%AF%E5%8C%BA/
基础不牢,地动山摇{:4_115:}
解答:
let timer = setInterval(() => {
if (document.querySelector(".follow-button.user-info-follow") !== null) {
let target = document.querySelector(".follow-button.user-info-follow");
//找到了定时器
target.insertAdjacentElement("afterend", getVedioBtn)
clearInterval(timer);
}
}, 1000);
https://learn.scriptcat.org/docs/question/%E5%B8%B8%E8%A7%81%E8%AF%AF%E5%8C%BA/
页:
[1]