I'm trying to revive Astro CB's auto edit corrections script. I've got a lot of it updated, improved, and working with Stack Exchange changes since 2015.
One thing that stuck on is setting the markdown from the new StackApps WYSIWYG editor that is currently used for answers on the meta sites. I can find the element in the page and gets its markdown with jQuery:
$('.post-editor .markdown').text()
However, I haven't figured out how to set the markdown back into the editor after modifying it. I have found the following that looks promising:
StackExchange.stacksEditor.getInstanceFromElement($('.post-editor'))
But when I run it I get:
Uncaught TypeError:
t.dataset
is undefined
l https://meta.stackexchange.com/Content/Js/stacks-editor.en.js?v=209d11c01c46:1
I've also tried using [0]
after the jQuery selector in case the editor expects plain JavaScript objects. However this gives the same error:
StackExchange.stacksEditor.getInstanceFromElement($('.post-editor')[0])
I found another user script that wraps something like that in using
, but I get the same result with:
StackExchange.using("stacksEditor",function(){StackExchange.stacksEditor.getInstanceFromElement($('.post-editor'))})
How do I get access to the StacksEditor from a user script so that I can set the markdown after editing it automatically?