ブラウザでBoxのフォルダを開いている時に、当該フォルダをBoxDrive(Windows Explorer)で開きたくなることがある。そんな時にこのブックマークレットを使用すれば、いい感じにパスをコピーできる。
以下で公開されているブックマークレットを元に修正したもの。
- 2026/02/25 版の不具合修正
- Box 仕様変更に追随
- 階層メニューの取得方法を変更
- 分類ラベルの除外処理を変更
- Box 仕様変更に追随 (すべてのファイル → ファイル)
- (1) 階層メニューのパスがコピーされない場合がある不具合を修正
- (2) 分類ラベルをコピーしないように修正
- (3) パス形式を Windows 用に変更
Windows Explorer で開く分には (3) のパス形式は変更しなくても問題はないのだが、自分の場合パスをそのまま他のテキストにもコピーすることが多いため Windows パス形式に揃えた。
以下のスクリプトをEdgeのブックマークに任意の名前で登録する。
javascript:(async function () { let path = "%USERPROFILE%\\Box\\"; const dotButton = document.querySelectorAll(".FolderTreeButton")[0]; if (dotButton) { await dotButton.click(); path += [ ...document.querySelectorAll( "a[data-resin-target='openfolder'].menu-item"), ] .map((e) => e.innerText) .filter( (v) => v !== decodeURI("%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB")) .join("\\"); if (!path.endsWith("\\")) path += "\\"; } path += [...document.querySelectorAll(".ItemListBreadcrumb-listItem:not(.is-last)"), ...document.querySelectorAll(".ItemListBreadcrumb-currentItemTitleAndFolderTreeFlyout")].map((v) => v.firstElementChild.innerText).filter( (v) => v !== "" && v !== decodeURI("%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB")).join("\\"); !(function (a) { var b = document.createElement("textarea"), c = document.getSelection(); (b.textContent = a), document.body.appendChild(b), c.removeAllRanges(), b.select(), document.execCommand("copy"), c.removeAllRanges(), document.body.removeChild(b); })(path); document.body.click();})();Boxでフォルダを表示している状態で登録したブックマークを呼び出すと、%USERPROFILE%\Box\to\local\path の様な形式でクリップボードにコピーされる。
Explorer のアドレスバーに貼り付けて移動する。
- Windows 11 25H2
- Edge 145.0.3800.70
ライセンスはFork元の下記ライセンスと同じく Unlicense とします。 https://gist.github.com/t3yamoto/35a61f4f95edafbe71056c6ba35d8596
処理と差分を見やすくするためにインデントを入れたもので、内容は上記と同一です。
javascript:
(async function () {
let path = "%USERPROFILE%\\Box\\";
const dotButton = document.querySelectorAll(".FolderTreeButton")[0];
if (dotButton) {
await dotButton.click();
path += [ ...document.querySelectorAll( "a[data-resin-target='openfolder'].menu-item"), ] .map((e) => e.innerText) .filter( (v) => v !== decodeURI("%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB")) .join("\\");
if (!path.endsWith("\\")) path += "\\";
}
path += [...document.querySelectorAll(".ItemListBreadcrumb-listItem:not(.is-last)"),
...document.querySelectorAll(".ItemListBreadcrumb-currentItemTitleAndFolderTreeFlyout")]
.map((v) => v.firstElementChild.innerText).filter( (v) => v !== "" && v !== decodeURI("%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB")).join("\\");
!(function (a) {
var b = document.createElement("textarea"), c = document.getSelection();
(b.textContent = a), document.body.appendChild(b), c.removeAllRanges(), b.select(), document.execCommand("copy"), c.removeAllRanges(), document.body.removeChild(b);
})(path);
document.body.click();
})();
度々便利に使わせて頂いています。ありがとうございます。
boxの仕様変更で「すべてのファイル」が「ファイル」になったので、
decodeURIの"%E3%81%99%E3%81%B9%E3%81%A6%E3%81%AE%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB"の「すべての」の部分を削らないと動作しなくなりました。