Created
February 22, 2017 11:28
-
-
Save ColCh/dc2ac16ba4f80cc11f6370c3869522ea to your computer and use it in GitHub Desktop.
Copy new branch name to clipboard on issue page in GitLab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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"); | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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