Skip to content

Commit

Permalink
feat: add copy path to clipboard button to ipsw ent --ui UI
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Sep 29, 2024
1 parent a4b0e83 commit 6d20411
Showing 1 changed file with 61 additions and 6 deletions.
67 changes: 61 additions & 6 deletions internal/commands/ent/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@
color: #2e3440;
/* Polar Night text */
}

.entitlement-button {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
padding: 1rem;
}

.entitlement-text {
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
padding-right: 1rem;
text-align: left; /* Add this line to left-justify the text */
}

.copy-btn {
flex-shrink: 0;
}
</style>
</head>

Expand Down Expand Up @@ -140,21 +161,55 @@ <h1 class="text-3xl font-bold mb-6 text-center text-nord-frost">Entitlement Data
const entitlementItem = document.createElement('div');
entitlementItem.className = 'bg-nord-light rounded shadow-md';

const highlightedKey = highlightMatches(key, searchTerm);

const entitlementButton = document.createElement('button');
entitlementButton.className = 'p-4 w-full text-left hover-bg-nord-light';
entitlementButton.innerHTML = highlightedKey;
entitlementButton.addEventListener('click', () => toggleDetails(entitlementItem, value, searchTerm));
entitlementButton.className = 'entitlement-button hover-bg-nord-light';
entitlementButton.innerHTML = `
<span class="entitlement-text" title="${key}">${highlightMatches(key, searchTerm)}</span>
<button class="copy-btn bg-nord-frost text-nord p-1 rounded ml-2" data-clipboard="${key}" title="Copy to clipboard">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
`;
entitlementItem.appendChild(entitlementButton);

const entitlementDetails = document.createElement('div');
entitlementDetails.className = 'accordion-content bg-nord';
entitlementDetails.innerHTML = `<div class="accordion-inner"><pre><code class="language-xml"></code></pre></div>`;
entitlementDetails.innerHTML = `<div class="accordion-inner"><pre><code class="language-xml"></code></pre></div>`;
entitlementItem.appendChild(entitlementDetails);

entitlementList.appendChild(entitlementItem);

entitlementButton.addEventListener('click', (e) => {
if (!e.target.closest('.copy-btn')) {
toggleDetails(entitlementItem, value, searchTerm);
}
});
}

// Add event listeners for copy buttons
document.querySelectorAll('.copy-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
e.stopPropagation();
const textToCopy = btn.getAttribute('data-clipboard');
navigator.clipboard.writeText(textToCopy).then(() => {
const originalHTML = btn.innerHTML;
btn.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/>
</svg>
`;
btn.classList.add('bg-green-500');
setTimeout(() => {
btn.innerHTML = originalHTML;
btn.classList.remove('bg-green-500');
}, 2000);
}).catch(err => {
console.error('Failed to copy text: ', err);
});
});
});
};

const toggleDetails = (entitlementItem, value, searchTerm) => {
Expand Down

0 comments on commit 6d20411

Please sign in to comment.