Greasy Fork is available in English.

Activation and Login Code Library

A library for generating, storing, and exposing activation and login codes for other scripts.

بۇ قوليازمىنى بىۋاسىتە قاچىلاشقا بولمايدۇ. بۇ باشقا قوليازمىلارنىڭ ئىشلىتىشى ئۈچۈن تەمىنلەنگەن ئامبار بولۇپ، ئىشلىتىش ئۈچۈن مېتا كۆرسەتمىسىگە قىستۇرىدىغان كود: // @require https://update.greasyfork.org/scripts/522177/1511398/Activation%20and%20Login%20Code%20Library.js

// ==UserScript==
// @name         Activation & Login Code Library
// @namespace    https://example.com/
// @version      1.1
// @description  A reusable library for injecting and storing activation and login codes.
// @author       xiangye
// @license      Apache 2.0
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const StorageKeys = {
        ACTIVATION_CODE: 'activation_code',
        LOGIN_CODE: 'login_code',
        EXPIRY_TIME: 'activation_expiry'
    };

    // Helper: Generate a secure activation code
    function generateActivationCode() {
        const timestamp = Date.now().toString(36); // Base36 timestamp for compactness
        const randomPart = Array.from({ length: 8 }, () =>
            Math.random().toString(36).charAt(2).toUpperCase()
        ).join('');
        return `KEY-${timestamp}-${randomPart}`;
    }

    // Helper: Store data with an optional expiry time
    function storeData(key, value, durationInMs = null) {
        const data = { value };
        if (durationInMs) {
            data.expiry = Date.now() + durationInMs;
        }
        try {
            localStorage.setItem(key, JSON.stringify(data));
        } catch (e) {
            console.error(`Failed to store data for key: ${key}`, e);
        }
    }

    // Helper: Retrieve data and check expiry
    function retrieveData(key) {
        const rawData = localStorage.getItem(key);
        if (!rawData) return null;

        try {
            const data = JSON.parse(rawData);
            if (data.expiry && Date.now() > data.expiry) {
                localStorage.removeItem(key);
                return null;
            }
            return data.value;
        } catch (e) {
            console.error(`Failed to parse stored data for key: ${key}`, e);
            return null;
        }
    }

    // Inject and store activation code with selectable duration
    function injectActivationCode(durationOption) {
        const durations = {
            "1week": 7 * 24 * 60 * 60 * 1000,
            "1month": 30 * 24 * 60 * 60 * 1000,
            "3months": 90 * 24 * 60 * 60 * 1000,
            "6months": 180 * 24 * 60 * 60 * 1000,
            "1year": 365 * 24 * 60 * 60 * 1000,
            "forever": null
        };

        const durationInMs = durations[durationOption];
        if (durationInMs === undefined) {
            throw new Error("Invalid duration option");
        }

        const activationCode = generateActivationCode();
        storeData(StorageKeys.ACTIVATION_CODE, activationCode, durationInMs);

        return activationCode;
    }

    // Inject and store a custom login code
    function injectLoginCode(loginCode) {
        if (!loginCode || typeof loginCode !== 'string') {
            throw new Error("Invalid login code");
        }
        storeData(StorageKeys.LOGIN_CODE, loginCode);
    }

    // Public API for external use
    window.ActivationLibrary = {
        injectActivationCode,
        injectLoginCode,
        getActivationCode: () => retrieveData(StorageKeys.ACTIVATION_CODE),
        getLoginCode: () => retrieveData(StorageKeys.LOGIN_CODE)
    };

    console.log("Activation & Login Code Library initialized (v1.1).");
})();