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

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

View File

@ -124,8 +124,8 @@
] ]
}, },
"electronDownload": { "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 --> <!-- その他 Dropdown Structure -->
<ul id="dropdown2" class="dropdown-content"> <ul id="dropdown2" class="dropdown-content">
<li> <li>
<a onclick="nowplaying('spotify');">@@NPSpotify@@</a> <a onclick="nowplaying('spotify');">NowPlaying (Spotify)</a>
</li> </li>
<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>
<li> <li>
<a onclick="schedule();">@@schedule@@</a> <a onclick="schedule();">@@schedule@@</a>

View File

@ -11,8 +11,6 @@
"cwDes":"Hide text behind warning", "cwDes":"Hide text behind warning",
"selfile":"Attach..", "selfile":"Attach..",
"insertEmoji":"Emojis", "insertEmoji":"Emojis",
"NPSpotify":"NowPlaying(Spotify)",
"NPiTunes":"NowPlaying(macOS)",
"schedule":"Scheduled toot", "schedule":"Scheduled toot",
"postat":"Post at", "postat":"Post at",
"scheduleWarn":"2.7.0~ Minimum time gap:5min(clock on the server may not be accurate.)", "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.", "linkwarn": "TheDesk save your data on thedesk.top server.",
"connect": "Connect", "connect": "Connect",
"disconnect": "Disconnect", "disconnect": "Disconnect",
"lastFmWarn": "User name...(empty to disconnect) You cannot hide your recent play log at last.fm privacy settings.",
"templateedit": "Edit a template", "templateedit": "Edit a template",
"templateeditwarn": "", "templateeditwarn": "",
"template1": "Spotify:{song}:Song name/{album}:Album name/{artist}:Artist name/{url}:URL to Spotify", "template1": "Spotify:{song}:Song name/{album}:Album name/{artist}:Artist name/{url}:URL to Spotify",

View File

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

View File

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

View File

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

View File

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

View File

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