Copy ASF Code Button

Adds a button to copy ASF code to clipboard

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Copy ASF Code Button
// @namespace    http://tampermonkey.net/
// @version      1.01
// @description  Adds a button to copy ASF code to clipboard
// @author       祈之羽
// @match        https://keylol.com/*
// @grant        GM_setClipboard
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    var hasSteamAppPaths = Array.from(document.querySelectorAll('a[href]')).some(link => link.href.includes('store.steampowered.com/app/'));
    if (hasSteamAppPaths) {
        var copyButton = document.createElement('button');
        copyButton.innerHTML = 'Copy ASF Code';
        copyButton.style.position = 'fixed';
        copyButton.style.top = '20px';
        copyButton.style.left = '20px';
        copyButton.style.zIndex = '9999';
        copyButton.addEventListener('click', function() {
            var links = document.querySelectorAll('a[href]');
            var numbers = new Set();
            links.forEach(function(link) {
                var match = link.href.match(/store\.steampowered\.com\/app\/(\d+)/);
                if (match) {
                    numbers.add(match[1]);
                }
            });
            var asfCode = '!addlicense asf ' + Array.from(numbers).map(number => 'a/' + number).join(',');
            GM_setClipboard(asfCode);
            alert('ASF code copied to clipboard!');
        });
        document.body.appendChild(copyButton);
    }
})();