Skip to content

Instantly share code, notes, and snippets.

@ColCh
Created Feb 22, 2017
Embed
What would you like to do?
Copy new branch name to clipboard on issue page in GitLab
(function () {
try {
var newBranchButton = document.querySelector('#new-branch > a.available');
var title = newBranchButton.title || newBranchButton.dataset.originalTitle;
if (!title) {
alert("Can't find New Branch button");
return;
}
var copied = false;
try {
var element = document.createElement('span');
element.innerHTML = title;
document.body.appendChild(element);
var range = document.createRange();
range.selectNode(element);
var selection = window.getSelection();
selection.addRange(range);
copied = document.execCommand('copy');
document.body.removeChild(element);
} catch (e) { }
selection.removeAllRanges();
if (copied) {
alert("Copied "+title+" to clipboard");
} else {
prompt("Can't copy title. Do it yourself", title);
}
} catch (e) {
alert("Can't find element to copy from");
}
})();
!function(){try{var e=document.querySelector("#new-branch > a.available"),t=e.title||e.dataset.originalTitle;if(!t)return void alert("Can't find New Branch button");var n=!1;try{var a=document.createElement("span");a.innerHTML=t,document.body.appendChild(a);var o=document.createRange();o.selectNode(a);var c=window.getSelection();c.addRange(o),n=document.execCommand("copy"),document.body.removeChild(a)}catch(r){}c.removeAllRanges(),n?alert("Copied "+t+" to clipboard"):prompt("Can't copy title. Do it yourself",t)}catch(r){alert("Can't find element to copy from")}}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment