Skip to main content

Documentation Index

Fetch the complete documentation index at: https://bym.lonestill.uk/llms.txt

Use this file to discover all available pages before exploring further.

Показывает Artist — Title в заголовке окна браузера. При паузе добавляет иконку ⏸.
BYM.register({
  id: 'now-playing-title',
  name: 'Now Playing Title',
  version: '1.1.0',
  description: 'Показывает текущий трек в заголовке окна.',
  author: 'BYM',
  settings: [
    { key: 'format',    type: 'select',  label: 'Формат',       default: 'artist — title',
      options: ['artist — title', 'title — artist', 'title'] },
    { key: 'pauseIcon', type: 'boolean', label: 'Иконка паузы', default: true },
  ],
}, (api, getSetting) => {
  let interval    = null;
  let paused      = false;
  const origTitle = document.title;

  function getTrackInfo() {
    const ms = navigator.mediaSession?.metadata;
    if (ms?.title) return { title: ms.title, artist: ms.artist || '' };

    const titleEl  = document.querySelector('[class*="TrackTitle"] a, [class*="TrackTitle"] span');
    const artistEl = document.querySelector('[class*="TrackArtists"] a, [class*="TrackArtists"] span');
    const title    = titleEl?.textContent?.trim();
    return title ? { title, artist: artistEl?.textContent?.trim() || '' } : null;
  }

  function update(forcePaused) {
    const info = getTrackInfo();
    if (!info) return;

    const isPaused = forcePaused !== undefined ? forcePaused : paused;
    const fmt      = getSetting('format') ?? 'artist — title';
    const icon     = (getSetting('pauseIcon') !== false) && isPaused ? '⏸ ' : '';

    let text;
    if (fmt === 'title')               text = info.title;
    else if (fmt === 'title — artist') text = info.artist ? `${info.title}${info.artist}` : info.title;
    else                               text = info.artist ? `${info.artist}${info.title}` : info.title;

    document.title = icon + text;
  }

  return {
    start() {
      interval = setInterval(update, 1000);
      api.Events.on('play',  () => { paused = false; update(false); });
      api.Events.on('pause', () => { paused = true;  update(true);  });
    },
    stop() {
      clearInterval(interval);
      api.Events.off('play');
      api.Events.off('pause');
      document.title = origTitle;
    },
  };
});
Использованные API: api.Events, api.Player, api.DOM, settings