// ==UserScript== // @name Bandcamp: Target Your Track on the List // @name:en Bandcamp: Target Your Track on the List // @name:ru Bandcamp: Найдите Ваш Трек в Списке // @name:zh Bandcamp: 锁定列表中的轨道 // @description Adds a button to the music bar that scrolls to the track you are currently listening to but have lost it // @description:en Adds a button to the music bar that scrolls to the track you are currently listening to but have lost it // @description:ru Добавляет кнопку в музыкальную панель, которая прокручивает страницу к треку, который вы сейчас слушаете, но потеряли его // @description:zh 在音乐栏中添加一个按钮,滚动到当前正在收听但已丢失的曲目 // @namespace http://tampermonkey.net/ // @version 1.3 // @author Grihail // @match https://bandcamp.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=bandcamp.com // @license CC-BY // @downloadURL https://update.greasyfork.icu/scripts/481570/Bandcamp%3A%20Target%20Your%20Track%20on%20the%20List.user.js // @updateURL https://update.greasyfork.icu/scripts/481570/Bandcamp%3A%20Target%20Your%20Track%20on%20the%20List.meta.js // ==/UserScript== (function() { 'use strict'; // Функция для прокрутки страницы к элементу с учетом процентов function scrollToElementWithPercentage(element, percentage) { const offsetTop = element.offsetTop - (window.innerHeight * percentage / 100); window.scrollTo({ top: offsetTop, behavior: 'smooth' }); } // Функция для обработки клика по кнопке function handleDivClick() { // Находим элемент с текстом текущего трека const currentTrackElement = document.querySelector('div[data-bind="text: currentTrack().title"]'); if (!currentTrackElement) return; // Получаем текст из текущего трека const currentTrackText = currentTrackElement.textContent.trim(); // Проверяем элементы .dig-deeper-item const digDeeperItems = document.querySelectorAll('.dig-deeper-items > div > .dig-deeper-item'); for (const item of digDeeperItems) { const titleElement = item.querySelector('.info > a > .title'); if (titleElement && titleElement.textContent.trim() === currentTrackText) { // Найдено совпадение, прокручиваем страницу к элементу с 50% от высоты scrollToElementWithPercentage(item, 20); return; } } // Проверяем элементы ol.collection-grid > li const collectionItems = document.querySelectorAll('ol.collection-grid > li'); for (const item of collectionItems) { const titleElement = item.querySelector('.collection-item-gallery-container > .collection-title-details > a > .collection-item-title'); if (titleElement && titleElement.textContent.trim() === currentTrackText) { // Найдено совпадение, прокручиваем страницу к элементу с 50% от высоты scrollToElementWithPercentage(item, 20); return; } } } // Функция для добавления кнопки и стиля function addButtonAndStyle() { const buttonContainer = document.querySelector('.progress-transport'); if (!buttonContainer) return; buttonContainer.style.alignItems = 'center'; // Добавляем стиль const button = document.createElement('button'); button.className = 'target-track'; // Добавляем класс target-track button.style.width = '26px'; button.style.height = '26px'; button.style.color = 'unset'; button.style.padding = '6px'; button.style.boxSizing = 'unset'; // Добавьте вашу SVG-иконку как innerHTML кнопки button.innerHTML = ''; // Добавляем обработчик клика по кнопке button.addEventListener('click', handleDivClick); // Добавляем кнопку в конец контейнера buttonContainer.appendChild(button); // Устанавливаем overflow: visible; для элемента с селектором .target-track>svg:not(:root) const svgElement = document.querySelector('.target-track>svg:not(:root)'); if (svgElement) { svgElement.style.overflow = 'visible'; } } // Вызываем функцию добавления кнопки и стиля после загрузки страницы window.addEventListener('load', addButtonAndStyle); })();