Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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