Greasy Fork is available in English.
Трансляция музыки с ВК и ЯМ в статус профилея Lolzteam
当前为
// ==UserScript==
// @name LZT Music Streaming
// @namespace http://greasyfork.icu/ru/users/1142494-llimonix
// @version 1.0
// @description Трансляция музыки с ВК и ЯМ в статус профилея Lolzteam
// @author llimonix
// @match https://music.yandex.ru/*
// @match https://zelenka.guru/*
// @match https://vk.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
// ==/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') {
console.log(GM_getValue('LZTMSactiveService', 0))
clearInterval(GM_getValue('LZTMSintervalYM', ''));
}
}
function LZTMSexecuteScriptVK(LZTMSrandomStringVK, LZTMSintervalVK) {
if (GM_getValue('LZTMSintervalVK', '0') != LZTMSrandomStringVK) {
clearInterval(LZTMSintervalVK)
}
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') {
console.log(GM_getValue('LZTMSintervalVK', ''));
clearInterval(GM_getValue('LZTMSintervalVK', ''));
}
}
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('LZTMSactiveService', 0) === 'ym') {
var LZTMSrandomStringYM = LZTMSgenerateRandomString(10);
GM_setValue('LZTMSintervalYM', LZTMSrandomStringYM)
var LZTMSintervalYM = setInterval(function() {
LZTMSexecuteScriptYM(LZTMSrandomStringYM, LZTMSintervalYM)}, 1000);
}
}
if (window.location.href.startsWith('https://vk.com/')) {
console.log(window.location.href)
if (GM_getValue('LZTMSactiveService', 0) === 'vk') {
var LZTMSrandomStringVK = LZTMSgenerateRandomString(10);
GM_setValue('LZTMSintervalVK', LZTMSrandomStringVK)
var LZTMSintervalVK = setInterval(function() {
LZTMSexecuteScriptVK(LZTMSrandomStringVK, LZTMSintervalVK)}, 1000);
}
}
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');
if (LZTMSmodalBackdrops.length > 0) {
LZTMSmodalBackdrops[LZTMSmodalBackdrops.length - 1].remove();
}
var LZTMSdefaultStatus = GM_getValue('LZTMSdefaultStatus', '');
var LZTMScontentMenu = `<h3 class="textHeading" style="margin-left: 30px;">Музыкальный сервис</h3><li style="margin-left: 30px;"><input type="checkbox" id="lzt_music_active"><label for="lzt_music_active">Включить трансляцию музыки в статус</label></li><ul style="display: flex; flex-direction: column; padding-bottom: 10px; margin-left: 50px;"><li style="list-style-type: none;"><label for="lzt_musicStreaming_vk"><input type="radio" name="lzt_music_service" id="lzt_musicStreaming_vk" value="vk"> ВК Музыка</label></li><li style="list-style-type: none;"><label for="lzt_musicStreaming_ym"><input type="radio" name="lzt_music_service" id="lzt_musicStreaming_ym" value="ym"> Яндекс.Музыка</label></li></ul><h3 class="textHeading" style="margin-left: 30px;">Настройки</h3><dl style="display: flex;align-items: center; margin-left: 30px;"><dt><label>Статус по умолчанию:</label></dt><dd><input style="width: 100%;" placeholder="..." id="lzt_music_defaultstatus" value="${LZTMSdefaultStatus}" class="textCtrl"></dd></dl><p style="margin-left: 30px; color: #626262">Статус, который будет отображаться когда музыка на паузе или музыкальный сервис неактивен</p><div style="display: flex;padding-top: 30px;flex-direction: column;"><button class="button" id="lzt_music_cache_reset" style="margin-bottom: 10px;">Очистить кеш</button><button class="button primary close OverlayCloser" id="lzt_music_save">Сохранить</button></div>`;
XenForo.alert(LZTMScontentMenu, 'LZT Music Streaming');
document.getElementById("lzt_music_save").addEventListener("click", function() {
MusicStreamingSave();
});
document.getElementById("lzt_music_cache_reset").addEventListener("click", function() {
MusicStreamingCacheReset();
});
if (GM_getValue('LZTMSactiveStatus', "notchecked") === 'checked') {
document.getElementById("lzt_music_active").checked = true;
}
if (GM_getValue('LZTMSactiveService', 0) === 'vk') {
document.getElementById("lzt_musicStreaming_vk").checked = true;
} else if (GM_getValue('LZTMSactiveService', 0) === 'ym') {
document.getElementById("lzt_musicStreaming_ym").checked = true;
} else {
document.getElementById("lzt_musicStreaming_vk").checked = false;
document.getElementById("lzt_musicStreaming_ym").checked = false;
}
}
function MusicStreamingSave() {
var LZTMSactiveStatus = document.getElementById("lzt_music_active");
var LZTMSactiveService = document.getElementsByName("lzt_music_service");
if (LZTMSactiveStatus.checked) {
if (LZTMSactiveService[0].checked) {
GM_setValue('LZTMSactiveService', 'vk');
} else if (LZTMSactiveService[1].checked) {
GM_setValue('LZTMSactiveService', 'ym');
} else {
XenForo.alert('Ошибка: выберите музыкальный сервис', 1, 5000)
return
}
}
if (LZTMSactiveStatus.checked) {
GM_setValue('LZTMSactiveStatus', 'checked');
} else {
GM_setValue('LZTMSactiveStatus', 'notchecked');
}
var LZTMSdefaultStatus = document.getElementById('lzt_music_defaultstatus').value;
GM_setValue('LZTMSdefaultStatus', LZTMSdefaultStatus);
XenForo.alert('Успешно: параметры сохранены', 1, 5000)
}
function MusicStreamingCacheReset() {
GM_deleteValue('LZTMSready_track');
GM_deleteValue('LZTMSdefaultSet');
GM_deleteValue('LZTMSartist');
GM_deleteValue('LZTMStrack');
GM_deleteValue('LZTMScountDefault');
GM_deleteValue('LZTMSrandomStringYM');
GM_deleteValue('LZTMSrandomStringVK');
GM_deleteValue('LZTMSrandomStringLOLZ');
XenForo.alert('Успешно: кеш музыкальных сервисов сброшен', 1, 5000)
}
var accountMenu = document.querySelector('#AccountMenu > ul > li:nth-child(1) > a');
if (accountMenu) {
var newMenuItem = document.createElement('li');
newMenuItem.innerHTML = '<a id="MusicStreamingMenu">Music Streaming</a>';
accountMenu.parentNode.insertBefore(newMenuItem, accountMenu.nextSibling);
var separator = document.createElement('div');
separator.className = 'account-menu-sep';
accountMenu.parentNode.insertBefore(separator, newMenuItem);
document.getElementById("MusicStreamingMenu").addEventListener("click", function() {
MusicStreamingMenu();
});
}
if (GM_getValue('LZTMSactiveStatus', "notchecked") === 'checked') {
var LZTMSrandomStringLOLZ = LZTMSgenerateRandomString(10);
GM_setValue('LZTMSintervalLOLZ', LZTMSrandomStringLOLZ)
var LZTMSintervalLOLZ = setInterval(function() {
LZTMSexecuteScriptLolz(LZTMSrandomStringLOLZ, LZTMSintervalLOLZ)}, 1000);
}
}
});
})();