我正在尝试为 twitter 做一个扩展,我被困在本节中插入 div 块(有点像 btn)
清单.json
{
"manifest_version": 3,
"name": "Twitter Saver",
"version": "0.0.1",
"description": "Twitter Saver| Save tweets.",
"permissions": ["tabs", "https://*.twitter.com/*"],
"icons": {
"128": "img/icon-app-128.png",
"256": "img/icon-app-128@2x.png"
},
"content_scripts": [
{
"html": ["save-dropdown.html"],
"js": ["js/jquery-3.6.0.min.js", "js/content.js"],
"matches": ["https://*.twitter.com/*"]
}
]
}
内容.js
$(
"<div>",{
class: "css-1dbjc4n r-18u37iz r-1h0z5md",
text: "HELLO WORLD"
}
).appendTo(".css-1dbjc4n.r-1ta3fxp.r-18u37iz.r-1wtj0ep.r-1s2bzr4.r-1mdbhws");
我研究了一些像MutationObserver这样的东西, 但在这里我得到了错误,因为参数不是节点
let react_root = $("#react-root");
let callback = function(changeList, observer) => {
console.log(changeList);
}
const observer = new MutationObserver();
observer.observe(callback, {childList: true});
Twitter在向下滚动时删除以前的帖子添加新帖子,并在滚动回顶部时添加以前的帖子删除新帖子