2018-01-28 23:22:43 +11:00
|
|
|
|
//左下のメッセージ
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var todcTrigger = null
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function todo(mes) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
clearInterval(todcTrigger)
|
|
|
|
|
$('#message').text(mes)
|
|
|
|
|
$('#message').fadeIn()
|
|
|
|
|
todcTrigger = setTimeout(todc, 4000)
|
2018-01-28 23:22:43 +11:00
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function todc() {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
$('#message').fadeOut()
|
2018-01-28 23:22:43 +11:00
|
|
|
|
}
|
2018-09-11 04:59:44 +10:00
|
|
|
|
//reverse
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function bottomReverse() {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
$('#bottom').toggleClass('reverse')
|
|
|
|
|
$('.leftside').toggleClass('reverse')
|
|
|
|
|
if ($('#bottom').hasClass('reverse')) {
|
|
|
|
|
localStorage.removeItem('reverse')
|
2019-05-19 17:39:30 +10:00
|
|
|
|
} else {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
localStorage.setItem('reverse', 'true')
|
2018-09-11 04:59:44 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function tips(mode) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
postMessage(['sendSinmpleIpc', 'endmem'], '*')
|
|
|
|
|
clearInterval(clockint)
|
|
|
|
|
clearInterval(spotStart)
|
|
|
|
|
if (mode == 'ver') {
|
|
|
|
|
tipsToggle()
|
|
|
|
|
$('#tips-text').html(
|
|
|
|
|
'<img src="../../img/desk.png" width="20" onclick="todo(\'TheDesk is a nice client!: TheDesk ' +
|
|
|
|
|
localStorage.getItem('ver') +
|
|
|
|
|
' git: ' +
|
|
|
|
|
gitHash +
|
2020-05-10 22:52:01 +10:00
|
|
|
|
'\')"> ' +
|
2019-11-09 16:19:18 +11:00
|
|
|
|
localStorage.getItem('ver') +
|
|
|
|
|
' {' +
|
|
|
|
|
gitHash.slice(0, 7) +
|
|
|
|
|
'} [<i class="material-icons" style="font-size:1.2rem;top: 3px;position: relative;">supervisor_account</i><span id="persons">1+</span>]'
|
|
|
|
|
)
|
|
|
|
|
localStorage.setItem('tips', 'ver')
|
|
|
|
|
} else if (mode == 'clock') {
|
|
|
|
|
tipsToggle()
|
|
|
|
|
localStorage.setItem('tips', 'clock')
|
|
|
|
|
clock()
|
|
|
|
|
} else if (mode == 'memory') {
|
|
|
|
|
tipsToggle()
|
|
|
|
|
localStorage.setItem('tips', 'memory')
|
|
|
|
|
startmem()
|
|
|
|
|
} else if (mode == 'trend') {
|
|
|
|
|
tipsToggle()
|
|
|
|
|
localStorage.setItem('tips', 'trend')
|
|
|
|
|
trendTagonTip()
|
|
|
|
|
} else if (mode == 'spotify') {
|
|
|
|
|
tipsToggle()
|
|
|
|
|
localStorage.setItem('tips', 'spotify')
|
|
|
|
|
spotifytips()
|
2019-11-09 16:30:28 +11:00
|
|
|
|
} else if (mode == 'itunes') {
|
|
|
|
|
tipsToggle()
|
|
|
|
|
localStorage.setItem('tips', 'itunes')
|
|
|
|
|
itunestips()
|
2018-07-28 07:25:12 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//メモリ
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function startmem() {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
postMessage(['sendSinmpleIpc', 'startmem'], '*')
|
2019-06-15 03:10:11 +10:00
|
|
|
|
}
|
2019-11-04 03:10:06 +11:00
|
|
|
|
function renderMem(use, cpu, total) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
$('#tips-text').html(
|
|
|
|
|
escapeHTML(cpu) +
|
|
|
|
|
'<br>Memory:' +
|
|
|
|
|
Math.floor(use / 1024 / 1024 / 102.4) / 10 +
|
|
|
|
|
'/' +
|
|
|
|
|
Math.floor(total / 1024 / 1024 / 102.4) / 10 +
|
|
|
|
|
'GB(' +
|
|
|
|
|
Math.floor((use / total) * 100) +
|
|
|
|
|
'%)'
|
|
|
|
|
)
|
2018-07-28 07:25:12 +10:00
|
|
|
|
}
|
|
|
|
|
//トレンドタグ
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function trendTagonTip() {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
$('.trendtag').remove()
|
|
|
|
|
var domain = 'imastodon.net'
|
|
|
|
|
var at = localStorage.getItem('acct_' + acct_id + '_at')
|
|
|
|
|
var start = 'https://' + domain + '/api/v1/trend_tags'
|
2018-07-28 07:25:12 +10:00
|
|
|
|
fetch(start, {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
method: 'GET',
|
2018-07-28 07:25:12 +10:00
|
|
|
|
headers: {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
'content-type': 'application/json',
|
|
|
|
|
Authorization: 'Bearer ' + at
|
2019-05-19 17:39:30 +10:00
|
|
|
|
}
|
2019-11-04 03:10:06 +11:00
|
|
|
|
})
|
|
|
|
|
.then(function(response) {
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
response.text().then(function(text) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
setLog(response.url, response.status, text)
|
|
|
|
|
})
|
2019-11-04 03:10:06 +11:00
|
|
|
|
}
|
2019-11-09 16:19:18 +11:00
|
|
|
|
return response.json()
|
2019-11-04 03:10:06 +11:00
|
|
|
|
})
|
|
|
|
|
.catch(function(error) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
todo(error)
|
|
|
|
|
setLog(start, 'JSON', error)
|
|
|
|
|
console.error(error)
|
2019-11-04 03:10:06 +11:00
|
|
|
|
})
|
|
|
|
|
.then(function(json) {
|
|
|
|
|
if (json) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var tags = ''
|
|
|
|
|
json = json.score
|
2019-11-04 03:10:06 +11:00
|
|
|
|
Object.keys(json).forEach(function(tag) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
tags =
|
|
|
|
|
tags +
|
|
|
|
|
`<a onclick="tagShow('${tag}')" class="pointer">
|
|
|
|
|
#${escapeHTML(tag)}
|
|
|
|
|
</a>
|
2019-11-25 01:07:21 +11:00
|
|
|
|
<span class="hide" data-tag="${tag}" data-regTag="${tag.toLowerCase()}">
|
2019-11-09 16:19:18 +11:00
|
|
|
|
<a onclick="tagTL('tag','${tag}',false,'add')" class="pointer" title="#${tag}のタイムライン">TL</a>
|
|
|
|
|
<a onclick="show();brInsert('#${tag}')" class="pointer" title="#${tag}でトゥート">Toot</a>
|
|
|
|
|
</span><br>`
|
|
|
|
|
})
|
|
|
|
|
$('#tips-text').html(
|
|
|
|
|
'<div class="trendtag">トレンドタグ<i class="material-icons pointer" onclick="trendTagonTip()" style="font-size:12px">refresh</i>:<br>' +
|
|
|
|
|
tags +
|
|
|
|
|
'</div>'
|
|
|
|
|
)
|
|
|
|
|
trendTagonTipInterval()
|
2019-11-04 03:10:06 +11:00
|
|
|
|
} else {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
$('#tips-text').html('')
|
2019-11-04 03:10:06 +11:00
|
|
|
|
}
|
2019-11-09 16:19:18 +11:00
|
|
|
|
})
|
2018-07-28 07:25:12 +10:00
|
|
|
|
}
|
2018-07-29 17:37:54 +10:00
|
|
|
|
//Spotify
|
2019-11-09 16:19:18 +11:00
|
|
|
|
spotint = null
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function spotifytips() {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
if (spotint) clearInterval(spotint)
|
|
|
|
|
var start =
|
|
|
|
|
'https://thedesk.top/now-playing?at=' +
|
|
|
|
|
localStorage.getItem('spotify') +
|
|
|
|
|
'&rt=' +
|
|
|
|
|
localStorage.getItem('spotify-refresh')
|
|
|
|
|
var at = localStorage.getItem('spotify')
|
2019-05-19 17:39:30 +10:00
|
|
|
|
if (at) {
|
|
|
|
|
fetch(start, {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
method: 'GET',
|
2019-05-19 17:39:30 +10:00
|
|
|
|
headers: {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
'content-type': 'application/json'
|
2019-05-19 17:39:30 +10:00
|
|
|
|
}
|
2019-11-04 03:10:06 +11:00
|
|
|
|
})
|
|
|
|
|
.then(function(response) {
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
response.text().then(function(text) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
setLog(response.url, response.status, text)
|
|
|
|
|
})
|
2018-07-29 17:37:54 +10:00
|
|
|
|
}
|
2019-11-09 16:19:18 +11:00
|
|
|
|
return response.json()
|
2019-11-04 03:10:06 +11:00
|
|
|
|
})
|
|
|
|
|
.catch(function(error) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
todo(error)
|
|
|
|
|
setLog(start, 'JSON', error)
|
|
|
|
|
console.error(error)
|
2019-11-04 03:10:06 +11:00
|
|
|
|
})
|
|
|
|
|
.then(function(json) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var ms = json.progress_ms
|
2020-04-08 16:28:04 +10:00
|
|
|
|
if(!ms) {
|
|
|
|
|
tips('ver')
|
|
|
|
|
return false
|
|
|
|
|
}
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var last = 1000 - (ms % 1000)
|
|
|
|
|
var item = json.item
|
|
|
|
|
var img = item.album.images[0].url
|
|
|
|
|
var artisttxt = ''
|
2019-11-04 03:10:06 +11:00
|
|
|
|
for (i = 0; i < item.artists.length; i++) {
|
|
|
|
|
if (i > 0) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
artisttxt = artisttxt + ',' + item.artists[i].name
|
2019-11-04 03:10:06 +11:00
|
|
|
|
} else {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
artisttxt = item.artists[0].name
|
2019-11-04 03:10:06 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-09 16:19:18 +11:00
|
|
|
|
artisttxt = escapeHTML(artisttxt)
|
|
|
|
|
sleep(last)
|
|
|
|
|
var tms = item.duration_ms
|
|
|
|
|
var per = (ms / item.duration_ms) * 100
|
|
|
|
|
ms = ms / 1000
|
|
|
|
|
tms = tms / 1000
|
|
|
|
|
var s = Math.round(ms) % 60
|
2019-11-04 03:10:06 +11:00
|
|
|
|
if (s < 10) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
s = '0' + s
|
2019-11-04 03:10:06 +11:00
|
|
|
|
}
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var m = (Math.round(ms) - (Math.round(ms) % 60)) / 60
|
|
|
|
|
var ts = Math.round(tms) % 60
|
2019-11-04 03:10:06 +11:00
|
|
|
|
if (ts < 10) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
ts = '0' + ts
|
2019-11-04 03:10:06 +11:00
|
|
|
|
}
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var tm = (Math.round(tms) - (Math.round(tms) % 60)) / 60
|
|
|
|
|
var html = `
|
|
|
|
|
<div id="spot-box">
|
|
|
|
|
<div id="spot-refresh">
|
|
|
|
|
<i class="material-icons pointer" onclick="spotifytips()" style="font-size:20px">refresh</i>
|
|
|
|
|
<i class="material-icons pointer" onclick="nowplaying('spotify');show()" style="font-size:20px">send</i>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="spot-cover">
|
|
|
|
|
<img src="${img}" id="spot-img">
|
|
|
|
|
</div>
|
|
|
|
|
<div id="spot-name">
|
|
|
|
|
${escapeHTML(item.name)}
|
|
|
|
|
</div>
|
|
|
|
|
<div id="spot-artist">
|
|
|
|
|
<span class="gray sml" id="spot-art">${artisttxt}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="spot-time">
|
|
|
|
|
<span id="spot-m">${m}</span>:<span id="spot-s">${s}</span>/${tm}:${ts}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="progress grey">
|
|
|
|
|
<div class="determinate spotify-prog grey lighten-2"
|
|
|
|
|
style="width:${per}%" data-s="${Math.round(ms)}" data-total="${item.duration_ms}">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`
|
|
|
|
|
$('#tips-text').html(html)
|
|
|
|
|
spotint = setInterval(spotStart, 1000)
|
|
|
|
|
})
|
2019-05-19 17:39:30 +10:00
|
|
|
|
} else {
|
2019-06-22 02:06:32 +10:00
|
|
|
|
Swal.fire({
|
2019-11-09 16:19:18 +11:00
|
|
|
|
type: 'info',
|
2019-06-22 02:06:32 +10:00
|
|
|
|
title: lang.lang_spotify_acct
|
2019-11-09 16:19:18 +11:00
|
|
|
|
})
|
2020-04-08 16:28:04 +10:00
|
|
|
|
tips('ver')
|
|
|
|
|
return false
|
2019-05-19 17:39:30 +10:00
|
|
|
|
}
|
2018-07-29 17:37:54 +10:00
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function spotStart() {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var total = $('.spotify-prog').attr('data-total')
|
|
|
|
|
var s = $('.spotify-prog').attr('data-s')
|
|
|
|
|
var news = s * 1 + 1
|
|
|
|
|
var per = (news * 100000) / total
|
|
|
|
|
var ns = news % 60
|
|
|
|
|
var nm = (news - ns) / 60
|
2019-05-19 17:39:30 +10:00
|
|
|
|
if (ns < 10) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
ns = '0' + ns
|
2018-07-29 17:37:54 +10:00
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
|
if (per >= 100) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
clearInterval(spotStart)
|
|
|
|
|
spotifytips()
|
2019-05-19 17:39:30 +10:00
|
|
|
|
} else {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
$('#spot-m').text(nm)
|
|
|
|
|
$('#spot-s').text(ns)
|
2019-05-19 17:39:30 +10:00
|
|
|
|
}
|
2019-11-09 16:19:18 +11:00
|
|
|
|
$('.spotify-prog').attr('data-s', news)
|
|
|
|
|
$('.spotify-prog').css('width', per + '%')
|
2018-07-29 17:37:54 +10:00
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function trendTagonTipInterval() {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
setTimeout(trendTagonTip, 6000000)
|
2018-07-28 07:25:12 +10:00
|
|
|
|
}
|
|
|
|
|
//時計
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var clockint
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function clock() {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var now = new Date()
|
|
|
|
|
var last = 1000 - (now.getTime() % 1000)
|
|
|
|
|
sleep(last)
|
|
|
|
|
clockint = setInterval(clockStart, 1000)
|
2018-07-28 07:25:12 +10:00
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function clockStart() {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var nowTime = new Date() // 現在日時を得る
|
|
|
|
|
var nowHour = nowTime.getHours() // 時を抜き出す
|
2019-11-04 03:10:06 +11:00
|
|
|
|
if (nowHour < 10) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
nowHour = '0' + nowHour
|
2019-11-04 03:10:06 +11:00
|
|
|
|
}
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var nowMin = nowTime.getMinutes() // 分を抜き出す
|
2019-11-04 03:10:06 +11:00
|
|
|
|
if (nowMin < 10) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
nowMin = '0' + nowMin
|
2019-11-04 03:10:06 +11:00
|
|
|
|
}
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var nowSec = nowTime.getSeconds() // 秒を抜き出す
|
2019-11-04 03:10:06 +11:00
|
|
|
|
if (nowSec < 10) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
nowSec = '0' + nowSec
|
2019-11-04 03:10:06 +11:00
|
|
|
|
}
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var msg =
|
|
|
|
|
nowTime.getFullYear() +
|
|
|
|
|
'/' +
|
|
|
|
|
(nowTime.getMonth() + 1) +
|
|
|
|
|
'/' +
|
|
|
|
|
nowTime.getDate() +
|
|
|
|
|
'<span style="font-size:20px; font-family:Open Sans">' +
|
|
|
|
|
nowHour +
|
|
|
|
|
':' +
|
|
|
|
|
nowMin +
|
|
|
|
|
':' +
|
|
|
|
|
nowSec +
|
|
|
|
|
'</span>'
|
|
|
|
|
$('#tips-text').html(msg)
|
2018-07-28 07:25:12 +10:00
|
|
|
|
}
|
|
|
|
|
function sleep(waitMsec) {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
var startMsec = new Date()
|
2018-07-28 07:25:12 +10:00
|
|
|
|
while (new Date() - startMsec < waitMsec);
|
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
|
function tipsToggle() {
|
2019-11-09 16:19:18 +11:00
|
|
|
|
$('#tips').toggleClass('hide')
|
|
|
|
|
$('#tips-menu').toggleClass('hide')
|
2018-07-28 07:25:12 +10:00
|
|
|
|
}
|
2020-04-08 16:28:04 +10:00
|
|
|
|
|