Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
if(op.attributes.exists("type") && op.attributes.getOne("type")=="outline"){
var wp_post = opml.parse(op.getCursorOpml());
var title = wp_post.opml.head.title;
var text = "";
var imagepart="";
for (i=0;i<wp_post.opml.body.subs[0].subs.length;i++){
if(wp_post.opml.body.subs[0].subs[i].image !==undefined){
var imagepart="<p><img src='"+wp_post.opml.body.subs[0].subs[i].image+"'></p>";
text=text+imagepart;
}
if(wp_post.opml.body.subs[0].subs[i].inlineImage !==undefined){
var imagepart="<p><img src='"+wp_post.opml.body.subs[0].subs[i].inlineImage+"'></p>";
text=text+imagepart;
}
var textpart= "<p>"+wp_post.opml.body.subs[0].subs[i].text+"</p>";
text=text+textpart;
}
var data =
{
"action": "create_post",
"title": title,
"content": text,
"status": "draft",
"categories": 14,
}
var url = root.env.endpoint;
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Authorization", "Basic " + btoa(root.env.basic));
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responstext);
var returndata = JSON.parse(xhr.responseText);
op.attributes.setOne("wp_postid",returndata.id)
clock.waitSeconds(2);
webBrowser.openUrl(returndata.link);
}
};
xhr.send(JSON.stringify(data));
}else{
dialog.alert("You\'re on the wrong level");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment