GitLab: copy the branch name
Copies the current branch or merge-request source branch name to the clipboard with a short confirmation.
Code to copy
// Copy the current branch or merge-request source branch to the clipboard
const el = document.querySelector(
'.ref-name, [data-testid="ref-name"], .js-source-branch, .source-branch-name'
);
const name = el ? el.textContent.trim() : '';
if (name && navigator.clipboard) {
navigator.clipboard.writeText(name).then(function () {
const note = document.createElement('div');
note.textContent = 'Branch copied: ' + name;
note.style.cssText =
'position:fixed;bottom:20px;left:50%;transform:translateX(-50%);' +
'background:#1f1f1f;color:#fff;padding:8px 14px;border-radius:6px;z-index:9999;font-size:13px';
document.body.appendChild(note);
setTimeout(function () { note.remove(); }, 2000);
});
}
How to use this example
- Copy the code with the button above.
- Install JustZix (2 minutes) and open the extension on the target page.
- Add a new rule matching that page.
- Enable the action panel, add a button in the Actions tab and paste the code into it — run it with one click.
Rate this example
No ratings yet — be the first.