today shinchoku

This commit is contained in:
cutls 2020-07-21 09:06:58 +09:00
parent 47749dde7b
commit d92a9ae1ae
3 changed files with 71 additions and 56 deletions

View File

@ -65,7 +65,12 @@ async function verck(ver) {
r += c[Math.floor(Math.random() * cl)]
}
const start = 'https://thedesk.top/ver.json'
const mess = await getApi(start, null)
let mess
try {
mess = await getApi(start, null)
} catch {
return false
}
console.table(mess)
if (mess) {
let newest = null
@ -98,7 +103,12 @@ async function verck(ver) {
lni = 0
}
const getNotice = 'https://thedesk.top/notice/index.php?since_id=' + lni
const notices = await getApi(getNotice, null)
let notices
try {
notices = await getApi(getNotice, null)
} catch {
return false
}
if (notices.length < 1) {
return false
} else {

View File

@ -8,7 +8,7 @@ localStorage.removeItem('imas')
localStorage.removeItem('stable')
const acctList = JSON.parse(localStorage.getItem('multi'))
function ck() {
async function ck() {
const main = localStorage.getItem('main')
if (!main) {
localStorage.setItem('main', '0')
@ -37,7 +37,8 @@ function ck() {
const key = keymap[i]
const acct = obj[key]
if (acct.domain) {
req = refresh(key, true)
let refreshed = await refresh(key, true)
if(refreshed) req = true
}
}
if(req) {
@ -76,27 +77,35 @@ async function refresh(target, loadskip) {
return
}
const start = `https://${domain}/api/v1/accounts/verify_credentials`
const json = await getApi(start, at)
let json
try{
json = await getApi(start, at)
} catch {
return false
}
if (json.error) {
console.error('Error:' + json.error)
M.toast({ html: lang.lang_fatalerroroccured + 'Error:' + json.error, displayLength: 5000 })
return
}
if(!json) return false
let avatar = json['avatar']
//missingがmissingなやつ
if (avatar == '/avatars/original/missing.png' || !avatar) {
avatar = './img/missing.svg'
}
const { newName, newProf, newVis } = json
const newName = json.display_name
const newProf = avatar
const newVis = json.source.privacy
if (newName != name || newProf != prof || newVis != vis) {
let ref = {
at: at,
name: json['display_name'],
name: newName,
domain: domain,
user: json['acct'],
prof: avatar,
id: json['id'],
vis: json['source']['privacy']
vis: newVis
}
if (background) {
ref.background = background
@ -173,7 +182,7 @@ function multiSelector(parseC) {
lastUsed = localStorage.getItem('main')
} else if (localStorage.getItem('last-use')) {
lastUsed = localStorage.getItem('last-use')
if (lastUsed == 'webview' || last == 'noauth') {
if (lastUsed == 'webview' || lastUsed == 'noauth') {
lastUsed = '0'
}
} else {
@ -187,7 +196,7 @@ function multiSelector(parseC) {
for (let i = 0; i < obj.length; i++) {
const acct = obj[i]
const strKey = i?.toString()
if (key == lastUsed) {
if (strKey == lastUsed) {
sel = 'selected'
const domain = acct.domain
const letters = idata[`${domain}_letters`]
@ -196,7 +205,7 @@ function multiSelector(parseC) {
textarea.setAttribute('data-length', letters)
} else {
//手動でアカマネで変えれちゃうから
const maxLetters = localStorage.getItem('letters_' + key)
const maxLetters = localStorage.getItem('letters_' + strKey)
if (maxLetters > 0) {
textarea.setAttribute('data-length', maxLetters)
} else {
@ -210,7 +219,7 @@ function multiSelector(parseC) {
if (!profimg) {
profimg = '../../img/missing.svg'
}
document.querySelector('#acct-sel-pro').setAttribute('src', profimg)
document.querySelector('#acct-sel-prof').setAttribute('src', profimg)
let cc = ''
if (domain) {
cc = `(${domain})`
@ -225,35 +234,35 @@ function multiSelector(parseC) {
if (domain == 'imastodon.net') {
trendTag()
} else {
document.querySelector('#trendtag').innerHTML = ''
if(document.querySelector('#trendtag')) this.innerHTML = ''
}
} else {
sel = ''
}
template = `
<option value="${key}" data-icon="${acct.prof}" class="left circle" ${sel}>
<option value="${strKey}" data-icon="${acct.prof}" class="left circle" ${sel}>
@${acct.user} ${acct.domain}
</option>
`
appendPrepend('.acct-sel', template, 'append')
}
$('#src-acct-sel').append('<option value="tootsearch">Tootsearch</option>')
$('#add-acct-sel').append(
'<option value="noauth">' +
lang.lang_login_noauth +
'</option><option value="webview">Twitter</option>'
)
$('#dir-acct-sel').append('<option value="noauth">' + lang.lang_login_noauth + '</option>')
appendPrepend('#src-acct-sel', '<option value="tootsearch">Tootsearch</option>', 'append')
appendPrepend('#add-acct-sel', `
<option value="noauth">${lang.lang_login_noauth}</option>
<option value="webview">Twitter</option>
`, 'append')
appendPrepend('#dir-acct-sel', `<option value="noauth">${lang.lang_login_noauth}</option>`, 'append')
}
$('select').formSelect()
const elems = document.querySelectorAll('select');
M.FormSelect.init(elems, null);
if (!parseC) {
parseColumn(null, true)
}
}
//インスタンスティッカー
function ticker() {
async function ticker() {
const start = 'https://toot-app.thedesk.top/toot/index.php'
const json = getApi(start, null)
const json = await getApi(start, null)
if(json) localStorage.setItem('ticker', JSON.stringify(json))
}
function isMisskey(domain) {

View File

@ -1,11 +1,11 @@
$.strip_tags = function(str, allowed) {
$.strip_tags = function (str, allowed) {
if (!str) {
return ''
}
allowed = (((allowed || '') + '').toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join('')
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>?/gi,
commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi
return str.replace(commentsAndPhpTags, '').replace(tags, function($0, $1) {
return str.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : ''
})
}
@ -13,12 +13,7 @@ function escapeHTML(str) {
if (!str) {
return ''
}
return str
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;')
}
//PHPのnl2brと同様
function nl2br(str) {
@ -88,17 +83,18 @@ function formattimeutc(date) {
}
postMessage(['sendSinmpleIpc', 'custom-css-request'], '*')
function makeCID() {
return (
randomStr(8) +
'-' +
randomStr(4) +
'-' +
randomStr(4) +
'-' +
randomStr(4) +
'-' +
randomStr(12)
)
let chars = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.split('')
for (let i = 0, len = chars.length; i < len; i++) {
switch (chars[i]) {
case 'x':
chars[i] = Math.floor(Math.random() * 16).toString(16)
break
case 'y':
chars[i] = (Math.floor(Math.random() * 4) + 8).toString(16)
break
}
}
return chars.join('')
}
function randomStr(l) {
// 生成する文字列に含める文字セット
@ -129,7 +125,7 @@ function rgbToHex(color) {
// RGBからHEXへ変換
parseInt(regex[1]).toString(16),
parseInt(regex[2]).toString(16),
parseInt(regex[3]).toString(16)
parseInt(regex[3]).toString(16),
]
for (var i = 0; i < rgb.length; ++i) {
@ -147,15 +143,15 @@ function rgbToHex(color) {
console.error(color + ':第1引数はRGB形式で入力')
}
/*マルチバイト用切り出し*/
$.isSurrogatePear = function(upper, lower) {
$.isSurrogatePear = function (upper, lower) {
return 0xd800 <= upper && upper <= 0xdbff && 0xdc00 <= lower && lower <= 0xdfff
}
$.mb_strlen = function(str) {
$.mb_strlen = function (str) {
var splitter = new GraphemeSplitter()
var arr = splitter.splitGraphemes(str)
return arr.length
}
$.mb_substr = function(str, begin, end) {
$.mb_substr = function (str, begin, end) {
//配列にする
var splitter = new GraphemeSplitter()
var arr = splitter.splitGraphemes(str)
@ -175,7 +171,7 @@ function object_array_sort(data, key, order, fn) {
num_a = 1
num_b = -1
}
data = data.sort(function(a, b) {
data = data.sort(function (a, b) {
var x = a[key]
var y = b[key]
if (x > y) return num_a
@ -252,7 +248,7 @@ function statusModel(now) {
reblog: null,
application: {
name: null,
website: null
website: null,
},
account: {
id: '',
@ -273,13 +269,13 @@ function statusModel(now) {
statuses_count: 0,
last_status_at: now,
emojis: [],
fields: []
fields: [],
},
media_attachments: [],
mentions: [],
tags: [],
card: null,
poll: null
poll: null,
}
}
@ -310,16 +306,16 @@ function setAllClasses(query, className, action) {
const allTarget = document.querySelectorAll(query)
for (let i = 0; i < allTarget.length; i++) {
const target = allTarget[i]
if(action == 'add') target.classList.add(className)
if(action == 'remove') target.classList.remove(className)
if (action == 'add') target.classList.add(className)
if (action == 'remove') target.classList.remove(className)
}
}
function appendPrepend(query, elm, action) {
const allTarget = document.querySelectorAll(query)
for (let i = 0; i < allTarget.length; i++) {
const target = allTarget[i]
if(action == 'prepend') target.prependChild(elm)
if(action == 'append') target.appendChild(elm)
if (action == 'prepend') target.prependChild(document.createTextNode(elm))
if (action == 'append') target.appendChild(document.createTextNode(elm))
}
}
const sleep = msec => new Promise(resolve => setTimeout(resolve, msec));
const sleep = (msec) => new Promise((resolve) => setTimeout(resolve, msec))