I am trying to remove an element For this purpose I am trying to make small plug in in .js I have tailored this to this one specific google form I want to use it at, and for some reason I am haveing more issues in docs.google.com than I have in other websites
// content.js
const element = document.getElementsByClassName("xxxxxx");
element[0].remove();
xxx” 是持有电子邮件显示器的组群,I ve在这里做了改动,如果能够把电子邮件带上<>。
When I paste the code in the console manually it works as I want it , but if I run it by plug in it gives me an error code: "Uncaught TypeError: Cannot read Properties of undefined (reading remove )"
Edit: Upon request the manifest.json and the timer, I bet theres also a better way to do it
//manifest.json
{
"manifest_version": 3,
"name": "Auto Delete xxxxxx Elements",
"version": "1.0",
"description": "A Chrome extension to automatically delete elements containing the class xxxxxx on doc.google.com.",
"permissions": ["activeTab"],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["*://docs.google.com/*"],
"js": ["content.js"]
}
]
}
// background.js
chrome.runtime.onInstalled.addListener(() => {
setInterval(() => {
chrome.tabs.query({ url: "*://docs.google.com/*" }, tabs => {
tabs.forEach(tab => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: [ content.js ]
});
});
});
}, 1000); // 1000 milliseconds = 1 second
});