// ==UserScript== // @name LZT Music Streaming // @namespace https://greasyfork.org/ru/users/1142494-llimonix // @version 1.1 // @description Трансляция музыки с ВК и ЯМ в статус профилея Lolzteam // @author llimonix // @match https://music.yandex.ru/* // @match https://zelenka.guru/* // @match https://vk.com/* // @match https://music.youtube.com/* // @match https://developer.spotify.com/dashboard/create?type=LZTMS // @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 if (LZTMScustom_title.length > 50) { LZTMScustom_title = LZTMScustom_title.slice(0, 47) + "..."; } } XenForo.ajax('https://zelenka.guru/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 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) } 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 { GM_setValue('LZTMSdefaultSet', "true"); clearInterval(LZTMSintervalSpotify); 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 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://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)}, 3000); } } 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="homepage"]') LZTMSselectore.value = "https://github.com/llimonix"; LZTMSselectore.blur(); LZTMSselectore = document.querySelector('input[id="redirect_uris"]') LZTMSselectore.value = "https://zelenka.guru/threads/5846703/"; LZTMSselectore.blur(); if (document.querySelector('input[id="terms_accepted"]').checked == false) { document.querySelector('label[for="terms_accepted"] > 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://zelenka.guru/')) { 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)}