thedesk/app/js/post/status.js

715 lines
21 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
//お気に入り登録やブースト等、フォローやブロック等
//お気に入り登録
2018-03-21 16:36:02 +11:00
function fav(id, acct_id, remote) {
2019-12-12 02:05:40 +11:00
if ($(`.cvo[unique-id=${id}]`).hasClass('faved')) {
2019-11-09 00:52:54 +11:00
var flag = 'unfavourite'
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
var flag = 'favourite'
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
2019-11-04 03:09:02 +11:00
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
2019-11-09 00:52:54 +11:00
var json = httpreq.response
2019-11-04 03:09:02 +11:00
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, json)
2019-11-04 03:09:02 +11:00
}
if (json.reblog) {
2019-11-09 00:52:54 +11:00
json = json.reblog
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
if (remote != 'remote') {
2019-11-04 03:09:02 +11:00
//APIのふぁぼカウントがおかしい
2019-11-09 00:52:54 +11:00
if ($('[unique-id=' + id + '] .fav_ct').text() == json.favourites_count) {
if (flag == 'unfavourite') {
var fav = json.favourites_count - 1
2019-11-04 03:09:02 +11:00
if (fav * 1 < 0) {
2019-11-09 00:52:54 +11:00
fav = 0
2019-11-04 03:09:02 +11:00
}
} else {
2019-11-09 00:52:54 +11:00
var fav = json.favourites_count
2019-11-04 03:09:02 +11:00
//var fav = json.favourites_count;
}
} else {
2019-11-09 00:52:54 +11:00
var fav = json.favourites_count
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
$('[unique-id=' + id + '] .fav_ct').text(fav)
$('[unique-id=' + id + '] .rt_ct').text(json.reblogs_count)
if ($('[unique-id=' + id + ']').hasClass('faved')) {
$('[unique-id=' + id + ']').removeClass('faved')
$('.fav_' + id).removeClass('yellow-text')
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('[unique-id=' + id + ']').addClass('faved')
$('.fav_' + id).addClass('yellow-text')
2019-11-04 03:09:02 +11:00
}
} else {
2020-07-09 18:03:22 +10:00
Mtoast({ html: lang.lang_status_favWarn, displayLength: 1000 })
2019-11-04 03:09:02 +11:00
}
2019-05-19 17:39:30 +10:00
}
2019-11-09 00:52:54 +11:00
}
2018-01-28 23:22:43 +11:00
}
//ブースト
2019-10-05 03:23:47 +10:00
function rt(id, acct_id, remote, vis) {
2019-12-15 01:41:35 +11:00
if ($(`.cvo[toot-id=${id}]`).hasClass('rted')) {
2019-11-09 00:52:54 +11:00
var flag = 'unreblog'
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
var flag = 'reblog'
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
2019-11-04 03:09:02 +11:00
if (vis) {
2019-11-09 00:52:54 +11:00
httpreq.send(JSON.stringify({ visibility: vis }))
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
httpreq.send()
2019-11-04 03:09:02 +11:00
}
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
2019-11-09 00:52:54 +11:00
var json = httpreq.response
2019-11-04 03:09:02 +11:00
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, json)
2019-11-04 03:09:02 +11:00
}
if (json.reblog) {
2019-11-09 00:52:54 +11:00
json = json.reblog
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
console.log(['Success: boost', json])
2019-12-15 01:41:35 +11:00
$('[toot-id=' + id + '] .fav_ct').text(json.favourites_count)
2019-11-04 03:09:02 +11:00
if (!json.reblog) {
2019-11-09 00:52:54 +11:00
if (flag == 'unreblog') {
var rt = json.reblogs_count - 1
2019-11-04 03:09:02 +11:00
if (rt * 1 < 0) {
2019-11-09 00:52:54 +11:00
rt = 0
2019-11-04 03:09:02 +11:00
}
} else {
2019-11-09 00:52:54 +11:00
var rt = json.reblogs_count
2019-11-04 03:09:02 +11:00
}
2019-12-15 01:41:35 +11:00
$('[toot-id=' + id + '] .rt_ct').text(rt)
2019-11-04 03:09:02 +11:00
} else {
2019-12-15 01:41:35 +11:00
$('[toot-id=' + id + '] .rt_ct').text(json.reblogs_count)
2019-11-04 03:09:02 +11:00
}
2018-01-28 23:22:43 +11:00
2019-12-15 01:41:35 +11:00
if ($('[toot-id=' + id + ']').hasClass('rted')) {
$('[toot-id=' + id + ']').removeClass('rted')
2019-11-09 00:52:54 +11:00
$('.rt_' + id).removeClass('light-blue-text')
2019-11-04 03:09:02 +11:00
} else {
2019-12-15 01:41:35 +11:00
$('[toot-id=' + id + ']').addClass('rted')
2019-11-09 00:52:54 +11:00
$('.rt_' + id).addClass('light-blue-text')
2019-11-04 03:09:02 +11:00
}
}
2019-11-09 00:52:54 +11:00
}
2018-01-28 23:22:43 +11:00
}
2019-10-12 01:50:25 +11:00
function boostWith(vis) {
2019-11-09 00:52:54 +11:00
var id = $('#tootmodal').attr('data-id')
var acct_id = $('#tootmodal').attr('data-acct')
rt(id, acct_id, false, vis)
2019-10-05 03:23:47 +10:00
}
2019-11-16 05:42:23 +11:00
//ブックマーク
2019-11-16 06:58:37 +11:00
function bkm(id, acct_id, tlid) {
2019-12-12 02:05:40 +11:00
if ($(`.cvo[unique-id=${id}]`).hasClass('bkmed')) {
2019-11-16 05:42:23 +11:00
var flag = 'unbookmark'
} else {
var flag = 'bookmark'
}
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
var json = httpreq.response
if (this.status !== 200) {
setLog(start, this.status, json)
}
if (json.reblog) {
json = json.reblog
}
2019-11-16 06:58:37 +11:00
var fav = json.favourites_count
2019-11-27 01:26:04 +11:00
$('[toot-id=' + id + '] .fav_ct').text(fav)
$('[toot-id=' + id + '] .rt_ct').text(json.reblogs_count)
if (flag == 'unbookmark') {
$('.bkmStr_' + id).text(lang.lang_parse_bookmark)
$('.bkm_' + id).removeClass('red-text')
$('[toot-id=' + id + ']').removeClass('bkmed')
} else {
$('.bkmStr_' + id).text(lang.lang_parse_unbookmark)
$('.bkm_' + id).addClass('red-text')
$('[toot-id=' + id + ']').addClass('bkmed')
}
var tlidTar = $(`.bookmark-timeline[data-acct=${acct_id}]`).attr('tlid')
columnReload(tlidTar, 'bookmark')
2019-11-16 05:42:23 +11:00
}
}
}
2018-01-28 23:22:43 +11:00
//フォロー
2019-11-04 03:09:02 +11:00
async function follow(acct_id, resolve) {
2020-06-12 23:13:06 +10:00
if($('#his-data').hasClass('locked')) {
locked = true
} else {
locked = false
}
2019-11-09 00:52:54 +11:00
if (!acct_id && acct_id != 'selector') {
var acct_id = $('#his-data').attr('use-acct')
2020-06-12 23:13:06 +10:00
2019-11-09 00:52:54 +11:00
} else if (acct_id == 'selector') {
var acct_id = $('#user-acct-sel').val()
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
if (!resolve && $('#his-data').hasClass('following')) {
var flag = 'unfollow'
var flagm = 'delete'
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
var flag = 'follow'
var flagm = 'create'
2019-11-04 03:09:02 +11:00
}
2020-06-12 23:13:06 +10:00
2019-11-09 00:52:54 +11:00
var id = $('#his-data').attr('user-id')
if (resolve == 'selector') {
var fullacct = $('#his-acct').attr('fullname')
var id = await acctResolve(acct_id, fullacct)
console.log(id)
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag
if (localStorage.getItem('mode_' + domain) == 'misskey') {
var start = 'https://' + domain + '/api/following/' + flagm
var ent = { i: at, userId: id }
} else if (flag == 'follow') {
var ent = {}
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send(JSON.stringify(ent))
2019-11-04 03:09:02 +11:00
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
2019-11-09 00:52:54 +11:00
var json = httpreq.response
2019-11-04 03:09:02 +11:00
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, json)
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
console.log(['Success: folllow', json])
if ($('#his-data').hasClass('following')) {
$('#his-data').removeClass('following')
$('#his-follow-btn-text').text(lang.lang_status_follow)
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('#his-data').addClass('following')
2020-06-12 23:13:06 +10:00
if(locked) {
$('#his-follow-btn-text').text(lang.lang_status_requesting)
} else {
$('#his-follow-btn-text').text(lang.lang_status_unfollow)
}
2019-11-04 03:09:02 +11:00
}
}
2019-11-09 00:52:54 +11:00
}
2019-11-04 03:09:02 +11:00
}
async function acctResolve(acct_id, user) {
2019-11-09 00:52:54 +11:00
console.log('Get user data of ' + user)
var domain = localStorage.getItem('domain_' + acct_id)
if (localStorage.getItem('mode_' + domain) == 'misskey') {
return false
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v2/search?resolve=true&q=' + user
2019-11-04 03:09:02 +11:00
let promise = await fetch(start, {
2019-11-09 00:52:54 +11:00
method: 'GET',
2019-11-04 03:09:02 +11:00
headers: {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json',
Authorization: 'Bearer ' + at
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
})
var idJson = await promise.json()
2019-11-04 03:09:02 +11:00
if (idJson.accounts[0]) {
2019-11-09 00:52:54 +11:00
var id = idJson.accounts[0].id
2019-11-04 03:09:02 +11:00
} else {
2020-07-09 18:03:22 +10:00
Mtoast({ html: lang.lang_fatalerroroccured, displayLength: 2000 })
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
return id
2018-01-28 23:22:43 +11:00
}
//ブロック
function block(acct_id) {
2019-11-09 00:52:54 +11:00
if ($('#his-data').hasClass('blocking')) {
var flag = 'unblock'
var txt = lang.lang_status_unmute
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
var flag = 'block'
var txt = lang.lang_status_block
2019-11-04 03:09:02 +11:00
}
Swal.fire({
title: txt,
2019-11-09 00:52:54 +11:00
text: '',
type: 'warning',
2019-11-04 03:09:02 +11:00
showCancelButton: true,
2019-11-09 00:52:54 +11:00
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
2019-11-04 03:09:02 +11:00
confirmButtonText: lang.lang_yesno,
cancelButtonText: lang.lang_no
}).then(result => {
if (result.value) {
if (!acct_id) {
2019-11-09 00:52:54 +11:00
var acct_id = $('#his-data').attr('use-acct')
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var id = $('#his-data').attr('user-id')
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
2019-11-04 03:09:02 +11:00
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, this.response)
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
if ($('#his-data').hasClass('blocking')) {
$('#his-data').removeClass('blocking')
$('#his-block-btn-text').text(lang.lang_status_block)
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('#his-data').addClass('blocking')
$('#his-block-btn-text').text(lang.lang_status_unblock)
2019-11-04 03:09:02 +11:00
}
}
2019-11-09 00:52:54 +11:00
}
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
})
2018-01-28 23:22:43 +11:00
}
//ミュート
2019-06-22 00:17:56 +10:00
function muteDo(acct_id) {
2019-11-09 00:52:54 +11:00
if ($('#his-data').hasClass('muting')) {
var flag = 'unmute'
var flagm = 'delete'
var txt = lang.lang_status_unmute
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
var flag = 'mute'
var flagm = 'create'
var txt = lang.lang_status_mute
2019-11-04 03:09:02 +11:00
}
Swal.fire({
title: txt,
2019-11-09 00:52:54 +11:00
text: '',
type: 'warning',
2019-11-04 03:09:02 +11:00
showCancelButton: true,
2019-11-09 00:52:54 +11:00
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
2019-11-04 03:09:02 +11:00
confirmButtonText: lang.lang_yesno,
cancelButtonText: lang.lang_no
}).then(result => {
if (result.value) {
if (!acct_id) {
2019-11-09 00:52:54 +11:00
var acct_id = $('#his-data').attr('use-acct')
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var id = $('#his-data').attr('user-id')
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
if (localStorage.getItem('mode_' + domain) == 'misskey') {
var start = 'https://' + domain + '/api/mute/' + flagm
var ent = { i: at, userId: id }
var rq = JSON.stringify(ent)
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag
var rq = ''
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send(rq)
2019-11-04 03:09:02 +11:00
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, this.response)
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
if ($('#his-data').hasClass('muting')) {
$('#his-data').removeClass('muting')
$('#his-mute-btn-text').text(lang.lang_status_mute)
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('#his-data').addClass('muting')
$('#his-mute-btn-text').text(lang.lang_status_unmute)
2019-11-04 03:09:02 +11:00
}
}
2019-11-09 00:52:54 +11:00
}
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
})
2018-01-28 23:22:43 +11:00
}
//投稿削除
function del(id, acct_id) {
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
if (localStorage.getItem('mode_' + domain) == 'misskey') {
var start = 'https://' + domain + '/api/notes/delete'
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.responseType = 'json'
httpreq.send(JSON.stringify({ i: at, noteId: id }))
$('[toot-id=' + id + ']').hide()
$('[toot-id=' + id + ']').remove()
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
var start = 'https://' + domain + '/api/v1/statuses/' + id
var httpreq = new XMLHttpRequest()
httpreq.open('DELETE', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
2019-11-04 03:09:02 +11:00
}
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, this.response)
2019-11-04 03:09:02 +11:00
}
}
2019-11-09 00:52:54 +11:00
}
2018-01-28 23:22:43 +11:00
}
2018-07-17 01:39:06 +10:00
//redraft
2019-05-19 17:39:30 +10:00
function redraft(id, acct_id) {
2019-11-04 03:09:02 +11:00
Swal.fire({
title: lang.lang_status_redraftTitle,
text: lang.lang_status_redraft,
2019-11-09 00:52:54 +11:00
type: 'warning',
2019-11-04 03:09:02 +11:00
showCancelButton: true,
2019-11-09 00:52:54 +11:00
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
2019-11-04 03:09:02 +11:00
confirmButtonText: lang.lang_yesno,
cancelButtonText: lang.lang_no
}).then(result => {
if (result.value) {
2019-11-09 00:52:54 +11:00
show()
2019-11-27 01:26:04 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
if (localStorage.getItem('mode_' + domain) == 'misskey') {
var start = 'https://' + domain + '/api/notes/delete'
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.responseType = 'json'
httpreq.send(JSON.stringify({ i: at, noteId: id }))
$('[toot-id=' + id + ']').hide()
$('[toot-id=' + id + ']').remove()
} else {
var start = 'https://' + domain + '/api/v1/statuses/' + id
var httpreq = new XMLHttpRequest()
httpreq.open('DELETE', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
}
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
if (this.status !== 200) {
setLog(start, this.status, this.response)
}
var json = httpreq.response
$('#post-acct-sel').prop('disabled', true)
$('#post-acct-sel').val(acct_id)
2020-07-05 20:45:21 +10:00
//$('select').formSelect()
2019-11-27 01:26:04 +11:00
mdCheck()
var medias = $('[toot-id=' + id + ']').attr('data-medias')
2019-12-14 12:12:18 +11:00
var mediack = json.media_attachments[0]
//メディアがあれば
var media_ids = []
if (mediack) {
for (var i = 0; i <= 4; i++) {
if (json.media_attachments[i]) {
media_ids.push(json.media_attachments[i].id)
$('#preview').append(
'<img src="' +
json.media_attachments[i].preview_url +
2020-05-23 14:54:51 +10:00
'" style="width:50px; max-height:100px;">'
2019-12-14 12:12:18 +11:00
)
} else {
break
}
}
}
2019-11-27 01:26:04 +11:00
var vismode = $('[toot-id=' + id + '] .vis-data').attr('data-vis')
vis(vismode)
2019-12-14 12:12:18 +11:00
var medias = media_ids.join(',');
2019-11-27 01:26:04 +11:00
$('#media').val(medias)
localStorage.setItem('nohide', true)
show()
2019-12-12 02:05:40 +11:00
if (json.text) {
2019-11-27 01:26:04 +11:00
var html = json.text
} else {
var html = $('[toot-id=' + id + '] .toot').html()
html = html.replace(/^<p>(.+)<\/p>$/, '$1')
html = html.replace(/<br\s?\/?>/, '\n')
html = html.replace(/<p>/, '\n')
html = html.replace(/<\/p>/, '\n')
html = html.replace(/<img[\s\S]*alt="(.+?)"[\s\S]*?>/g, '$1')
html = $.strip_tags(html)
}
$('#textarea').val(html)
if (json.spoiler_text) {
cw()
$('#cw-text').val(json.spoiler_text)
}
2019-12-12 02:05:40 +11:00
if (json.sensitive) {
2019-11-27 01:26:04 +11:00
$('#nsfw').addClass('yellow-text')
$('#nsfw').html('visibility')
$('#nsfw').addClass('nsfw-avail')
}
2019-12-12 02:05:40 +11:00
if (json.in_reply_to_id) {
2019-11-27 01:48:22 +11:00
$('#reply').val(json.in_reply_to_id)
}
2019-11-04 03:09:02 +11:00
}
}
}
2019-11-09 00:52:54 +11:00
})
2018-07-17 01:39:06 +10:00
}
2018-03-11 01:22:59 +11:00
//ピン留め
function pin(id, acct_id) {
2019-12-12 02:05:40 +11:00
if ($(`.cvo[unique-id=${id}]`).hasClass('pined')) {
2019-11-09 00:52:54 +11:00
var flag = 'unpin'
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
var flag = 'pin'
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/statuses/' + id + '/' + flag
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
2019-11-04 03:09:02 +11:00
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
2019-11-09 00:52:54 +11:00
var json = httpreq.response
2019-11-04 03:09:02 +11:00
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, this.response)
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
console.log(['Success: pinned', json])
2019-11-16 05:42:23 +11:00
if (flag == 'unpin') {
2019-11-09 00:52:54 +11:00
$('[toot-id=' + id + ']').removeClass('pined')
$('.pin_' + id).removeClass('blue-text')
2019-11-16 05:42:23 +11:00
$('.pinStr_' + id).text(lang.lang_parse_pin)
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('[toot-id=' + id + ']').addClass('pined')
$('.pin_' + id).addClass('blue-text')
2019-11-16 05:42:23 +11:00
$('.pinStr_' + id).text(lang.lang_parse_unpin)
2019-11-04 03:09:02 +11:00
}
}
2019-11-09 00:52:54 +11:00
}
2018-03-11 01:22:59 +11:00
}
2018-01-28 23:22:43 +11:00
//フォロリク
function request(id, flag, acct_id) {
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/follow_requests/' + id + '/' + flag
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
2019-11-04 03:09:02 +11:00
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
2019-11-09 00:52:54 +11:00
var json = httpreq.response
2019-11-04 03:09:02 +11:00
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, this.response)
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
console.log(['Success: request', 'type:' + flag, json])
showReq()
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
}
2018-01-28 23:22:43 +11:00
}
//ドメインブロック(未実装)
function domainblock(add, flag, acct_id) {
2019-11-04 03:09:02 +11:00
if (!acct_id) {
2019-11-09 00:52:54 +11:00
var acct_id = $('#his-data').attr('use-acct')
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/domain_blocks'
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
2019-11-04 03:09:02 +11:00
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
2019-11-09 00:52:54 +11:00
var json = httpreq.response
2019-11-04 03:09:02 +11:00
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, this.response)
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
console.log(['Success: domain block', json])
showDom()
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
}
2018-01-28 23:22:43 +11:00
}
function addDomainblock() {
2019-11-09 00:52:54 +11:00
var domain = $('#domainblock').val()
domainblock(domain, 'POST')
2018-01-28 23:22:43 +11:00
}
2018-03-11 01:22:59 +11:00
//ユーザー強調
2019-05-19 17:39:30 +10:00
function empUser() {
2019-11-09 00:52:54 +11:00
var usr = localStorage.getItem('user_emp')
var obj = JSON.parse(usr)
var id = $('#his-acct').attr('fullname')
2019-11-04 03:09:02 +11:00
if (!obj) {
2019-11-09 00:52:54 +11:00
var obj = []
obj.push(id)
2020-07-09 18:03:22 +10:00
Mtoast({ html: id + lang.lang_status_emphas, displayLength: 4000 })
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
var can
2019-11-04 03:09:02 +11:00
Object.keys(obj).forEach(function(key) {
2019-11-09 00:52:54 +11:00
var usT = obj[key]
2019-11-04 03:09:02 +11:00
if (usT != id && !can) {
2019-11-09 00:52:54 +11:00
can = false
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
can = true
obj.splice(key, 1)
2020-07-09 18:03:22 +10:00
Mtoast({ html: id + lang.lang_status_unemphas, displayLength: 4000 })
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
})
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var json = JSON.stringify(obj)
localStorage.setItem('user_emp', json)
2018-03-11 01:22:59 +11:00
}
2018-09-05 01:04:56 +10:00
//Endorse
2019-05-19 17:39:30 +10:00
function pinUser() {
2019-11-09 00:52:54 +11:00
var id = $('#his-data').attr('user-id')
var acct_id = $('#his-data').attr('use-acct')
if ($('#his-end-btn').hasClass('endorsed')) {
var flag = 'unpin'
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
var flag = 'pin'
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v1/accounts/' + id + '/' + flag
var httpreq = new XMLHttpRequest()
httpreq.open('POST', start, true)
httpreq.setRequestHeader('Content-Type', 'application/json')
httpreq.setRequestHeader('Authorization', 'Bearer ' + at)
httpreq.responseType = 'json'
httpreq.send()
2019-11-04 03:09:02 +11:00
httpreq.onreadystatechange = function() {
if (httpreq.readyState === 4) {
2019-11-09 00:52:54 +11:00
var json = httpreq.response
2019-11-04 03:09:02 +11:00
if (this.status !== 200) {
2019-11-09 00:52:54 +11:00
setLog(start, this.status, this.response)
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
if ($('#his-end-btn').hasClass('endorsed')) {
$('#his-end-btn').removeClass('endorsed')
$('#his-end-btn').text(lang.lang_status_endorse)
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('#his-end-btn').addClass('endorsed')
$('#his-end-btn').text(lang.lang_status_unendorse)
2019-11-04 03:09:02 +11:00
}
}
2019-11-09 00:52:54 +11:00
}
2018-09-05 01:04:56 +10:00
}
2018-02-18 16:43:11 +11:00
//URLコピー
2019-05-19 17:39:30 +10:00
function tootUriCopy(url) {
2019-11-09 00:52:54 +11:00
execCopy(url)
2020-07-09 18:03:22 +10:00
Mtoast({ html: lang.lang_details_url, displayLength: 1500 })
2018-03-21 16:36:02 +11:00
}
//他のアカウントで…
2019-05-19 17:39:30 +10:00
function staEx(mode) {
2019-11-09 00:52:54 +11:00
var url = $('#tootmodal').attr('data-url')
var acct_id = $('#status-acct-sel').val()
var domain = localStorage.getItem('domain_' + acct_id)
var at = localStorage.getItem('acct_' + acct_id + '_at')
var start = 'https://' + domain + '/api/v2/search?resolve=true&q=' + url
2019-11-04 03:09:02 +11:00
fetch(start, {
2019-11-09 00:52:54 +11:00
method: 'GET',
2019-11-04 03:09:02 +11:00
headers: {
2019-11-09 00:52:54 +11:00
'content-type': 'application/json',
Authorization: 'Bearer ' + at
2019-10-31 02:30:26 +11:00
}
2019-11-04 03:09:02 +11:00
})
.then(function(response) {
if (!response.ok) {
response.text().then(function(text) {
2019-11-09 00:52:54 +11:00
setLog(response.url, response.status, text)
})
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
return response.json()
2019-11-04 03:09:02 +11:00
})
.catch(function(error) {
2019-11-09 00:52:54 +11:00
todo(error)
setLog(start, 'JSON', error)
console.error(error)
2019-11-04 03:09:02 +11:00
})
.then(function(json) {
2019-12-12 02:05:40 +11:00
if (json.statuses) {
if (json.statuses[0]) {
var id = json.statuses[0].id
if (mode == 'rt') {
rt(id, acct_id, 'remote')
} else if (mode == 'fav') {
fav(id, acct_id, 'remote')
} else if (mode == 'reply') {
reEx(id)
}
}
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
})
return
2018-05-02 14:14:03 +10:00
}
2019-11-16 05:42:23 +11:00
function toggleAction(elem, height) {
var cont = elem.parents('.cvo').find('.contextMenu')
if (cont.hasClass('hide')) {
$('#contextWrap').removeClass('hide')
var left = elem.offset().left + 60
var top = elem.offset().top - height
if (top < 75) {
top = elem.offset().top + 45
cont.removeClass('bottom')
cont.addClass('top')
} else {
cont.removeClass('top')
cont.addClass('bottom')
}
2019-11-27 01:26:04 +11:00
if (elem.parents('.cvo').attr('id') == 'toot-this') {
2019-11-16 15:36:16 +11:00
console.log($('#toot-this').offset().top, elem.offset().top)
left = $('#toot-this').offset().left + elem.offset().left + 10
2019-11-27 01:26:04 +11:00
top = $('#toot-this').offset().top - $('#toot-this').height() - height + 25
2019-11-16 15:36:16 +11:00
}
2019-11-16 05:42:23 +11:00
cont.css('top', top + 'px')
cont.css('right', `calc(100vw - ${left}px)`)
cont.removeClass('hide')
elem
.parents('.cvo')
.find('.act-icon')
.text('expand_less')
2019-11-04 03:09:02 +11:00
} else {
2019-11-16 05:42:23 +11:00
$('#contextWrap').addClass('hide')
$('.contextMenu').addClass('hide')
$('.act-icon').text('expand_more')
2019-11-04 03:09:02 +11:00
}
2019-10-12 01:50:25 +11:00
}