I would like some help with a Tampermonkey script.
I have a script that will add a button to the page and on click, it will add some text to a text area. That part is working fine. See below.
Now, I need that on click of this button, before it adds the text, I need it to check a checkbox ID="1234"
Please assist.
(function() {
window.addEventListener("load", () => {
addButton("Add Markdown");
});
function addButton(text, onclick, cssObj) {
cssObj = cssObj || {
position: "fixed",
top: "15%",
right: "4%",
"z-index": 3,
fontWeight: "600",
fontSize: "14px",
backgroundColor: "#00cccc",
color: "white",
border: "none",
padding: "10px 20px"
};
let button = document.createElement("button"),
btnStyle = button.style;
document.body.appendChild(button);
button.innerHTML = text;
// Setting function for button when it is clicked.
button.onclick = selectReadFn;
Object.keys(cssObj).forEach(key => (btnStyle[key] = cssObj[key]));
return button;
}
function selectReadFn() {
var txt = document.getElementById("markdown-editor").value += '\n---\n```markdown text here.\n```\n\n'
}
})();
I couldn't find a script that will check a checkbox with the click of another button
Aucun commentaire:
Enregistrer un commentaire