MyBB Community Forums

Full Version: auto copy to clipboard in edit
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using notemoderator plugin. Which is basically the edit feature of a mybb post. So it is only shown to admins or mods.

I am trying to make a button in which copies text to your clipboard. This is because note moderator adds a mod note at the bottom of the users post (things like use BBCode, wrong forum, mark thread as solved, etc) are common things we use note moderator for. So i want to create a button in which copies the text to the users clipboard to post in there, so we dont have to write it every time. And so it is consistent every time.

The problem is in jsfiddle this works as expected. But in mybb, it executes the post like you hit the button "update post" instead. Can anyone help determine why this is and how to go around it? I mean in terms of the plugin is not relatable, because i could do the same thing in edit page, which has nothing to do with the plguin. So this is a mybb thing, not a plugin thing.

EDIT:
I have figured out that i can override the paste text via:

var pasteEvent = new ClipboardEvent('paste');
pasteEvent.clipboardData.items.add('My string', 'text/plain');
document.dispatchEvent(pasteEvent);


// Overwrite what is being copied to the clipboard.
document.addEventListener('copy', function(e) {
  // e.clipboardData is initially empty, but we can set it to the
  // data that we want copied onto the clipboard.
  e.clipboardData.setData('text/plain', 'CONTENT1');


  // This is necessary to prevent the current document selection from
  // being written to the clipboard.
  e.preventDefault();
});
but i cant figure out how to assign the text based on different buttons? For example if button 1 said CONTENT 1, and button 2 said CONTENT 2 and so on and so on.


EDIT2:
I have also been trying to make a button to insert text straight into the textarea with ID notemoderator. In jsfiddle, this works perfect again. But in MyBB it does not. I have tried numerous methods, such as replacing the value of the textarea, to no avail. THe only way i can modify the textarea is this code in script tag

var paragraph = document.getElementById("notemoderator");
var text = document.createTextNode("test");
paragraph.appendChild(text);
But i cant seem to assign a button to a function to change the text on a per button basis. Anything else it seems to completely ignore common javascript usage.