Greasy Fork

atlassian license bulk copy

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

目前为 2024-11-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         atlassian license bulk copy
// @namespace    http://tampermonkey.net/
// @version      2024-11-27.1
// @description  Inserts a textarea with basic license info in csv format for easy export
// @author       You
// @match        https://my.atlassian.com/products/index
// @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, lic) {
            console.log('timeout', n, lic);
            if (n.querySelector('td span.account-name') == null
                || lic.querySelector('textarea') == null
                || lic.querySelector('#sen') == null) {
                setTimeout(printlicense, 1000, n, lic);
                return;
            }
            let name = n.querySelector('td span.account-name').textContent.trim().replaceAll(',', '');
            let description = 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 line = `${name},${description},${expiry},${sen},${t}`.replaceAll('\n', '');
            document.getElementById('tsx-csv').textContent += line + '\n';
            console.log(line);
        }
        let form = document.querySelector("#your-licenses > section.product-list.show-paid > form");
        let d = document.createElement("div");
        let csv = document.createElement("textarea");
        let btn = document.createElement("button");
        csv.id = 'tsx-csv';
        csv.textContent = 'owner,app,expiry,sen,license\n';
        btn.textContent = 'copy csv';
        btn.addEventListener("click", function (e) {
            navigator.clipboard.writeText(csv.textContent);
        });
        d.appendChild(csv);
        d.appendChild(btn);
        form.after(d);
        for (let name of document.querySelectorAll("#your-licenses > section.product-list.show-paid > table > tbody > tr.headingRow")) {
            if (name.checkVisibility()) {
                name.querySelector('td > span').click();
                let lic = name.nextElementSibling;
                setTimeout(printlicense, 1000, name, lic);
            };
        };
    });
})();