I am making a chrome extension that changes the formatting of suggestions on an internal CMS our school newspaper uses. I made a context menu option that, when clicked, will perform the formatting change. However, when the context menu is clicked, nothing happens.
1) I have checked that my code for makeVisible works on the javascript console in Chrome.
2) I have made sure the function makeVisible is never called because the console.log("Test") never happens.
3) I have tried switching the plugin to another website besides superdesk.thetriangle.org, still doesn't work.
4) Tried making the background.js script persistent and using the onclick attribute of chrome.contextMenus.create(). Same thing there, onclick never fires.
manifest.json:
{
"name": "Find Hidden Suggestions",
"version": "1.0",
"description": "Highlights hidden suggestions in Superdesk's editor.",
"manifest_version": 2,
"permissions": ["*://superdesk.thetriangle.org/*", "contextMenus"],
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
background.js:
function makeVisible(info, tab) {
console.log("Test");
var spansAdd = document.querySelectorAll("span[style='color: rgb(0, 180, 0);']");
var spansDel = document.querySelectorAll("span[style='color: rgb(255, 0, 0); text-decoration: line-through;']");
spansAdd.forEach((ele) => {
ele.setAttribute("style", "color: green; border-bottom: 2px solid green;");
});
spansDel.forEach((ele) => {
ele.setAttribute("style", "color: rgb(255, 0, 0); text-decoration: line-through; border-bottom: 2px solid red");
});
}
chrome.contextMenus.create({
id: "Suggestions command",
title: "Make Suggestions Visible",
contexts: ["all"],
});
chrome.contextMenus.onClicked.addListener(makeVisible);
At this point, I am at a loss as to why a click on the contextMenu is not working.