Hi all. I'm having a hell of a time trying to insert text into an HTML textarea, or grab data from the clipboard with a Chrome extension (using a context menu). My elementary javascript skills almost seem not to apply once thrown into a Chrome extension. I currently have these permissions in my manifest.json file:It seems like document.execCode('paste') and setting up a listener might be the way to go, but it looks like security issues prevent direct paste, and I'm confused by syntax and what code goes where. Programatically this is what I'd imagine the function would do:Code:"permissions": [ "contextMenus", "clipboardRead", "clipboardWrite"],So if the textarea contained:
- Get the selected string in the current textarea and copy to a variable "orig_str".
- If a string, get the current clipboard and store it in a variable "clip_str". If not, set variable to nothing.
- Overwrite the original selected string in the current textarea with "orig_str + clip_str".
and the clipboard contained:Code:I eat peasand the user selected "eat", then the function was activated, the string in the textarea would be changed to read:Code:and cookAny help down the right path would be appreciated, preferably with straight JS rather than JQuery. My code as it exists can be found here.Code:I eat and cook peas


LinkBack URL
About LinkBacks



Reply With Quote
