thedesk/app/js/post/post.js

103 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
/*投稿系*/
//投稿
function post() {
var str = $("#textarea").val();
var acct_id = $("#post-acct-sel").val();
localStorage.setItem("last-use", acct_id);
todo("Posting");
var domain = localStorage.getItem("domain_" + acct_id);
var at = localStorage.getItem(domain + "_at");
var start = "https://" + domain + "/api/v1/statuses";
var reply = $("#reply").val();
2018-03-20 15:55:25 +11:00
var toot={
status: str
}
if(reply){
toot.in_reply_to_id=reply
}
2018-01-28 23:22:43 +11:00
var media = $("#media").val();
2018-03-20 15:55:25 +11:00
if(media){
2018-03-27 13:39:35 +11:00
toot.media_ids=media.split(",");
2018-03-20 15:55:25 +11:00
}
2018-01-28 23:22:43 +11:00
if ($("#nsfw").hasClass("nsfw-avail")) {
var nsfw = "true";
2018-03-20 15:55:25 +11:00
toot.sensitive=nsfw;
2018-01-28 23:22:43 +11:00
} else {
var nsfw = "false";
}
var vis = $("#vis").text();
2018-03-21 16:36:02 +11:00
if(vis!="inherit"){
2018-03-20 15:55:25 +11:00
toot.visibility=vis;
}
2018-01-28 23:22:43 +11:00
if ($("#cw").hasClass("cw-avail")) {
var spo = $("#cw-text").val();
2018-03-14 05:31:31 +11:00
cw();
2018-03-20 15:55:25 +11:00
toot.spoiler_text=spo;
2018-01-28 23:22:43 +11:00
} else {
var spo = "";
}
fetch(start, {
method: 'POST',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + at
},
2018-03-20 15:55:25 +11:00
body: JSON.stringify(toot)
2018-01-28 23:22:43 +11:00
}).then(function(response) {
return response.json();
}).catch(function(error) {
todo(error);
console.error(error);
}).then(function(json) {
console.log(json);
var box = localStorage.getItem("box");
if (box == "yes") {
hide();
2018-02-24 03:02:44 +11:00
}else if (box == "hide"){
2018-02-25 02:59:53 +11:00
$("body").addClass("mini-post");
$(".mini-btn").text("expand_less");
2018-01-28 23:22:43 +11:00
}
todc();
clear();
});
}
//クリア(Shift+C)
function clear() {
$("#textarea").val("");
2018-02-24 03:02:44 +11:00
$("#textarea").attr("placeholder", "");
2018-01-28 23:22:43 +11:00
$("#reply").val("");
$("#media").val("");
var cwt = localStorage.getItem("cw-text");
if (cwt) {
$("#cw-text").val(cwt);
} else {
$("#cw-text").val("");
}
$("#cw").addClass("blue");
$("#cw").removeClass("yellow");
$("#cw").removeClass("cw-avail");
$("#rec").text("いいえ");
$("#mec").text("なし");
2018-03-14 17:52:55 +11:00
var vist = localStorage.getItem("vis");
if (!vist) {
vis("public");
2018-01-28 23:22:43 +11:00
} else {
2018-03-14 17:52:55 +11:00
if (vist == "memory") {
2018-01-28 23:22:43 +11:00
localStorage.setItem("vis-memory", $("#vis").text());
} else {
2018-03-14 17:52:55 +11:00
vis(vist);
2018-01-28 23:22:43 +11:00
}
}
$("#nsfw").addClass("blue");
$("#nsfw").removeClass("yellow");
$("#nsi").html("lock_open");
$("#nsfw").removeClass("nsfw-avail");
$("#nsc").text("なし");
$("#drag").css("background-color", "#e0e0e0");
$("#preview").html("");
2018-02-19 04:41:25 +11:00
$("#toot-post-btn").prop("disabled", false);
2018-02-24 03:02:44 +11:00
$("#post-acct-sel").prop("disabled", false);
$('select').material_select();
2018-02-19 04:41:25 +11:00
localStorage.removeItem("image");
2018-03-27 13:39:35 +11:00
}