Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save t-yamamoto-mercury-inc/b58969dcc58bb13ee4b7e2c1fc316501 to your computer and use it in GitHub Desktop.
Save t-yamamoto-mercury-inc/b58969dcc58bb13ee4b7e2c1fc316501 to your computer and use it in GitHub Desktop.
Googleドライブのパスをクリップボードにコピーするブックマークレット
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