Greasy Fork

Greasy Fork is available in English.

atlassian license bulk copy

Inserts a textarea with basic license info in csv format for easy export

当前为 2024-12-12 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         atlassian license bulk copy
// @namespace    http://tampermonkey.net/
// @version      2024.12.11.6
// @description  Inserts a textarea with basic license info in csv format for easy export
// @author       You
// @match        https://my.atlassian.com/product
// @match        https://my.atlassian.com/products/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=atlassian.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    window.addEventListener("load", (event) => {

        function printlicense(n) {
            let lic = n.nextElementSibling;
            if (n.querySelector('td span.account-name') == null
                || lic.querySelector('textarea') == null
                || lic.querySelector('#sen') == null) {
                setTimeout(printlicense, 1000, n);
                return;
            }
            function getUsers(name) {
                let split_name = name.split(' ');
                let user_count_index = split_name.lastIndexOf('Users:')-1;
                if (user_count_index > 0) {
                    return split_name.at(user_count_index);
                }

                user_count_index = split_name.lastIndexOf('Agents:')-1;
                if (user_count_index > 0) {
                    return split_name.at(user_count_index);
                }
                return '';
            }
            let org = n.querySelector('td span.account-name').textContent.trim().replaceAll(',', '');
            let name = n.querySelector('span.desc').textContent.trim().replaceAll(',', '');
            let expiry = n.querySelector('td.support-expiry-date').textContent.trim().replaceAll(',', '');
            let sen = lic.querySelector('#sen').textContent.trim().replaceAll(',', '');
            let t = lic.querySelector('textarea').textContent.trim().replaceAll(',', '');
            let user_count = getUsers(name);
            let line = `${user_count},${org},${name},${expiry},${sen},${t}`.replaceAll('\n', '');
            document.getElementById('tsx-csv').textContent += line + '\n';
            console.log(line);
            window.TSX_license_count -=1 ;
        }
        function notify(message, time) {
            var popup = $(`<div >${message}</div>`);
            $('body').append(popup);

            // Style the popup (you can customize this)
            popup.css({
                'position': 'fixed',
                'bottom': '0%',
                'right': '0%',
                // 'transform': 'translate(-50%, -50%)',
                'background-color': 'red',
                'padding': '10px',
                'border': '1px solid black',
                'z-index': '1000'
            });

            // Show the popup
            popup.fadeIn();

            // Hide the popup after a delay (e.g., 3 seconds)
            setTimeout(function() {
                popup.fadeOut();
                setTimeout(function(){popup.remove();}, 50);
            }, time);
        }
        function licenseDone() {
            if (window.TSX_license_count > 0) {
                console.log("waiting for csv to complete " + window.TSX_license_count);
                notify("waiting for csv to complete " + window.TSX_license_count + ' left', 1050);
                setTimeout(licenseDone, 1000);
                return
            }
            console.log('csv is done');
            notify('csv is done', 5000);
            let d = document.getElementById('tsx-div');
            let p = document.createElement("p");
            p.textContent = 'csv is done';
            d.appendChild(p);
        }
        let form = document.querySelector("#your-licenses > section.product-list.show-paid > form");
        let d = document.createElement("div");
        d.id = 'tsx-div';
        let csv = document.createElement("textarea");
        let btn = document.createElement("button");
        let btn2 = document.createElement("button");
        csv.id = 'tsx-csv';
        csv.textContent = 'user_count,owner,app,expiry,sen,license\n';
        btn.textContent = 'Get Licenses';
        btn.addEventListener("click", function (e) {
            var wait = 0;
            for (let name of document.querySelectorAll("#your-licenses > section.product-list.show-paid > table > tbody > tr.headingRow").values().toArray().reverse()) {
                if (name.checkVisibility()) {
                    let x = (n) => {
                        n.querySelector('td > span').click();
                        setTimeout(printlicense, 1000, n);
                    }

                    window.TSX_license_count +=1 ;
                    if (window.TSX_license_count%2==0) {
                        wait += 1000;
                    }
                    console.log(1000 + wait);
                    setTimeout(x, 1200 * window.TSX_license_count, name);
                };
            };
            setTimeout(licenseDone, 1000);
        });
        btn2.textContent = 'copy csv';
        btn2.addEventListener("click", function (e) {
            navigator.clipboard.writeText(csv.textContent);
        });
        d.appendChild(csv);
        d.appendChild(btn);
        d.appendChild(btn2);
        form.after(d);
        window.TSX_license_count = 0;
    });
})();