Add: Last.fm

This commit is contained in:
cutls 2020-05-05 23:36:31 +09:00
parent 9aef043344
commit 7ee4205f8a
11 changed files with 146 additions and 89 deletions

View File

@ -3,7 +3,7 @@ var envView = new Vue({
el: '#envView',
data: { config: envConstruction },
methods: {
complete: function(i, val) {
complete: function (i, val) {
var ls = envView.config[i].storage
M.toast({ html: 'Complete', displayLength: 3000 })
if (!val) {
@ -21,14 +21,14 @@ var envView = new Vue({
frameSet(val)
}
return true
}
}
},
},
})
var tlView = new Vue({
el: '#tlView',
data: { config: tlConstruction },
methods: {
complete: function(i, val) {
complete: function (i, val) {
var ls = tlView.config[i]
if (val) {
localStorage.setItem(ls.storage, val)
@ -46,18 +46,18 @@ var tlView = new Vue({
}
}
return true
}
}
},
},
})
var postView = new Vue({
el: '#postView',
data: {
config: postConstruction,
kirishima: localStorage.getItem('kirishima'),
quoters: localStorage.getItem('quoters')
quoters: localStorage.getItem('quoters'),
},
methods: {
complete: function(i, val) {
complete: function (i, val) {
var ls = postView.config[i]
if (val) {
localStorage.setItem(ls.storage, val)
@ -75,8 +75,8 @@ var postView = new Vue({
}
}
return true
}
}
},
},
})
//設定ボタン押した。
function settings() {
@ -177,6 +177,7 @@ function load() {
$('#soundVolVal').text(cvol * 100)
}
//$("#log").val(localStorage.getItem("errors"))
$('#lastFmUser').val(localStorage.getItem('lastFmUser'))
}
function customVol() {
var cvol = $('#soundvol').val()
@ -215,7 +216,7 @@ function climute() {
return
}
var templete
Object.keys(obj).forEach(function(key) {
Object.keys(obj).forEach(function (key) {
var cli = obj[key]
var list = key * 1 + 1
templete =
@ -250,7 +251,7 @@ function wordmute() {
obj = []
}
$('#wordmute').chips({
data: obj
data: obj,
})
}
function wordmuteSave() {
@ -266,7 +267,7 @@ function wordemp() {
obj = []
}
$('#wordemp').chips({
data: obj
data: obj,
})
}
function wordempSave() {
@ -278,7 +279,7 @@ function notftest() {
var os = localStorage.getItem('platform')
var options = {
body: lang.lang_setting_notftest + '(' + lang.lang_setting_notftestprof + ')',
icon: localStorage.getItem('prof_0')
icon: localStorage.getItem('prof_0'),
}
var n = new Notification('TheDesk' + lang.lang_setting_notftest, options)
}
@ -303,7 +304,7 @@ function changelang(lang) {
}
function exportSettings() {
var exp = exportSettingsCore()
$("#imp-exp").val(JSON5.stringify(exp))
$('#imp-exp').val(JSON5.stringify(exp))
Swal.fire({
title: lang.lang_setting_exportwarn,
type: 'warning',
@ -311,8 +312,8 @@ function exportSettings() {
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: lang.lang_yesno,
cancelButtonText: lang.lang_no
}).then(result => {
cancelButtonText: lang.lang_no,
}).then((result) => {
if (result.value) {
postMessage(['exportSettings', ''], '*')
}
@ -351,11 +352,7 @@ function exportSettingsCore() {
config.font = localStorage.getItem('font')
exp.config = config
//keysc
exp.ksc = [
localStorage.getItem('oks-1'),
localStorage.getItem('oks-2'),
localStorage.getItem('oks-3')
]
exp.ksc = [localStorage.getItem('oks-1'), localStorage.getItem('oks-2'), localStorage.getItem('oks-3')]
//climu
var cli = localStorage.getItem('client_mute')
var climu = JSON.parse(cli)
@ -384,8 +381,8 @@ function exportSettingsCore() {
return exp
}
function importSettings() {
if($("#imp-exp").val()) {
importSettingsCore(JSON5.parse($("#imp-exp").val()))
if ($('#imp-exp').val()) {
importSettingsCore(JSON5.parse($('#imp-exp').val()))
return false
}
Swal.fire({
@ -395,8 +392,8 @@ function importSettings() {
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: lang.lang_yesno,
cancelButtonText: lang.lang_no
}).then(result => {
cancelButtonText: lang.lang_no,
}).then((result) => {
if (result.value) {
postMessage(['importSettings', ''], '*')
}
@ -490,7 +487,7 @@ function importSettingsCore(obj) {
} else {
Swal.fire({
type: 'error',
title: 'Error'
title: 'Error',
})
}
}
@ -505,21 +502,13 @@ function fontList(arg) {
$('#fonts').removeClass('hide')
for (var i = 0; i < arg.length; i++) {
var font = arg[i]
$('#fonts').append(
'<div class="font pointer" style="font-family:' +
font +
'" onclick="insertFont(\'' +
font +
'\')">' +
font +
'</div>'
)
$('#fonts').append('<div class="font pointer" style="font-family:' + font + '" onclick="insertFont(\'' + font + '\')">' + font + '</div>')
}
}
function insertFont(name) {
$('#font').val(name)
}
$('.color-picker').each(function(i, elem) {
$('.color-picker').each(function (i, elem) {
pickerDefine(i, 'fff')
})
function pickerDefine(i, color) {
@ -536,17 +525,16 @@ function pickerDefine(i, color) {
hue: true, // Hue slider
interaction: {
rgba: false, // rgba option (red green blue and alpha)
input: true // input / output element
}
input: true, // input / output element
},
},
strings: {
save: 'Save', // Default for save button
clear: 'Clear' // Default for clear button
}
clear: 'Clear', // Default for clear button
},
})
pickr.on('change', (...args) => {
var rgb =
'rgb(' + args[0].toRGBA()[0] + ',' + args[0].toRGBA()[1] + ',' + args[0].toRGBA()[2] + ')'
var rgb = 'rgb(' + args[0].toRGBA()[0] + ',' + args[0].toRGBA()[1] + ',' + args[0].toRGBA()[2] + ')'
$('#color-picker' + i + '_value').val(rgb)
})
}
@ -600,7 +588,7 @@ function customComp() {
TheDeskModal: modalC,
TheDeskBottom: bottomC,
TheDeskPostbox: postboxC,
TheDeskSubcolor: subcolorC
TheDeskSubcolor: subcolorC,
}
} else {
var advanceTheme = {}
@ -620,10 +608,10 @@ function customComp() {
vars: {
primary: primaryC,
secondary: secondaryC,
text: textC
text: textC,
},
props: advanceTheme,
id: id
id: id,
}
$('#custom_json').val(JSON.stringify(json))
themes('custom')
@ -633,9 +621,7 @@ function customComp() {
$('#dark').prop('checked', true)
$('#custom_json').val('')
for (var i = 0; i <= 8; i++) {
$('#color-picker' + i + '-wrap').html(
'<div class="color-picker" id="color-picker' + i + '"></div>'
)
$('#color-picker' + i + '-wrap').html('<div class="color-picker" id="color-picker' + i + '"></div>')
$('#color-picker' + i + '_value').val('')
pickerDefine(i, 'fff')
}
@ -648,9 +634,7 @@ function deleteIt() {
$('#dark').prop('checked', true)
$('#custom_json').val('')
for (var i = 0; i <= 8; i++) {
$('#color-picker' + i + '-wrap').html(
'<div class="color-picker" id="color-picker' + i + '"></div>'
)
$('#color-picker' + i + '-wrap').html('<div class="color-picker" id="color-picker' + i + '"></div>')
$('#color-picker' + i + '_value').val('')
pickerDefine(i, 'fff')
}
@ -661,7 +645,7 @@ function ctLoad() {
}
function ctLoadCore(args) {
var templete = ''
Object.keys(args).forEach(function(key) {
Object.keys(args).forEach(function (key) {
var theme = args[key]
var themeid = theme.id
templete = templete + '<option value="' + themeid + '">' + theme.name + '</option>'
@ -670,8 +654,7 @@ function ctLoadCore(args) {
localStorage.setItem('customtheme-id', args[0].id)
}
$('#custom-sel-sel').html(templete)
templete =
'<option value="add_new">' + $('#edit-selector').attr('data-add') + '</option>' + templete
templete = '<option value="add_new">' + $('#edit-selector').attr('data-add') + '</option>' + templete
$('#custom-edit-sel').html(templete)
$('select').formSelect()
}
@ -687,9 +670,7 @@ function custom() {
$('#dark').prop('checked', true)
$('#custom_json').val('')
for (var i = 0; i <= 8; i++) {
$('#color-picker' + i + '-wrap').html(
'<div class="color-picker" id="color-picker' + i + '"></div>'
)
$('#color-picker' + i + '-wrap').html('<div class="color-picker" id="color-picker' + i + '"></div>')
$('#color-picker' + i + '_value').val('')
pickerDefine(i, 'fff')
}
@ -737,9 +718,7 @@ function advancedConncet(args, tar, sub, i) {
} else {
var color = args.vars[sub]
}
$('#color-picker' + i + '-wrap').html(
'<div class="color-picker" id="color-picker' + i + '"></div>'
)
$('#color-picker' + i + '-wrap').html('<div class="color-picker" id="color-picker' + i + '"></div>')
$('#color-picker' + i + '_value').val(color)
pickerDefine(i, rgbToHex(color))
}
@ -750,7 +729,7 @@ function customImp() {
} else {
Swal.fire({
type: 'error',
title: 'Error'
title: 'Error',
})
}
}
@ -777,7 +756,7 @@ function customSoundSave(key, file) {
localStorage.setItem('custom' + key, file)
$('#c1-file').text(file)
}
window.onload = function() {
window.onload = function () {
//最初に読む
load()
climute()
@ -793,11 +772,7 @@ function asReadEnd() {
postMessage(['asReadComp', ''], '*')
}
function checkupd() {
if (
localStorage.getItem('winstore') == 'brewcask' ||
localStorage.getItem('winstore') == 'snapcraft' ||
localStorage.getItem('winstore') == 'winstore'
) {
if (localStorage.getItem('winstore') == 'brewcask' || localStorage.getItem('winstore') == 'snapcraft' || localStorage.getItem('winstore') == 'winstore') {
var winstore = true
} else {
var winstore = false
@ -805,22 +780,22 @@ function checkupd() {
var ver = localStorage.getItem('ver')
var start = 'https://thedesk.top/ver.json'
fetch(start, {
method: 'GET'
method: 'GET',
})
.then(function(response) {
.then(function (response) {
if (!response.ok) {
response.text().then(function(text) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function(error) {
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function(mess) {
.then(function (mess) {
console.table(mess)
if (mess) {
var platform = localStorage.getItem('platform')
@ -833,13 +808,13 @@ function checkupd() {
Swal.fire({
type: 'info',
title: lang.lang_setting_noupd,
html: ver
html: ver,
})
} else if (ver.indexOf('beta') != -1 || winstore) {
Swal.fire({
type: 'info',
title: lang.lang_setting_thisisbeta,
html: ver
html: ver,
})
} else {
localStorage.removeItem('new-ver-skip')
@ -848,3 +823,11 @@ function checkupd() {
}
})
}
function lastFmSet() {
if ($('#lastFmUser').val()) {
localStorage.setItem('lastFmUser', $('#lastFmUser').val())
} else {
localStorage.removeItem('lastFmUser')
}
M.toast({ html: 'Complete: last.fm', displayLength: 3000 })
}

View File

@ -138,6 +138,76 @@ function nowplaying(mode) {
}
} else if (mode == 'itunes') {
postMessage(['itunes', ''], '*')
} else if (mode == 'lastFm') {
var user = localStorage.getItem('lastFmUser')
var start = 'https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=' + user + '&limit=1&api_key=8f113803bfea951b6dde9e56d32458b2&format=json'
if (user) {
fetch(start, {
method: 'GET',
headers: {
'content-type': 'application/json',
},
})
.then(function (response) {
if (!response.ok) {
response.text().then(function (text) {
setLog(response.url, response.status, text)
})
}
return response.json()
})
.catch(function (error) {
todo(error)
setLog(start, 'JSON', error)
console.error(error)
})
.then(function (json) {
console.table(json)
if (!json || !json.recenttracks) {
console.error('no data')
return false
}
var item = json.recenttracks.track[0]
if(!item['@attr']) return false
var img = item.image[3]['#text']
var isImg = item.streamable*1
var flag = localStorage.getItem('artwork')
if (flag && isImg && img) {
postMessage(['bmpImage', [img, 0]], '*')
}
var content = localStorage.getItem('np-temp')
if (!content || content == '' || content == 'null') {
var content = '#NowPlaying {song} / {album} / {artist}\n{url}'
}
var regExp = new RegExp('{song}', 'g')
content = content.replace(regExp, item.name)
var regExp = new RegExp('{album}', 'g')
content = content.replace(regExp, item.album['#text'])
var regExp = new RegExp('{artist}', 'g')
content = content.replace(regExp, item.artist['#text'])
var regExp = new RegExp('{url}', 'g')
content = content.replace(regExp,'')
var regExp = new RegExp('{composer}', 'g')
content = content.replace(regExp, '')
var regExp = new RegExp('{hz}', 'g')
content = content.replace(regExp, '')
var regExp = new RegExp('{bitRate}', 'g')
content = content.replace(regExp, '')
var regExp = new RegExp('{lyricist}', 'g')
content = content.replace(regExp, '')
var regExp = new RegExp('{bpm}', 'g')
content = content.replace(regExp, '')
var regExp = new RegExp('{genre}', 'g')
content = content.replace(regExp, '')
$('#textarea').val(content)
})
} else {
Swal.fire({
type: 'info',
title: lang.lang_spotify_acct,
})
}
}
}
async function npCore(arg) {
@ -148,7 +218,7 @@ async function npCore(arg) {
}
var flag = localStorage.getItem('artwork')
var platform = localStorage.getItem('platform')
var aaw = {aaw: '', album: ''}
var aaw = { aaw: '', album: '' }
if (platform == 'win32') {
if (flag && arg.path) {
media(arg.path, 'image/png', 'new')
@ -169,11 +239,11 @@ async function npCore(arg) {
if (arg.album.name) {
content = content.replace(regExp, arg.album.name)
} else {
if(aaw.album) content = content.replace(regExp, aaw.album)
if (aaw.album) content = content.replace(regExp, aaw.album)
content = content.replace(regExp, '-')
}
} else {
if(aaw.album) content = content.replace(regExp, aaw.album)
if (aaw.album) content = content.replace(regExp, aaw.album)
content = content.replace(regExp, '-')
}
var regExp = new RegExp('{artist}', 'g')

View File

@ -124,8 +124,8 @@
]
},
"electronDownload": {
"version": "6.0.0"
"version": "8.0.0"
},
"electronVersion": "6.0.0"
"electronVersion": "8.0.0"
}
}

View File

@ -442,10 +442,13 @@
<!-- その他 Dropdown Structure -->
<ul id="dropdown2" class="dropdown-content">
<li>
<a onclick="nowplaying('spotify');">@@NPSpotify@@</a>
<a onclick="nowplaying('spotify');">NowPlaying (Spotify)</a>
</li>
<li>
<a onclick="nowplaying('itunes');">@@NPiTunes@@</a>
<a onclick="nowplaying('itunes');">NowPlaying (iTunes macOS)</a>
</li>
<li>
<a onclick="nowplaying('lastFm');">NowPlaying (Last.fm)</a>
</li>
<li>
<a onclick="schedule();">@@schedule@@</a>

View File

@ -11,8 +11,6 @@
"cwDes":"Hide text behind warning",
"selfile":"Attach..",
"insertEmoji":"Emojis",
"NPSpotify":"NowPlaying(Spotify)",
"NPiTunes":"NowPlaying(macOS)",
"schedule":"Scheduled toot",
"postat":"Post at",
"scheduleWarn":"2.7.0~ Minimum time gap:5min(clock on the server may not be accurate.)",

View File

@ -167,6 +167,7 @@
"linkwarn": "TheDesk save your data on thedesk.top server.",
"connect": "Connect",
"disconnect": "Disconnect",
"lastFmWarn": "User name...(empty to disconnect) You cannot hide your recent play log at last.fm privacy settings.",
"templateedit": "Edit a template",
"templateeditwarn": "",
"template1": "Spotify:{song}:Song name/{album}:Album name/{artist}:Artist name/{url}:URL to Spotify",

View File

@ -11,8 +11,6 @@
"cwDes":"コンテンツワーニング(ほんまに見るんか?って聞く)",
"selfile":"ファイル選ぶ",
"insertEmoji":"絵文字入れる",
"NPSpotify":"NowPlaying(Spotify)",
"NPiTunes":"NowPlaying(macOS)",
"schedule":"時間指定投稿",
"postat":"時間指定投稿",
"scheduleWarn":"2.7.0~ 5分は待ってな。サーバーの時計おうてるかは知らんで。",

View File

@ -165,6 +165,7 @@
"linkwarn": "APIの性質上thedesk.topへもアクセスするけどしゃーない。",
"connect": "接続",
"disconnect": "切断",
"lastFmWarn": "ユーザー名を入れてや。空白にすると消すで。last.fmの「最近のリスニング情報を表示しない」にチェックを入れんといてな。",
"templateedit": "テンプレートの編集",
"templateeditwarn": "以下を編集してテンプレートを変更できんで。",
"template1": "Spotify:{song}:曲名/{album}:アルバム名/{artist}:アーティスト名/{url}:各曲のSpotifyのURL",

View File

@ -11,8 +11,6 @@
"cwDes":"コンテンツワーニング(トゥートを表示する前にメッセージで隠す)",
"selfile":"ファイルを選択",
"insertEmoji":"絵文字を挿入",
"NPSpotify":"NowPlaying(Spotify)",
"NPiTunes":"NowPlaying(macOS)",
"schedule":"時間指定投稿",
"postat":"時間指定投稿",
"scheduleWarn":"2.7.0~ 5分以内には投稿できません。サーバーの時計が正確とは限りません。",

View File

@ -167,6 +167,7 @@
"linkwarn": "APIの性質上thedesk.topへアクセスします。",
"connect": "接続",
"disconnect": "切断",
"lastFmWarn": "ユーザー名を入れてください。空白にすると解除されます。last.fmの「最近のリスニング情報を表示しない」にチェックを入れないでください。",
"templateedit": "テンプレートの編集",
"templateeditwarn": "以下を編集してテンプレートを変更できます。",
"template1": "Spotify:{song}:曲名/{album}:アルバム名/{artist}:アーティスト名/{url}:各曲のSpotifyのURL",

View File

@ -388,7 +388,7 @@
<i class="fab fa-spotify"></i>@@spotify@@
</div>
<div class="collapsible-body">
<h5>@@link@@</h5>
<h5>@@link@@(Spotify)</h5>
@@linkwarn@@<br>
<div id="spotify-code-show" class="hide"><input type="text" id="spotify-code"><button
onclick="spotifyAuth()" class="btn waves-effect" style="width:100px;">@@set@@</button></div>
@ -398,6 +398,10 @@
<a onclick="spotifyDisconnect()" class="btn waves-effect nex disabled"
style="width:100%; max-width:200px; background-color:#1ed760;" id="spotify-disable"><i
class="fab fa-spotify left"></i>@@disconnect@@</a>
<h5>@@link@@(Last.fm)</h5>
@@lastFmWarn@@
<input type="text" style="width:150px" id="lastFmUser">
<button onclick="lastFmSet()" class="btn waves-effect" style="width:100px;">@@set@@</button>
<h5>@@templateedit@@</h5>
@@templateeditwarn@@<br>
<textarea id="np-temp" class="materialize-textarea" data-length="500">#NowPlaying {song} / {album} / {artist}