thedesk/app/js/post/status.js

653 lines
19 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-11-09 00:52:54 +11:00
if ($('#pub_' + id).hasClass('faved')) {
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 {
2019-11-09 00:52:54 +11:00
M.toast({ 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-11-09 00:52:54 +11:00
if ($('#pub_' + id).hasClass('rted')) {
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])
$('[unique-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-11-09 00:52:54 +11:00
$('[unique-id=' + id + '] .rt_ct').text(rt)
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('[unique-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-11-09 00:52:54 +11:00
if ($('[unique-id=' + id + ']').hasClass('rted')) {
$('[unique-id=' + id + ']').removeClass('rted')
$('.rt_' + id).removeClass('light-blue-text')
2019-11-04 03:09:02 +11:00
} else {
2019-11-09 00:52:54 +11:00
$('[unique-id=' + id + ']').addClass('rted')
$('.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-11-16 05:42:23 +11:00
if ($('#pub_' + id).hasClass('bkmed')) {
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-16 05:42:23 +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')
}
2019-11-16 06:58:37 +11:00
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) {
2019-11-09 00:52:54 +11:00
if (!acct_id && acct_id != 'selector') {
var acct_id = $('#his-data').attr('use-acct')
} 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
}
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')
$('#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 {
2019-11-09 00:52:54 +11:00
M.toast({ 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()
del(id, acct_id)
$('#post-acct-sel').prop('disabled', true)
$('#post-acct-sel').val(acct_id)
$('select').formSelect()
mdCheck()
var medias = $('[toot-id=' + id + ']').attr('data-medias')
var vismode = $('[toot-id=' + id + '] .vis-data').attr('data-vis')
vis(vismode)
$('#media').val(medias)
var ct = medias.split(',').length
$('[toot-id=' + id + '] img.toot-img').each(function(i, elem) {
2019-11-04 03:09:02 +11:00
if (i < ct) {
2019-11-09 00:52:54 +11:00
var url = $(elem).attr('src')
console.log('Play back image data:' + url)
$('#preview').append('<img src="' + url + '" style="width:50px; max-height:100px;">')
2019-11-04 03:09:02 +11:00
}
2019-11-09 00:52:54 +11:00
})
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)
localStorage.setItem('nohide', true)
show()
$('#textarea').val(html)
var cwtxt = $('[toot-id=' + id + '] .cw_text').html()
if (cwtxt != '') {
cwtxt = $.strip_tags(cwtxt)
cw()
$('#cw-text').val(cwtxt)
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-11-09 00:52:54 +11:00
if ($('#pub_' + id).hasClass('pined')) {
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)
M.toast({ 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)
M.toast({ 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)
M.toast({ 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-11-09 00:52:54 +11:00
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-16 15:36:16 +11:00
if(elem.parents('.cvo').attr('id') == 'toot-this'){
console.log($('#toot-this').offset().top, elem.offset().top)
left = $('#toot-this').offset().left + elem.offset().left + 10
top = $('#toot-this').offset().top - $('#toot-this').height() -height + 25
}
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
}