var cssData = {atf: "", subsAtf: ""}; var i = 0; var links = []; var newTab;
window.addEventListener("storage", function(event) { if (event.key === "ready" && event.newValue === "true") { localStorage.removeItem("ready"); localStorage.setItem("cssData", JSON.stringify(cssData)); }
if (event.key === "atfCssData" && event.newValue) { cssData = JSON.parse(event.newValue); localStorage.removeItem("atfCssData"); newTab.close(); i++; createTab(); } });
// Recursively open one tab at a time to get the ATF CSS. // When we're out of links, add the resulting CSS into the appropriate divs. function createTab() { if ( i < links.length ) { let url = links[i] + '?pagemode=Preview'; newTab = window.open(url, '_blank'); } else { document.querySelector( "[data-role='atf']" ).innerText = cssData.atf; document.querySelector( "[data-role='subsAtf']" ).innerText = cssData.subsAtf; } } // Function that opens new tabs with provided URLs and establishes web socket connections function generateATF() { // Get the value of the input with ID "Links" and parse it into an array let els = Array.from( document.querySelectorAll( '#Links li > a' ) );
// Get the href values and store them in the links array. els.forEach( el => { links.push( el.href ); } );
// If we have links, start running them. if ( links ) createTab();
}
// Add an event listener to the button with data-role="gen" to call the generateATF function document.querySelector("[data-role='gen-atf']").addEventListener("click", generateATF);
// Copy to clipboard function copyPath1() { copyToClip( 1 ); }
function copyPath2() { copyToClip( 2 ); }
function copyToClip( SWITCH ) {
console.log("copied")
let copyItem;
SWITCH == 1 ? copyItem = document.querySelector( "[data-role='atf']" ) : copyItem = document.querySelector( "[data-role='subsAtf']" );
navigator.clipboard.writeText(copyItem.innerText);
} document.querySelector("[data-role='copy-1']").addEventListener("click", copyPath1); document.querySelector("[data-role='copy-2']").addEventListener("click", copyPath2);