2019-05-19 17:39:30 +10:00
|
|
|
/*投稿系*/
|
2018-01-28 23:22:43 +11:00
|
|
|
//投稿
|
2019-05-19 17:39:30 +10:00
|
|
|
function sec() {
|
2019-11-09 00:52:54 +11:00
|
|
|
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'
|
2018-09-17 21:55:00 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
post(null, mode)
|
2018-09-17 21:55:00 +10:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
function post(mode, postvis) {
|
2019-11-09 00:52:54 +11:00
|
|
|
if ($('#toot-post-btn').prop('disabled')) {
|
|
|
|
return false
|
2018-05-20 16:17:10 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +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)
|
2019-11-28 01:03:18 +11:00
|
|
|
if ($('#ideKey').val() != '') {
|
|
|
|
var ideKey = $('#ideKey').val()
|
|
|
|
} else {
|
|
|
|
var user = localStorage.getItem('user_' + acct_id)
|
|
|
|
var ideKey = Math.floor(Date.now() / 1000) + '/TheDesk/' + user + '@' + domain
|
|
|
|
$('#ideKey').val(ideKey)
|
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if (!localStorage.getItem('cw_sentence')) {
|
|
|
|
var cw_sent = 500
|
2019-05-19 17:39:30 +10:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
var cw_sent = localStorage.getItem('cw_sentence')
|
2019-05-19 17:39:30 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if (!localStorage.getItem('cw_letters')) {
|
|
|
|
var cw_ltres = 7000
|
2019-05-19 17:39:30 +10:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
var cw_ltres = localStorage.getItem('cw_letters')
|
2019-05-19 17:39:30 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if (domain != 'kirishima.cloud') {
|
|
|
|
if (
|
|
|
|
mode != 'pass' &&
|
|
|
|
!$('#cw').hasClass('cw-avail') &&
|
|
|
|
(str.length > cw_sent || str.split('\n').length - 1 > cw_ltres)
|
|
|
|
) {
|
|
|
|
var plus = str.replace(/\n/g, '').slice(0, 10) + '...'
|
2019-06-26 01:33:20 +10:00
|
|
|
Swal.fire({
|
2019-05-19 17:39:30 +10:00
|
|
|
title: lang.lang_post_cwtitle,
|
2019-06-26 01:33:20 +10:00
|
|
|
text: lang.lang_post_cwtxt + plus,
|
|
|
|
type: 'info',
|
|
|
|
showCancelButton: true,
|
|
|
|
confirmButtonColor: '#3085d6',
|
|
|
|
cancelButtonColor: '#3085d6',
|
|
|
|
confirmButtonText: lang.lang_post_btn2,
|
|
|
|
cancelButtonText: lang.lang_post_btn3,
|
|
|
|
showCloseButton: true,
|
2019-11-09 00:52:54 +11:00
|
|
|
focusConfirm: false
|
|
|
|
}).then(result => {
|
|
|
|
if (result.dismiss == 'cancel') {
|
2019-06-26 01:33:20 +10:00
|
|
|
//btn3:sonomama
|
2019-11-09 00:52:54 +11:00
|
|
|
post('pass')
|
2019-06-26 01:33:20 +10:00
|
|
|
} else if (result.value) {
|
|
|
|
//btn2:auto-CW
|
2019-11-09 00:52:54 +11:00
|
|
|
$('#cw-text').show()
|
|
|
|
$('#cw').addClass('yellow-text')
|
|
|
|
$('#cw').addClass('cw-avail')
|
|
|
|
$('#cw-text').val(plus)
|
|
|
|
post('pass')
|
2019-06-26 01:33:20 +10:00
|
|
|
}
|
|
|
|
})
|
2019-11-09 00:52:54 +11:00
|
|
|
return false
|
2019-05-19 17:39:30 +10:00
|
|
|
}
|
2018-08-23 03:29:39 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if (localStorage.getItem('mode_' + domain) == 'misskey') {
|
|
|
|
misskeyPost()
|
|
|
|
return
|
2018-07-30 21:03:49 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
$('.toot-btn-group').prop('disabled', true)
|
|
|
|
todo('Posting')
|
|
|
|
var at = localStorage.getItem('acct_' + acct_id + '_at')
|
|
|
|
var start = 'https://' + domain + '/api/v1/statuses'
|
|
|
|
var reply = $('#reply').val()
|
|
|
|
if (str.indexOf(localStorage.getItem('stable')) == -1) {
|
|
|
|
str + ' #' + localStorage.getItem('stable')
|
2019-03-13 02:51:07 +11:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
var toot = {
|
2018-03-20 15:55:25 +11:00
|
|
|
status: str
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
if (reply) {
|
|
|
|
toot.in_reply_to_id = reply
|
2018-03-20 15:55:25 +11:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
var media = $('#media').val()
|
2019-05-19 17:39:30 +10:00
|
|
|
if (media) {
|
2019-11-09 00:52:54 +11:00
|
|
|
toot.media_ids = media.split(',')
|
2018-03-20 15:55:25 +11:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
var quote = $('#quote').val()
|
2019-09-08 02:33:01 +10:00
|
|
|
if (quote) {
|
2019-11-09 00:52:54 +11:00
|
|
|
toot.quote_id = quote
|
2019-09-08 02:33:01 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if ($('#nsfw').hasClass('nsfw-avail')) {
|
|
|
|
var nsfw = 'true'
|
|
|
|
toot.sensitive = nsfw
|
2018-01-28 23:22:43 +11:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
var nsfw = 'false'
|
2018-01-28 23:22:43 +11:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
if (postvis) {
|
2019-11-09 00:52:54 +11:00
|
|
|
var vis = postvis
|
2019-05-19 17:39:30 +10:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
var vis = $('#vis').text()
|
2018-09-17 21:55:00 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if (vis != 'inherit' && vis != 'local') {
|
|
|
|
toot.visibility = vis
|
|
|
|
} else if (vis == 'local') {
|
|
|
|
toot.status = str + '👁️'
|
2018-03-20 15:55:25 +11:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if ($('#cw').hasClass('cw-avail')) {
|
|
|
|
var spo = $('#cw-text').val()
|
|
|
|
cw()
|
|
|
|
toot.spoiler_text = spo
|
2018-01-28 23:22:43 +11:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
var spo = ''
|
2018-01-28 23:22:43 +11:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if ($('#sch-box').hasClass('sch-avail')) {
|
|
|
|
var scheduled = formattimeutc(new Date(Date.parse($('#sch-date').val())))
|
|
|
|
console.log('This toot will be posted at:' + scheduled)
|
|
|
|
schedule()
|
|
|
|
toot.scheduled_at = scheduled
|
2020-06-16 16:08:27 +10:00
|
|
|
if($('#sch-box').hasClass('expire')) {
|
|
|
|
toot.scheduled_at = null
|
|
|
|
toot.expires_at = scheduled
|
|
|
|
}
|
2019-01-22 03:25:40 +11:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
var scheduled = ''
|
2019-01-22 03:25:40 +11:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if (!$('#poll').hasClass('hide')) {
|
|
|
|
var options = []
|
|
|
|
$('.mastodon-choice').map(function() {
|
|
|
|
var choice = $(this).val()
|
|
|
|
if (choice != '') {
|
|
|
|
options.push(choice)
|
2019-03-06 19:08:48 +11:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
})
|
|
|
|
if ($('#poll-multiple:checked').val() == '1') {
|
|
|
|
var mul = true
|
2019-05-19 17:39:30 +10:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
var mul = false
|
2019-03-06 19:08:48 +11:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if ($('#poll-until:checked').val() == '1') {
|
|
|
|
var htt = true
|
2019-05-19 17:39:30 +10:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
var htt = false
|
2019-03-06 22:56:39 +11:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
var exin = pollCalc()
|
2019-05-19 17:39:30 +10:00
|
|
|
if (!exin) {
|
2019-11-09 00:52:54 +11:00
|
|
|
todc('Error: Poll expires_in param')
|
2019-03-06 19:08:48 +11:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
toot.poll = {
|
2019-03-06 19:08:48 +11:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
console.table(toot)
|
|
|
|
var httpreq = new XMLHttpRequest()
|
|
|
|
httpreq.open('POST', start, true)
|
|
|
|
httpreq.setRequestHeader('Content-Type', 'application/json')
|
|
|
|
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
|
2019-11-27 01:48:22 +11:00
|
|
|
httpreq.setRequestHeader('Idempotency-Key', ideKey)
|
2019-11-09 00:52:54 +11:00
|
|
|
httpreq.responseType = 'json'
|
|
|
|
httpreq.send(JSON.stringify(toot))
|
|
|
|
httpreq.onreadystatechange = function() {
|
2019-03-08 05:19:26 +11:00
|
|
|
if (httpreq.readyState === 4) {
|
2019-11-09 00:52:54 +11:00
|
|
|
var json = httpreq.response
|
|
|
|
if (this.status !== 200) {
|
2020-04-07 18:41:57 +10:00
|
|
|
if(media && this.status == 422) {
|
|
|
|
$('#ideKey').val('')
|
|
|
|
$('.toot-btn-group').prop('disabled', false)
|
|
|
|
alertProcessUnfinished()
|
|
|
|
} else {
|
|
|
|
setLog(start, this.status, json)
|
|
|
|
var box = localStorage.getItem('box')
|
|
|
|
if (box == 'yes' || !box) {
|
|
|
|
$('#textarea').blur()
|
|
|
|
hide()
|
|
|
|
}
|
|
|
|
$('.toot-btn-group').prop('disabled', false)
|
|
|
|
todc()
|
|
|
|
clear()
|
|
|
|
}
|
2019-11-27 01:48:22 +11:00
|
|
|
} else {
|
|
|
|
$('#ideKey').val('')
|
2020-04-07 18:41:57 +10:00
|
|
|
var box = localStorage.getItem('box')
|
|
|
|
if (box == 'yes' || !box) {
|
|
|
|
$('#textarea').blur()
|
|
|
|
hide()
|
|
|
|
}
|
|
|
|
$('.toot-btn-group').prop('disabled', false)
|
|
|
|
todc()
|
|
|
|
clear()
|
2018-04-17 03:10:35 +10:00
|
|
|
}
|
2018-01-28 23:22:43 +11:00
|
|
|
}
|
2018-04-17 03:10:35 +10:00
|
|
|
}
|
2018-01-28 23:22:43 +11:00
|
|
|
}
|
2020-06-16 16:08:27 +10:00
|
|
|
function expPostMode() {
|
|
|
|
$('#sch-box').toggleClass('expire')
|
|
|
|
if($('#sch-box').hasClass('expire')) {
|
|
|
|
Swal.fire({
|
|
|
|
type: 'info',
|
|
|
|
title: 'Expiring toot On'
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
Swal.fire({
|
|
|
|
type: 'info',
|
|
|
|
title: 'Expireing toot Off'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
function misskeyPost() {
|
2019-11-09 00:52:54 +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)
|
|
|
|
$('.toot-btn-group').prop('disabled', true)
|
|
|
|
todo('Posting')
|
|
|
|
var at = localStorage.getItem('acct_' + acct_id + '_at')
|
|
|
|
var start = 'https://' + domain + '/api/notes/create'
|
|
|
|
var reply = $('#reply').val()
|
2019-05-19 17:39:30 +10:00
|
|
|
var toot = {
|
2018-07-30 21:03:49 +10:00
|
|
|
text: str
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
if (reply) {
|
2019-11-09 00:52:54 +11:00
|
|
|
if (reply.indexOf('renote') !== -1) {
|
|
|
|
toot.renoteId = reply.replace('renote_', '')
|
2019-05-19 17:39:30 +10:00
|
|
|
} else {
|
|
|
|
toot.replyId = reply
|
2018-07-30 21:03:49 +10:00
|
|
|
}
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
|
2019-11-09 00:52:54 +11:00
|
|
|
var media = $('#media').val()
|
2019-05-19 17:39:30 +10:00
|
|
|
if (media) {
|
2019-11-09 00:52:54 +11:00
|
|
|
toot.mediaIds = media.split(',')
|
2018-07-30 21:03:49 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if ($('#nsfw').hasClass('nsfw-avail')) {
|
|
|
|
var nsfw = 'true'
|
|
|
|
toot.sensitive = nsfw
|
2018-07-30 21:03:49 +10:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
var nsfw = 'false'
|
2018-07-30 21:03:49 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
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('@')
|
2018-07-30 21:03:49 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if (vis != 'inherit') {
|
|
|
|
toot.visibility = vis
|
2018-07-30 21:03:49 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
if ($('#cw').hasClass('cw-avail')) {
|
|
|
|
var spo = $('#cw-text').val()
|
|
|
|
cw()
|
|
|
|
toot.cw = spo
|
2018-07-30 21:03:49 +10:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
var spo = ''
|
2018-07-30 21:03:49 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
toot.i = at
|
|
|
|
var httpreq = new XMLHttpRequest()
|
|
|
|
httpreq.open('POST', start, true)
|
|
|
|
httpreq.setRequestHeader('Content-Type', 'application/json')
|
|
|
|
httpreq.responseType = 'json'
|
|
|
|
httpreq.send(JSON.stringify(toot))
|
|
|
|
httpreq.onreadystatechange = function() {
|
2019-03-08 05:19:26 +11:00
|
|
|
if (httpreq.readyState === 4) {
|
2019-11-09 00:52:54 +11:00
|
|
|
if (str.indexOf(localStorage.getItem('stable')) == -1) {
|
|
|
|
localStorage.removeItem('stable')
|
|
|
|
}
|
|
|
|
var json = httpreq.response
|
|
|
|
if (this.status !== 200) {
|
|
|
|
setLog(start, this.status, json)
|
2018-07-30 21:03:49 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
console.log(['Success: toot', json])
|
|
|
|
var box = localStorage.getItem('box')
|
|
|
|
if (box == 'yes') {
|
|
|
|
hide()
|
|
|
|
} else if (box == 'hide') {
|
|
|
|
$('body').addClass('mini-post')
|
|
|
|
$('.mini-btn').text('expand_less')
|
2018-07-30 21:03:49 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
$('.toot-btn-group').prop('disabled', false)
|
|
|
|
todc()
|
|
|
|
clear()
|
2018-07-30 21:03:49 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-28 23:22:43 +11:00
|
|
|
|
|
|
|
//クリア(Shift+C)
|
|
|
|
function clear() {
|
2019-11-09 00:52:54 +11:00
|
|
|
$('#textarea').val('')
|
2019-11-27 01:48:22 +11:00
|
|
|
$('#ideKey').val('')
|
2019-11-09 00:52:54 +11:00
|
|
|
if (localStorage.getItem('stable')) {
|
|
|
|
$('#textarea').val('#' + localStorage.getItem('stable') + ' ')
|
2018-07-28 07:25:12 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
$('#textarea').attr('placeholder', lang.lang_toot)
|
|
|
|
$('#reply').val('')
|
|
|
|
$('#quote').val('')
|
|
|
|
$('#media').val('')
|
|
|
|
var cwt = localStorage.getItem('cw-text')
|
2018-01-28 23:22:43 +11:00
|
|
|
if (cwt) {
|
2019-11-09 00:52:54 +11:00
|
|
|
$('#cw-text').val(cwt)
|
2018-01-28 23:22:43 +11:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
$('#cw-text').val('')
|
2018-01-28 23:22:43 +11:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
var acw = localStorage.getItem('always-cw')
|
|
|
|
if (acw != 'yes') {
|
|
|
|
$('#cw').removeClass('yellow-text')
|
|
|
|
$('#cw').removeClass('cw-avail')
|
|
|
|
$('#cw-text').hide()
|
2019-05-19 17:39:30 +10:00
|
|
|
} else {
|
2019-11-09 00:52:54 +11:00
|
|
|
$('#cw').addClass('yellow-text')
|
|
|
|
$('#cw').addClass('cw-avail')
|
|
|
|
$('#cw-text').show()
|
2018-08-05 13:36:23 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
$('#rec').text(lang.lang_no)
|
|
|
|
$('#mec').text(lang.lang_nothing)
|
|
|
|
loadVis()
|
|
|
|
$('#nsfw').removeClass('yellow-text')
|
|
|
|
$('#nsfw').html('visibility_off')
|
|
|
|
$('#nsfw').removeClass('nsfw-avail')
|
2019-12-14 03:54:40 +11:00
|
|
|
$('#stamp').html('Off')
|
|
|
|
$('#stamp').removeClass('stamp-avail')
|
2019-11-09 00:52:54 +11:00
|
|
|
$('#nsc').text(lang.lang_nothing)
|
|
|
|
$('#drag').css('background-color', '#e0e0e0')
|
|
|
|
$('#preview').html('')
|
|
|
|
$('.toot-btn-group').prop('disabled', false)
|
|
|
|
$('#post-acct-sel').prop('disabled', false)
|
|
|
|
$('#days_poll').val(0)
|
|
|
|
$('#hours_poll').val(0)
|
|
|
|
$('#mins_poll').val(6)
|
|
|
|
$('#poll').addClass('hide')
|
|
|
|
$('#pollsta').text(lang.lang_no)
|
|
|
|
$('.mastodon-choice').map(function() {
|
|
|
|
$(this).val('')
|
|
|
|
})
|
|
|
|
if (localStorage.getItem('mainuse') == 'main') {
|
|
|
|
$('#post-acct-sel').val(localStorage.getItem('main'))
|
2018-05-20 16:17:10 +10:00
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
$('#emoji').addClass('hide')
|
|
|
|
$('select').formSelect()
|
|
|
|
$('#default-emoji').show()
|
|
|
|
$('#unreact').show()
|
|
|
|
$('#addreact').addClass('hide')
|
|
|
|
$('#right-side').hide()
|
|
|
|
$('#right-side').css('width', '300px')
|
|
|
|
$('#left-side').css('width', '100%')
|
|
|
|
var width = localStorage.getItem('postbox-width')
|
|
|
|
if (width) {
|
|
|
|
width = width.replace('px', '') * 1
|
2019-10-22 16:34:30 +11:00
|
|
|
} else {
|
|
|
|
width = 300
|
|
|
|
}
|
2019-11-09 00:52:54 +11:00
|
|
|
$('#post-box').css('width', width)
|
2019-10-22 16:34:30 +11:00
|
|
|
mdCheck()
|
2019-11-09 00:52:54 +11:00
|
|
|
}
|