thedesk/app/js/post/post.js

307 lines
7.5 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
/*投稿系*/
//投稿
2018-09-17 21:55:00 +10:00
function sec(){
var mode=localStorage.getItem("sec");
var acct_id = $("#post-acct-sel").val();
var domain = localStorage.getItem("domain_" + acct_id);
if(~domain.indexOf("kirishima.cloud")>=0 && mode=="local"){
mode="unlisted";
}
post(null,mode);
}
function post(mode,postvis) {
2018-05-20 16:17:10 +10:00
if($("#toot-post-btn").prop("disabled")){
2019-03-08 05:19:26 +11:00
return false;
2018-05-20 16:17:10 +10:00
}
2018-01-28 23:22:43 +11:00
var str = $("#textarea").val();
var acct_id = $("#post-acct-sel").val();
localStorage.setItem("last-use", acct_id);
var domain = localStorage.getItem("domain_" + acct_id);
2018-06-18 00:26:45 +10:00
if(domain=="theboss.tech"){
if(~str.indexOf("#")){
if(str.indexOf("#theboss_tech")=="-1"){
2019-01-26 14:24:26 +11:00
if(!confirm(lang.lang_post_tagTL)){
2018-06-18 00:26:45 +10:00
return false;
}
}
}
}
if(domain=="dtp-mstdn.jp"){
if(~str.indexOf("#")){
if(str.indexOf("#dtp")=="-1"){
2019-01-26 14:24:26 +11:00
if(!confirm(lang.lang_post_tagTL)){
2018-06-18 00:26:45 +10:00
return false;
}
}
}
}
2018-08-24 01:15:57 +10:00
if(!localStorage.getItem("cw_sentence")){
var cw_sent=500;
}else{
var cw_sent=localStorage.getItem("cw_sentence");
}
if(!localStorage.getItem("cw_letters")){
var cw_ltres=500;
}else{
var cw_ltres=localStorage.getItem("cw_letters");
}
if(mode!="pass" && !$("#cw").hasClass("cw-avail") && (str.length>cw_sent || (str.split("\n").length - 1)>cw_ltres)){
2018-08-23 03:29:39 +10:00
var electron = require("electron");
var remote=electron.remote;
var dialog=remote.dialog;
var plus=str.replace(/\n/g,"").slice(0,10)+"...";
const options = {
type: 'info',
2019-01-26 14:24:26 +11:00
title: lang.lang_post_cwtitle,
message: lang.lang_post_cwtxt+plus,
buttons: [lang.lang_post_btn1,lang.lang_post_btn2, lang.lang_post_btn3]
2019-03-06 19:08:48 +11:00
}
dialog.showMessageBox(options, function(arg) {
2019-03-08 05:19:26 +11:00
if(arg===1){
2018-08-23 03:29:39 +10:00
$("#cw-text").show();
$("#cw").addClass("yellow-text");
$("#cw").addClass("cw-avail");
$("#cw-text").val(plus);
post("pass");
2019-03-08 05:19:26 +11:00
}else if(arg===2){
2018-08-23 03:29:39 +10:00
post("pass");
}
})
return false;
}
if(localStorage.getItem("mode_" + domain)=="misskey"){
2018-07-30 21:03:49 +10:00
misskeyPost();
return;
}
2018-09-19 02:41:48 +10:00
$(".toot-btn-group").prop("disabled", true);
2018-06-18 00:26:45 +10:00
todo("Posting");
2018-07-07 03:51:48 +10:00
var at = localStorage.getItem("acct_"+ acct_id + "_at");
2018-01-28 23:22:43 +11:00
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";
}
2018-09-17 21:55:00 +10:00
if(postvis){
var vis = postvis;
}else{
var vis = $("#vis").text();
}
2018-09-06 02:47:27 +10:00
if(vis!="inherit" && vis!="local"){
2018-03-20 15:55:25 +11:00
toot.visibility=vis;
2018-09-06 02:47:27 +10:00
}else if(vis=="local"){
toot.status=str+"👁️";
2018-03-20 15:55:25 +11:00
}
2019-01-22 03:25:40 +11:00
//ここに非公開・未収載タグについてwarn
if(~str.indexOf("#")){
if(vis == "local" || vis=="unlisted" || vis=="direct" || vis=="private"){
2019-01-26 14:24:26 +11:00
if(!confirm(lang.lang_post_tagVis)){
2019-01-22 03:25:40 +11:00
return false;
}
}
}
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 = "";
}
2019-01-22 03:25:40 +11:00
if ($("#sch-box").hasClass("sch-avail")) {
var scheduled=formattimeutc(new Date(Date.parse($("#sch-date").val())))
2019-03-06 19:08:48 +11:00
console.log(scheduled)
2019-01-22 03:25:40 +11:00
schedule();
toot.scheduled_at=scheduled;
} else {
var scheduled = "";
}
2019-03-06 19:08:48 +11:00
if ($("#poll-sel").val()=="mastodon-poll") {
var options=[];
$(".mastodon-choice").map(function() {
var choice=$(this).val();
if(choice!=""){
options.push(choice);
}
});
if($("#poll-multiple:checked").val()=="1"){
var mul=true;
}else{
var mul=false;
}
2019-03-06 22:56:39 +11:00
if($("#poll-until:checked").val()=="1"){
var htt=true;
}else{
var htt=false;
}
2019-03-06 19:08:48 +11:00
var exin=pollCalc();
if(!exin){
todc("Error: Poll expires_in param")
}
toot.poll={
options: options,
expires_in: exin,
2019-03-06 22:56:39 +11:00
multiple: mul,
hide_totals: htt
2019-03-06 19:08:48 +11:00
}
}
console.log(toot);
2018-04-17 03:10:35 +10:00
var httpreq = new XMLHttpRequest();
httpreq.open('POST', start, true);
httpreq.setRequestHeader('Content-Type', 'application/json');
httpreq.setRequestHeader('Authorization', 'Bearer ' + at);
2019-03-08 05:19:26 +11:00
httpreq.responseType = "json";
2018-04-17 03:10:35 +10:00
httpreq.send(JSON.stringify(toot));
httpreq.onreadystatechange = function() {
2019-03-08 05:19:26 +11:00
if (httpreq.readyState === 4) {
2018-07-28 07:25:12 +10:00
if(str.indexOf(localStorage.getItem("stable"))==-1){
localStorage.removeItem("stable")
}
2018-04-17 03:10:35 +10:00
var json = httpreq.response;
console.log(json);
var box = localStorage.getItem("box");
2018-08-11 01:58:00 +10:00
if (box == "yes" || !box) {
$("#textarea").blur();
2018-04-17 03:10:35 +10:00
hide();
}
2018-09-19 02:41:48 +10:00
$(".toot-btn-group").prop("disabled", false);
2018-04-17 03:10:35 +10:00
todc();
clear();
2018-01-28 23:22:43 +11:00
}
2018-04-17 03:10:35 +10:00
}
2018-01-28 23:22:43 +11:00
}
2018-07-30 21:03:49 +10:00
function misskeyPost(){
var str = $("#textarea").val();
var acct_id = $("#post-acct-sel").val();
localStorage.setItem("last-use", acct_id);
2018-08-23 03:29:39 +10:00
var domain = localStorage.getItem("domain_" + acct_id);
2018-09-19 02:41:48 +10:00
$(".toot-btn-group").prop("disabled", true);
2018-07-30 21:03:49 +10:00
todo("Posting");
var at = localStorage.getItem("acct_"+ acct_id + "_at");
var start = "https://" + domain + "/api/notes/create";
var reply = $("#reply").val();
var toot={
text: str
}
if(reply){
if(reply.indexOf("renote")!== -1){
toot.renoteId=reply.replace("renote_","")
}else{
toot.replyId=reply
}
}
var media = $("#media").val();
if(media){
toot.mediaIds=media.split(",");
}
if ($("#nsfw").hasClass("nsfw-avail")) {
var nsfw = "true";
toot.sensitive=nsfw;
} else {
var nsfw = "false";
}
var vis = $("#vis").text();
if(vis=="unlisted"){
vis=="home"
}else if(vis=="direct"){
vis=="specified";
toot.visibleUserIds=str.match(/@([a-zA-Z0-9_@.-]+)(\s|$)/g).join('').split("@");
}
if(vis!="inherit"){
toot.visibility=vis;
}
if ($("#cw").hasClass("cw-avail")) {
var spo = $("#cw-text").val();
cw();
toot.cw=spo;
} else {
var spo = "";
}
toot.i=at;
var httpreq = new XMLHttpRequest();
httpreq.open('POST', start, true);
httpreq.setRequestHeader('Content-Type', 'application/json');
2019-03-08 05:19:26 +11:00
httpreq.responseType = "json";
2018-07-30 21:03:49 +10:00
httpreq.send(JSON.stringify(toot));
httpreq.onreadystatechange = function() {
2019-03-08 05:19:26 +11:00
if (httpreq.readyState === 4) {
2018-07-30 21:03:49 +10:00
if(str.indexOf(localStorage.getItem("stable"))==-1){
localStorage.removeItem("stable")
}
var json = httpreq.response;
console.log(json);
var box = localStorage.getItem("box");
if (box == "yes") {
hide();
}else if (box == "hide"){
$("body").addClass("mini-post");
$(".mini-btn").text("expand_less");
}
2018-09-19 02:41:48 +10:00
$(".toot-btn-group").prop("disabled", false);
2018-07-30 21:03:49 +10:00
todc();
clear();
}
}
}
2018-01-28 23:22:43 +11:00
//クリア(Shift+C)
function clear() {
$("#textarea").val("");
2018-07-28 07:25:12 +10:00
if(localStorage.getItem("stable")){
$("#textarea").val(localStorage.getItem("stable"));
}
2019-01-26 14:24:26 +11:00
$("#textarea").attr("placeholder", lang.lang_toot);
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("");
}
2018-08-05 13:36:23 +10:00
var acw = localStorage.getItem("always-cw");
if (acw != "yes") {
$("#cw").removeClass("yellow-text");
$("#cw").removeClass("cw-avail");
$("#cw-text").hide();
}else{
$("#cw").addClass("yellow-text");
$("#cw").addClass("cw-avail");
$("#cw-text").show();
}
2019-01-26 14:24:26 +11:00
$("#rec").text(lang.lang_no);
$("#mec").text(lang.lang_nothing);
2018-06-18 00:26:45 +10:00
loadVis();
2018-05-02 14:14:03 +10:00
$("#nsfw").removeClass("yellow-text");
$("#nsfw").html("visibility_off");
2018-01-28 23:22:43 +11:00
$("#nsfw").removeClass("nsfw-avail");
2019-01-26 14:24:26 +11:00
$("#nsc").text(lang.lang_nothing);
2018-01-28 23:22:43 +11:00
$("#drag").css("background-color", "#e0e0e0");
$("#preview").html("");
2018-09-19 02:41:48 +10:00
$(".toot-btn-group").prop("disabled", false);
2018-02-24 03:02:44 +11:00
$("#post-acct-sel").prop("disabled", false);
2019-03-06 19:08:48 +11:00
$("#days_poll").val(0);
$("#hours_poll").val(0);
$("#mins_poll").val(0);
$(".mastodon-choice").map(function() {
$(this).val("");
});
2018-02-19 04:41:25 +11:00
localStorage.removeItem("image");
2018-05-20 16:17:10 +10:00
if(localStorage.getItem("mainuse")=="main"){
2018-07-30 21:03:49 +10:00
$("#post-acct-sel").val(localStorage.getItem("main"));
2018-05-20 16:17:10 +10:00
}
2018-07-30 21:03:49 +10:00
$('select').material_select();
2018-03-27 13:39:35 +11:00
}