ID Generator — Confluence Cloud Macro
The ID Generator macro provides a quick and reliable way to generate unique identifiers inside Confluence Cloud pages. It uses a timestamp-based approach combined with Base32 encoding to ensure compact, readable output. The interface is built using Atlassian AUI styling for a native Confluence look. When the user clicks the Generate ID button, a JavaScript function retrieves the current timestamp in milliseconds. This timestamp is then passed to a base32_encode function that converts each character into binary, pads the result to be divisible by 5 bits, and transforms every 5-bit segment into a Base32 symbol. The Base32 alphabet used contains uppercase letters and digits 2–7, ensuring a clean and URL-safe output. Once the ID is generated, it is displayed in a styled UI element next to the button without refreshing or reloading the page. Since the timestamp increases every millisecond, each ID is guaranteed to be unique at the moment of creation, making it suitable for lightweight referencing, task tracking, or naming objects in documentation. The macro does not require any server-side code or API calls, making it fully functional in Confluence Cloud environments where JavaScript macros are allowed. Its styling and behavior follow Atlassian design patterns, ensuring seamless appearance integration.
User Parameters
This macro comes without configurable user parameters.
Template
<script src="https://code.iconify.design/iconify-icon/2.1.0/iconify-icon.min.js"></script>
<div class="aui-page-panel-content">
<div style="display: flex; align-items: center; gap: 14px;">
<button id="idGeneratorButton" class="aui-button aui-button-primary">
Generate ID
</button>
<span id="generatedId" style="
display: none;
background: #f4f5f7;
border-radius: 3px;
padding: 2.5px 5px;
font-size: 14px;
border: 1px solid #dfe1e6;
color: #172b4d;
align-items: center;
gap: 6px;"
role="status"
aria-live="polite">
<strong>ID:</strong>
<span id="idValue" style="font-family:monospace"></span>
<button id="copyIdBtn"
type="button"
title="Copy ID"
aria-label="Copy ID"
style="border: none; background: transparent; padding: 4px; cursor:pointer; display: inline-flex; align-items: center;">
<iconify-icon id="copyIcon" icon="mdi:content-copy" width="16" height="16"></iconify-icon>
</button>
</span>
</div>
</div>
<script>
const base32_encode = (data) => {
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
let binary = [...data].map(c => c.charCodeAt(0).toString(2).padStart(8, '0')).join('');
while (binary.length % 5) binary += '0';
let out = '';
for (let i = 0; i < binary.length; i += 5) out += alphabet[parseInt(binary.slice(i, i+5), 2)];
return out;
};
const generateId = () => base32_encode(Date.now().toString());
const genBtn = document.getElementById('idGeneratorButton');
const wrap = document.getElementById('generatedId');
const valEl = document.getElementById('idValue');
const copyBtn = document.getElementById('copyIdBtn');
const copyIcon = document.getElementById('copyIcon');
genBtn.addEventListener('click', () => {
const id = generateId();
valEl.textContent = id;
wrap.style.display = 'inline-flex';
copyIcon.setAttribute('icon', 'mdi:content-copy');
});
function execCommandCopy(text) {
try {
const ta = document.createElement('textarea');
ta.value = text;
ta.setAttribute('readonly', '');
ta.style.position = 'fixed';
ta.style.top = '-9999px';
ta.style.left = '-9999px';
document.body.appendChild(ta);
ta.select();
ta.setSelectionRange(0, ta.value.length);
const ok = document.execCommand('copy');
document.body.removeChild(ta);
return !!ok;
} catch (e) {
console.warn('execCommand copy failed', e);
return false;
}
}
copyBtn.addEventListener('click', () => {
const value = valEl.textContent || '';
if (!value) return;
const success = execCommandCopy(value);
if (success) {
copyIcon.setAttribute('icon', 'mdi:check');
setTimeout(() => {
copyIcon.setAttribute('icon', 'mdi:content-copy');
}, 1200);
}
});
</script>Recommended Macros
Shows a mention of the user who created the current page. If it's a current user, mention blue. If it's another user, mention gray.
Find image within page attachments. Handy for reuse files and update them all at once
Display and interact with an OpenAPI / Swagger specification directly in Confluence by rendering a fully featured Swagger UI from a provided JSON URL
Content that is hidden only if a user is in a particular group
Create dropdown menus in Confluence Cloud with predefined sets of options and permission gates
Shows page creation date
Use sticky previous/next buttons to navigate through your Confluence page tree in a linear reading order
Displays a list of pages in specific space with certain title or label