Greasy Fork is available in English.

BCL - Boxscore button

Přidá tlačítko pod zvolený blok a po kliknutí přejde na #boxscore

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         BCL - Boxscore button
// @namespace    kvido
// @version      1.2
// @description  Přidá tlačítko pod zvolený blok a po kliknutí přejde na #boxscore
// @license      MIT
// @author       JM
// @match        https://www.championsleague.basketball/en/games*
// @match        https://www.championsleague.basketball/en/games/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
  'use strict';

  const BTN_ID = 'kvido-boxscore-btn';
  const WRAP_ID = 'kvido-boxscore-wrap';
  const TARGET_XPATH = "//*[@id='themeWrapper']/div[2]/div/div/div/div/div[2]/div/div/div/div[2]/div[2]/div/div/div[2]";

  function isGamePage() {
    return /^\/en\/games\/[^/]+/.test(location.pathname);
  }

  function goToBoxscore() {
    const url = new URL(location.href);
    url.hash = 'boxscore';
    location.href = url.toString();
  }

  function getXPathNode(xpath) {
    try {
      return document.evaluate(
        xpath,
        document,
        null,
        XPathResult.FIRST_ORDERED_NODE_TYPE,
        null
      ).singleNodeValue;
    } catch (e) {
      return null;
    }
  }

  function makeButton() {
    const btn = document.createElement('button');
    btn.id = BTN_ID;
    btn.type = 'button';
    btn.textContent = 'Boxscore';

    Object.assign(btn.style, {
      padding: '10px 14px',
      background: '#111',
      color: '#fff',
      border: 'none',
      borderRadius: '8px',
      cursor: 'pointer',
      fontSize: '14px',
      fontWeight: '700',
      boxShadow: '0 2px 8px rgba(0,0,0,0.25)'
    });

    btn.addEventListener('click', goToBoxscore);
    return btn;
  }

  function ensureButton() {
    if (!isGamePage()) return;
    if (!document.body) return;

    const target = getXPathNode(TARGET_XPATH);
    if (!target) return;

    let wrap = document.getElementById(WRAP_ID);

    if (!wrap) {
      wrap = document.createElement('div');
      wrap.id = WRAP_ID;

      Object.assign(wrap.style, {
        marginTop: '10px',
        display: 'flex',
        justifyContent: 'flex-start',
        alignItems: 'center'
      });

      wrap.appendChild(makeButton());
      target.insertAdjacentElement('afterend', wrap);
      return;
    }

    if (!document.getElementById(BTN_ID)) {
      wrap.appendChild(makeButton());
    }

    if (wrap.previousElementSibling !== target) {
      target.insertAdjacentElement('afterend', wrap);
    }
  }

  function init() {
    ensureButton();

    const observer = new MutationObserver(() => {
      ensureButton();
    });

    observer.observe(document.documentElement, {
      childList: true,
      subtree: true
    });

    setInterval(ensureButton, 1500);
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', init);
  } else {
    init();
  }
})();