// ==UserScript== // @name LZT Music Streaming // @namespace https://greasyfork.org/ru/users/1142494-llimonix // @version 1.3.3 // @description Трансляция музыки с ВК и ЯМ в статус профилея Lolzteam // @author llimonix // @match https://music.yandex.ru/* // @match https://lolz.live/* // @match https://vk.com/* // @match https://music.youtube.com/* // @match https://developer.spotify.com/dashboard/create?type=LZTMS // @match https://soundcloud.com/* // @icon https://cdn-icons-png.flaticon.com/512/3845/3845874.png // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @run-at document-start // @downloadURL none // ==/UserScript== (function() { document.addEventListener("DOMContentLoaded", () => { function LZTMSgenerateRandomString(length) { const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; let result = ''; for (let i = 0; i < length; i++) { const randomIndex = Math.floor(Math.random() * characters.length); result += characters.charAt(randomIndex); } return result; } function LZTMSupdateStatusLive(LZTMSstatusLive) { var LZTMSliveStatusEdit = document.querySelector('[data-edit-url="account/status-update"]'); if (LZTMSliveStatusEdit) { LZTMSliveStatusEdit.textContent = LZTMSstatusLive } } function LZTMSupdateStatus() { var LZTMSartist = GM_getValue('LZTMSartist', "false") var LZTMStrack = GM_getValue('LZTMStrack', "false") var LZTMScustom_title = GM_getValue('LZTMSdefaultStatus', '') GM_setValue('LZTMSready_track', "false"); if (GM_getValue('LZTMSdefaultSet', "false") == "false") { LZTMScustom_title = '♫ ' + LZTMSartist + ' - ' + LZTMStrack while (LZTMScustom_title.length > 50) { console.log(LZTMScustom_title); console.log(LZTMSartist); if (LZTMSartist.split(", ").length > 1) { var LZTMSartist_list = LZTMSartist.split(", ").slice(0, -1); var LZTMSartist_slice = ""; LZTMSartist_list.forEach(function(element) { LZTMSartist_slice += element + ', '; }); LZTMSartist_slice = LZTMSartist_slice.slice(0, -2); LZTMScustom_title = '♫ ' + LZTMSartist_slice + ' - ' + LZTMStrack } else { LZTMScustom_title = LZTMScustom_title.slice(0, 47) + "..."; } } } XenForo.ajax('https://lolz.live/account/status-update', { custom_title: LZTMScustom_title }).then(function(data) { if (GM_getValue('LZTMSdefaultSet', "false") == "false") { GM_setValue('LZTMSstatus_track', `♫ ${LZTMSartist} - ${LZTMStrack}`); LZTMSupdateStatusLive(LZTMScustom_title); } else { GM_setValue('LZTMSstatus_track', GM_getValue('LZTMSdefaultStatus', '')); LZTMSupdateStatusLive(GM_getValue('LZTMSdefaultStatus', '')); } }) } function LZTMSexecuteScriptYM(LZTMSrandomStringYM, LZTMSintervalYM) { if (GM_getValue('LZTMSintervalYM', '0') != LZTMSrandomStringYM) { clearInterval(LZTMSintervalYM) } var LZTMSartistElement = document.querySelectorAll('.d-artists.d-artists__expanded a.d-link.deco-link'); var LZTMStrackElement = document.querySelector('.track__name-innerwrap a.d-link.deco-link.track__title'); var LZTMSpauseElement = document.querySelector('.player-controls .player-controls__btn_pause'); if (LZTMSpauseElement == null) { GM_setValue('LZTMSdefaultSet', "true"); } else { GM_setValue('LZTMSdefaultSet', "false"); } if (LZTMSartistElement && LZTMStrackElement) { var LZTMSartist = ''; LZTMSartistElement.forEach(function(element) { LZTMSartist += element.textContent + ', '; }); LZTMSartist = LZTMSartist.slice(0, -2); var LZTMStrack = LZTMStrackElement.textContent; GM_setValue('LZTMSartist', LZTMSartist); GM_setValue('LZTMStrack', LZTMStrack); GM_setValue('LZTMSready_track', "true"); } if(GM_getValue('LZTMSactiveService', 0) !== 'ym') { clearInterval(LZTMSintervalYM); } } function LZTMSexecuteScriptVK(LZTMSrandomStringVK, LZTMSintervalVK) { if (GM_getValue('LZTMSintervalVK', '0') != LZTMSrandomStringVK) { clearInterval(LZTMSintervalVK) } var LZTMSplayerElement = document.querySelector('.top_audio_player.top_audio_player_enabled'); if (LZTMSplayerElement) { var LZTMSartistElement = document.querySelector('.top_audio_player_title'); var LZTMStrackElement = document.querySelector('.top_audio_player_title'); var LZTMSpauseElement = document.querySelector('.top_audio_player_playing'); if (LZTMSpauseElement == null) { GM_setValue('LZTMSdefaultSet', "true"); } else { GM_setValue('LZTMSdefaultSet', "false"); } if (LZTMSartistElement && LZTMStrackElement) { var LZTMSartist = (LZTMSartistElement.textContent).split(' — ')[0]; var LZTMStrack = (LZTMStrackElement.textContent).split(' — ')[1]; GM_setValue('LZTMSartist', LZTMSartist); GM_setValue('LZTMStrack', LZTMStrack); GM_setValue('LZTMSready_track', "true"); } } if(GM_getValue('LZTMSactiveService', 0) !== 'vk') { clearInterval(LZTMSintervalVK); } } function LZTMSexecuteScriptYTM(LZTMSrandomStringYTM, LZTMSintervalYTM) { if (GM_getValue('LZTMSintervalYTM', '0') != LZTMSrandomStringYTM) { clearInterval(LZTMSintervalYTM) } var LZTMSplayerElement = document.querySelector('[slot="player-bar"]') if (LZTMSplayerElement) { var LZTMSartistElement = document.querySelectorAll('.ytmusic-player-bar .yt-simple-endpoint'); var LZTMStrackElement = document.querySelector('.ytmusic-player-bar .ytmusic-player-bar.title'); var LZTMSpauseElement = document.querySelector('.ytmusic-player-bar .ytmusic-player-bar .play-pause-button #icon path'); if (LZTMSpauseElement) { if (LZTMSpauseElement.getAttribute('d') == "M6,4l12,8L6,20V4z") { GM_setValue('LZTMSdefaultSet', "true"); } else { GM_setValue('LZTMSdefaultSet', "false"); } } else { GM_setValue('LZTMSdefaultSet', "true"); } if (LZTMSartistElement && LZTMStrackElement) { var LZTMSartist = ''; LZTMSartistElement.forEach(function(element) { if (element.getAttribute('href').startsWith('channel')) { LZTMSartist += element.textContent + ', '; }; }); LZTMSartist = LZTMSartist.slice(0, -2); var LZTMStrack = LZTMStrackElement.textContent GM_setValue('LZTMSartist', LZTMSartist); GM_setValue('LZTMStrack', LZTMStrack); GM_setValue('LZTMSready_track', "true"); } } if(GM_getValue('LZTMSactiveService', 0) !== 'ytm') { clearInterval(LZTMSintervalYTM); } } function LZTMSexecuteScriptSCD(LZTMSrandomStringSCD, LZTMSintervalSCD) { console.log(321); if (GM_getValue('LZTMSintervalSCD', '0') != LZTMSrandomStringSCD) { clearInterval(LZTMSintervalSCD) } var LZTMSplayerElement = document.querySelector('.playControls__elements') if (LZTMSplayerElement) { var LZTMSartistElement = document.querySelector('a.playbackSoundBadge__lightLink').textContent; var LZTMStrackElement = document.querySelector("a.playbackSoundBadge__titleLink span[aria-hidden='true']").textContent; var LZTMSpauseElement = document.querySelector('button.playControl'); console.log(LZTMSartistElement); console.log(LZTMStrackElement); console.log(LZTMSpauseElement); if (LZTMSpauseElement.classList.contains('playing')) { GM_setValue('LZTMSdefaultSet', "false"); } else { GM_setValue('LZTMSdefaultSet', "true"); } if (LZTMSartistElement && LZTMStrackElement) { var LZTMSartist = LZTMSartistElement; var LZTMStrack = LZTMStrackElement; GM_setValue('LZTMSartist', LZTMSartist); GM_setValue('LZTMStrack', LZTMStrack); GM_setValue('LZTMSready_track', "true"); } } if(GM_getValue('LZTMSactiveService', 0) !== 'scd') { clearInterval(LZTMSintervalSCD); } } function LZTMSexecuteScriptSpotify(LZTMSrandomStringSpotify, LZTMSintervalSpotify) { if (GM_getValue('LZTMSintervalSpotify', '0') != LZTMSrandomStringSpotify) { clearInterval(LZTMSintervalSpotify) } if (GM_getValue('LZTMScodespotifyAPI', "ready") == "ready" || GM_getValue('LZTMScodespotifyAPI', "ready") == "") { XenForo.alert('Ошибка: не указан API токен Spotify!', 1, 5000) GM_setValue('LZTMSdefaultSet', "true"); clearInterval(LZTMSintervalSpotify); } else { fetch('https://api.spotify.com/v1/me/player', { headers: { 'Authorization': `Bearer ${GM_getValue('LZTMScodespotifyAPI', "ready")}` } }) .then(response => { if (response.status == 200) { return response.json(); } else if (response.status == 401) { var data = new URLSearchParams({ 'grant_type': 'refresh_token', 'refresh_token': GM_getValue('LZTMSrefreshTokenSpotify', '') }); var basicAuth = btoa(`${GM_getValue('LZTMSclientIDspotify', '')}:${GM_getValue('LZTMSclientSecretspotify', '')}`); var requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': `Basic ${basicAuth}`, }, body: data, }; return fetch("https://accounts.spotify.com/api/token", requestOptions) .then(response => response.json()) .then(token_data => { var access_token = token_data.access_token; var refresh_token = token_data.refresh_token || ''; GM_setValue('LZTMScodespotifyAPI', access_token); if (refresh_token != '') { GM_setValue('LZTMSrefreshTokenSpotify', refresh_token); } return null; }); } else if (response.status == 204) { clearInterval(LZTMSintervalSpotify); return null; } else { XenForo.alert('Ошибка: Spotify выдал ошибку!', 1, 5000) return null; } }) .then(data => { if (data != null) { var LSTMSpaused = data.is_playing; if (LSTMSpaused == false) { GM_setValue('LZTMSdefaultSet', "true"); } else { var LZTMStrack = data.item.name; var LZTMSartistMAP = data.item.artists; var LZTMSartist = LZTMSartistMAP.map(artist => artist.name).join(', '); GM_setValue('LZTMSartist', LZTMSartist); GM_setValue('LZTMStrack', LZTMStrack); GM_setValue('LZTMSready_track', "true"); GM_setValue('LZTMSdefaultSet', "false"); if (GM_getValue('LZTMSactiveService', 0) !== 'spotify') { clearInterval(LZTMSintervalSpotify); } } } }) .catch(error => { XenForo.alert('Ошибка: не удалось получить и сохранить Ваш токен!', 1, 10000); console.error(`Error: ${error}`); }); } } function LZTMSexecuteScriptLFM(LZTMSrandomStringLFM, LZTMSintervalLFM) { if (GM_getValue('LZTMSintervalLFM', '0') != LZTMSrandomStringLFM) { clearInterval(LZTMSintervalLFM) } if (GM_getValue('LZTMSlastfmAPI', "ready") == "ready" || GM_getValue('LZTMSlastfmNAME', "ready") == "") { XenForo.alert('Ошибка: не указан API Key или имя сервиса Last.fm!', 1, 5000) clearInterval(LZTMSintervalLFM); } else { fetch(`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${GM_getValue('LZTMSlastfmNAME', '')}&api_key=${GM_getValue('LZTMSlastfmAPI', '')}&format=json&limit=1`, {}) .then(response => { if (response.status == 200) { return response.json(); } else if (response.status == 403) { XenForo.alert('Ошибка: некорректно указан API Key сервиса Last.fm или возникла другая ошибка!!', 1, 5000) GM_setValue('LZTMSdefaultSet', "true"); clearInterval(LZTMSintervalLFM); return null; } else if (response.status == 404) { XenForo.alert('Ошибка: некорректно указано имя пользователя сервиса Last.fm или возникла другая ошибка!', 1, 5000) GM_setValue('LZTMSdefaultSet', "true"); clearInterval(LZTMSintervalLFM); return null; } else { XenForo.alert('Ошибка: Last.fm выдал ошибку!', 1, 5000) clearInterval(LZTMSintervalSpotify); return null; } }) .then(data => { if (data != null) { if (data.recenttracks && data.recenttracks.track[0]['@attr']) { var LZTMStrack = data.recenttracks.track[0].name; var LZTMSartist = data.recenttracks.track[0].artist["#text"]; /* var LZTMSartist = LZTMSartistMAP.map(artist => artist.name).join(', '); */ GM_setValue('LZTMSartist', LZTMSartist); GM_setValue('LZTMStrack', LZTMStrack); GM_setValue('LZTMSready_track', "true"); GM_setValue('LZTMSdefaultSet', "false"); if (GM_getValue('LZTMSactiveService', 0) !== 'lfm') { clearInterval(LZTMSintervalLFM); } } else { GM_setValue('LZTMSdefaultSet', "true"); } } }) .catch(error => { XenForo.alert('Ошибка: Last.fm выдал ошибку!', 1, 10000); console.error(`Error: ${error}`); GM_setValue('LZTMSdefaultSet', "true"); clearInterval(LZTMSintervalLFM); }); } } function LZTMSexecuteScriptLolz(LZTMSrandomStringLOLZ, LZTMSintervalLOLZ) { if (GM_getValue('LZTMSintervalLOLZ', '0') != LZTMSrandomStringLOLZ) { clearInterval(LZTMSintervalLOLZ) } if (GM_getValue('LZTMSready_track', "false") == "true") { var LZTMSstatus = GM_getValue('LZTMSstatus_track', "false") var LZTMSstatus_req if (GM_getValue('LZTMSdefaultSet', "false") == "false") { LZTMSstatus_req = '♫ ' + GM_getValue('LZTMSartist', "false") + ' - ' + GM_getValue('LZTMStrack', "false") } else { LZTMSstatus_req = GM_getValue('LZTMSdefaultStatus', '') } GM_setValue('LZTMScountDefault', 0); if (LZTMSstatus != LZTMSstatus_req) { LZTMSupdateStatus(); } else { GM_setValue('LZTMSready_track', "false"); } } else { GM_setValue('LZTMScountDefault', GM_getValue('LZTMScountDefault', 0) + 1); if (GM_getValue('LZTMScountDefault', 0) > 10 && (GM_getValue('LZTMSdefaultSet', "false") == "false" || GM_getValue('LZTMSdefaultStatus', '') != GM_getValue('LZTMSstatus_track', ''))) { GM_setValue('LZTMScountDefault', 1); GM_setValue('LZTMSdefaultSet', "true"); GM_setValue('LZTMSready_track', "true"); } else if (GM_getValue('LZTMScountDefault', 0) > 10 && GM_getValue('LZTMSdefaultSet', "false") == "true") { GM_setValue('LZTMScountDefault', 1); } } } if (window.location.href.startsWith('https://music.yandex.ru/') && !window.location.href.startsWith('https://music.yandex.ru/api/')) { if (GM_getValue('LZTMSactiveStatus', "notchecked") == "checked") { if (GM_getValue('LZTMSactiveService', 0) === 'ym') { var LZTMSrandomStringYM = LZTMSgenerateRandomString(10); GM_setValue('LZTMSintervalYM', LZTMSrandomStringYM) var LZTMSintervalYM = setInterval(function() { LZTMSexecuteScriptYM(LZTMSrandomStringYM, LZTMSintervalYM)}, 3000); } } } if (window.location.href.startsWith('https://vk.com/')) { if (GM_getValue('LZTMSactiveStatus', "notchecked") == "checked") { if (GM_getValue('LZTMSactiveService', 0) === 'vk') { var LZTMSrandomStringVK = LZTMSgenerateRandomString(10); GM_setValue('LZTMSintervalVK', LZTMSrandomStringVK) var LZTMSintervalVK = setInterval(function() { LZTMSexecuteScriptVK(LZTMSrandomStringVK, LZTMSintervalVK)}, 3000); } } } if (window.location.href.startsWith('https://soundcloud.com/')) { console.log(123); if (GM_getValue('LZTMSactiveStatus', "notchecked") == "checked") { if (GM_getValue('LZTMSactiveService', 0) === 'scd') { var LZTMSrandomStringSCD = LZTMSgenerateRandomString(10); GM_setValue('LZTMSintervalSCD', LZTMSrandomStringSCD) var LZTMSintervalSCD = setInterval(function() { LZTMSexecuteScriptSCD(LZTMSrandomStringSCD, LZTMSintervalSCD)}, 3000); } } } if (window.location.href.startsWith('https://music.youtube.com/')) { if (GM_getValue('LZTMSactiveStatus', "notchecked") == "checked") { if (GM_getValue('LZTMSactiveService', 0) === 'ytm') { var LZTMSrandomStringYTM = LZTMSgenerateRandomString(10); GM_setValue('LZTMSintervalYTM', LZTMSrandomStringYTM) var LZTMSintervalYTM = setInterval(function() { LZTMSexecuteScriptYTM(LZTMSrandomStringYTM, LZTMSintervalYTM)}, 3000); } } } if (GM_getValue('LZTMSactiveService', 0) === 'spotify') { if (GM_getValue('LZTMSactiveStatus', "notchecked") == "checked") { var LZTMSrandomStringSpotify = LZTMSgenerateRandomString(10); GM_setValue('LZTMSintervalSpotify', LZTMSrandomStringSpotify) var LZTMSintervalSpotify= setInterval(function() { LZTMSexecuteScriptSpotify(LZTMSrandomStringSpotify, LZTMSintervalSpotify)}, 5000); } } if (GM_getValue('LZTMSactiveService', 0) === 'lfm') { if (GM_getValue('LZTMSactiveStatus', "notchecked") == "checked") { var LZTMSrandomStringLFM = LZTMSgenerateRandomString(10); GM_setValue('LZTMSintervalLFM', LZTMSrandomStringLFM) var LZTMSintervalLFM = setInterval(function() { LZTMSexecuteScriptLFM(LZTMSrandomStringLFM, LZTMSintervalLFM)}, 5000); } } if (window.location.href.startsWith('https://developer.spotify.com/dashboard/create?type=LZTMS')) { var LZTMSselectore function MusicStreamingMenu() { if (document.querySelector('input[id="name"]')) { LZTMSselectore = document.querySelector('input[id="name"]'); LZTMSselectore.value = "LZT Music Streaming"; LZTMSselectore.blur(); LZTMSselectore = document.querySelector('textarea[id="description"]'); LZTMSselectore.value = "Транслируем музыку в статус профиля LOLZTEAM, играющую в Spotify"; LZTMSselectore.blur(); LZTMSselectore = document.querySelector('input[id="website"]') LZTMSselectore.value = "https://github.com/llimonix"; LZTMSselectore.blur(); LZTMSselectore = document.querySelector('input[id="newRedirectUri"]') LZTMSselectore.value = "https://lolz.live/threads/5846703/"; LZTMSselectore.blur(); if (document.querySelector('input[id="termsAccepted"]').checked == false) { document.querySelector('label[for="termsAccepted"] > span:nth-child(1)').click(); return true } return false } } var LZTMSintervalSpotifyDeveloper = setInterval(function() { var LZTMSintervalSpotifyStatus = MusicStreamingMenu(); if (LZTMSintervalSpotifyStatus == true) { clearInterval(LZTMSintervalSpotifyDeveloper); } }, 500); } if (window.location.href.startsWith('https://lolz.live/')) { function MusicStreamingMenu() { document.querySelectorAll('div.modal.fade').forEach(el => el.remove()); var LZTMSmodalBackdrops = document.querySelectorAll('div.modal-backdrop'); var LSTMScodeSpotifyAPI = GM_getValue('LZTMScodespotifyAPI', ""); if (LZTMSmodalBackdrops.length > 0) { LZTMSmodalBackdrops[LZTMSmodalBackdrops.length - 1].remove(); } var LZTMSdefaultStatus = GM_getValue('LZTMSdefaultStatus', ''); var LZTMScontentMenu = `
Статус, который будет отображаться когда музыка на паузе или музыкальный сервис неактивен
LZTMSready_track: ${GM_getValue('LZTMSready_track', false)}
LZTMSdefaultSet: ${GM_getValue('LZTMSdefaultSet', false)}
LZTMSartist: ${GM_getValue('LZTMSartist', false)}
LZTMStrack: ${GM_getValue('LZTMStrack', false)}
LZTMScountDefault: ${GM_getValue('LZTMScountDefault', false)}
LZTMSrandomStringYM: ${GM_getValue('LZTMSrandomStringYM', false)}
LZTMSrandomStringVK: ${GM_getValue('LZTMSrandomStringVK', false)}
LZTMSrandomStringYTM: ${GM_getValue('LZTMSrandomStringYTM', false)}
LZTMSrandomStringSpotify: ${GM_getValue('LZTMSrandomStringSpotify', false)}
LZTMSdefaultStatus: ${GM_getValue('LZTMSdefaultStatus', false)}