Last active
February 14, 2019 01:29
-
-
Save t-yamamoto-mercury-inc/50308059c03d55aaa5ec6b683f7d2e11 to your computer and use it in GitHub Desktop.
copy_github_issue_title_and_url.js
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
javascript:(function(){ | |
var xpath = '//*[@class="gh-header-title"]'; | |
var pre = ' - '; | |
document.getElementsByXPath = function(expression, parentElement) { | |
var r = []; | |
var x = document.evaluate(expression, parentElement || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
for (var i = 0, l = x.snapshotLength; i < l; i++) | |
{ | |
r.push(x.snapshotItem(i)); | |
} | |
return r; | |
}; | |
var target1Obj = document.getElementsByXPath(xpath); | |
var target1 = target1Obj[target1Obj.length-1].outerText; | |
function copyTextToClipboard(textVal){ | |
var copyFrom = document.createElement("textarea"); | |
copyFrom.textContent = textVal; | |
var bodyElm = document.getElementsByTagName("body")[0]; | |
bodyElm.appendChild(copyFrom); | |
copyFrom.select(); | |
var retVal = document.execCommand('copy'); | |
bodyElm.removeChild(copyFrom); | |
return retVal; | |
} | |
var text = pre + '[' + target1 + '](' + location.href + ')'; | |
console.log(text); | |
copyTextToClipboard(text); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment