1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Box Drive用のパスを取得するブックマークレットを作った

Last updated at Posted at 2025-02-07

はじめに

Boxを使った案件の場合、「Box Drive」 という公式に提供されているアプリケーションがとても便利です。

ざっくり説明すると、エクスプローラーから直接Boxのファイルを参照したり開いたり編集したり同期したり出来る代物。
いちいちダウンロード→アップロードをする必要もありませんし、バカ使いにくいExcel Onlineを使う必要もありません。
(他の人と並行して編集する事はできませんが)

ただ、一つ欠点があります。

それは、「基本的にファイル連携時はBoxのURLで渡される」 ということです。

なので、URLからboxを開いてー上のところのファイルパスを確認してーそれに合わせてエクスプローラーを開いていってーという手間がかかります。
めんどい。

必要な情報はブラウザの画面上にすべて出ているので、ブックマークレットで取得しちゃいましょう。

内容

Boxで開いているフォルダをBoxDrive(Finder)で開きたい時に便利なブックマークレット

散々偉そうなことを上で書きましたが、既に作ってくださっている方がいました。
ただ、僕の環境だとうまく動かなかったりなんだりあったので、少し改修しました。

javascript: {
    // 画面上に表示出来ているフォルダパスを取得して、全部合わせてクリップボードにコピー
	const getDisplayPathAndCopy = (path) => {
		path += [...document.querySelectorAll(".ItemListBreadcrumb-listItem")]
            .map((menuItem) => menuItem.innerText)
            .filter((innerText) => innerText !== "" && innerText !== "すべてのファイル")
            .join("/");
		navigator.clipboard.writeText(path);
		document.body.click(); // 省略されたフォルダパスを戻しておく
	};

	let path = "%USERPROFILE%/Box/";
	const dotButton = document.querySelectorAll(".ItemListBreadcrumb > button")[0];

    // 省略されているフォルダパスが存在する場合
	if (dotButton) {
		dotButton.click();
        // クリックした後に表示されるものが同一トランザクションだと取得出来ないので、setTimeoutで少しだけずらす
		setTimeout((path)=>{
			path += [...document.querySelectorAll("a[data-resin-target='openfolder'].menu-item")]
            .map((menuItem) => menuItem.innerText)
            .filter((innerText) => innerText !== "すべてのファイル")
            .join("/");

			if (!path.endsWith("/")) path += "/";

			getDisplayPathAndCopy(path);

		}, 100, path);
	} else {
		getDisplayPathAndCopy(path);
	}
}

これをminifyしたコイツ

javascript:{const getDisplayPathAndCopy=(path)=>{path+=[...document.querySelectorAll(".ItemListBreadcrumb-listItem")].map((menuItem)=>menuItem.innerText).filter((innerText)=>innerText!==""&&innerText!=="すべてのファイル").join("/");navigator.clipboard.writeText(path);document.body.click()};let path="%USERPROFILE%/Box/";const dotButton=document.querySelectorAll(".ItemListBreadcrumb > button")[0];if(dotButton){dotButton.click();setTimeout((path)=>{path+=[...document.querySelectorAll("a[data-resin-target='openfolder'].menu-item")].map((menuItem)=>menuItem.innerText).filter((innerText)=>innerText!=="すべてのファイル").join("/");if(!path.endsWith("/"))path+="/";getDisplayPathAndCopy(path)},100,path)}else{getDisplayPathAndCopy(path)}}

がURLとして設定されているブックマークを用意したら、後は呼び出すだけでクリップボードにフォルダパスがコピーされます。

おわりに

あとはBox Driveから直接BoxのURLを取得出来るようになってくれれば文句なしなのですが、そっち側はどうしようもないので諦めます。
ちょっと生きやすくなりました。

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?