Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Last active July 3, 2023 13:22
Show Gist options
  • Save jpluimers/6b526a86f207fc31ee58f8d91562bb9c to your computer and use it in GitHub Desktop.
Save jpluimers/6b526a86f207fc31ee58f8d91562bb9c to your computer and use it in GitHub Desktop.
JavaScript Bookmarklet for the WordPress classic editor which enables mastodon publishing (assuming you have at least one mastodon publishing account enabled under https://jetpack.com/redirect/?source=jetpack-social-connections-classic-editor / https://wordpress.com/marketing/connections/)
javascript:(function(){
publicizeFormEditHref = document.getElementById('publicize-form-edit'); // "edit" href
if(publicizeFormEditHref) {
publicizeFormEditHref.click();
}
mastodonCheckboxes = document.getElementsByClassName('wpas-submit-mastodon'); // any Mastodon checkboxes (one can have zero or more accounts configured)
Array.from(mastodonCheckboxes).forEach((mastodonCheckbox) => {
mastodonCheckbox.checked = true;
});
publicizeFormHideHref = document.getElementById('publicize-form-hide'); // "OK" button disguised as href
if (publicizeFormHideHref) {
publicizeFormHideHref.click();
}
savePostButton = document.getElementById('save-post'); // button exists when post has status "draft"
if (savePostButton) {
savePostButton.click();
}
else {
updateButton = document.getElementById('publish'); // button exists when post has status "draft", "scheduled", or "published"; when "draft" a click() will either "schedule" or "publish" depending on the schedule timestamp being in the future or past
if (updateButton) {
updateButton.click();
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment