SWC Events Clipboard

Adds an "Copy" button to the SWC Events page, which adds the event details to the clipboard.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         SWC Events Clipboard
// @namespace    https://www.swcombine.com/
// @version      1.2
// @description  Adds an "Copy" button to the SWC Events page, which adds the event details to the clipboard.
// @author       code-syl
// @match        https://www.swcombine.com/members/events/index.php*
// @icon         https://www.swcombine.com/favicon.ico
// @grant        none
// @license      MIT
// @require      https://greasyfork.org/scripts/383527-wait-for-key-elements/code/Wait_for_key_elements.js?version=701631
// ==/UserScript==
/* @require      https://code.jquery.com/jquery-3.6.3.min.js /* <-- enable when not using waitForKeyElements.js */

(function() {
    'use strict';

    const styles = `
        .eventmsg:not(:hover) #alani-copy { 
            display: none;
        }

        .eventmsg:hover #alani-copy,
        .eventpriv {
            align-self: center;
        }
        
        .eventpriv img {
            padding-top: 0 !important;
        }`;

    let styleSheet = document.createElement("style");
    styleSheet.innerText = styles;
    document.head.appendChild(styleSheet);

    const onCopyClick = (jNode) => {
        const swcDateTime = jNode.find('.eventdate')[0].outerText;
        const eventText = jNode.find('.eventtext')[0].outerText;

        navigator.clipboard.writeText(swcDateTime + ' ' + eventText)
            .then(() => { console.info('Copied event details to clipboard.'); })
            .catch(error => { console.error('Failed to copy event details to clipboard: ', error); });
    };

    const addCopyButton = (jNode) => {
        let button = document.createElement('button');
            button.id = 'alani-copy';
            button.textContent = 'Copy';
            button.style.height = '2rem';
            button.addEventListener('click', () => onCopyClick(jNode));

        jNode.find('.eventpriv')
             .before(button);
    }

    waitForKeyElements('.eventmsg', addCopyButton);
})();