Created
January 24, 2019 07:55
-
-
Save t-yamamoto-mercury-inc/b58969dcc58bb13ee4b7e2c1fc316501 to your computer and use it in GitHub Desktop.
Googleドライブのパスをクリップボードにコピーするブックマークレット
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 pre = 'Googleドライブ:'; | |
var xpath = '//*[@guidedhelpid="folder_path"]'; | |
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 pathObj = document.getElementsByXPath(xpath); | |
var path = pathObj[pathObj.length-1].outerText.replace(/フォルダ パス/g, pre).replace(/\r?\n/g, '/'); | |
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; | |
} | |
console.log(path); | |
copyTextToClipboard(path); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment