get proto_submit_purchases_recap

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.7 kB
0
Indexable
Never

// ==UserScript==
// @name         Get proto_submit_purchases_recap from sentry context
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Copy & clean the proto_submit_purchases_recap json from sentry context (by pressing Shit+S)
// @author       Khalil Bouguerra
// @match        https://stockly.sentry.io/issues/*
// @grant        GM_setClipboard
// ==/UserScript==

function parseNested(str) {
    try {
        return JSON.parse(str, (_, val) => {
            if (typeof val === 'string'){
                return parseNested(val)
            }
            return val
        })
    } catch (exc) {
        return str
    }
};

(function() {
    'use strict';
    document.addEventListener('keydown', evt => {
                console.log("started");
        if(evt.shiftKey){
                console.log("tirggered");
            if (event.code == 'KeyS') {
                let raw_btn= Array.from(document.querySelectorAll('input[value=raw]'))[0];
                raw_btn.click();
                let proto_submit_purchases_recap = Array.from(document.getElementsByTagName('tr')).filter((tag)=> tag.firstElementChild.innerText=="proto_submit_purchases_recap")
                if (proto_submit_purchases_recap){
                    let cleaned_recap = JSON.stringify(parseNested(proto_submit_purchases_recap[0].lastElementChild.innerText),null, 4)
                    GM_setClipboard(cleaned_recap);
                    alert("proto_submit_purchases_recap copied to clipboard");
                }else{
                    alert("No proto_submit_purchases_recap found on this Sentry contex!");
                }
                raw_btn.click();

            }
        }
    }, true);
})();