Copy explorer path of Box folder

Add a button on Box website that can copy explorer path of Box folder.

当前为 2021-09-05 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Copy explorer path of Box folder
// @description  Add a button on Box website that can copy explorer path of Box folder.
// @namespace    https://github.com/kevinzch/Copy-explorer-path-of-Box-folder
// @version      0.1
// @author       Kevin
// @include      https://app.box.com/folder/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    const copyExplorerPath = () => {
        try {
            let b1 = document.createElement('button');
            b1.textContent = 'コピー';
            let searchbar = document.querySelector('.header-search.prevent-item-deselection.HeaderSearch-isNewQuickSearch');
            searchbar.appendChild(b1);

            b1.addEventListener('click', function(){
                let hiddenPathButton = document.querySelector('button.btn-plain.ItemListBreadcrumbOverflow-menuButton');
                let topOfBreadcrumbList = document.querySelector('ol.ItemListBreadcrumb-list');
                let breadcrumb = topOfBreadcrumbList.querySelectorAll('[class=ItemListBreadcrumb-listItem]');
                let lastBreadcrumb = topOfBreadcrumbList.querySelector('.ItemListBreadcrumb-listItem.is-last>.ItemListBreadcrumb-currentItemTitle');
                let text = 'Box\\';

                hiddenPathButton.click();
                setTimeout(function() {
                    let hiddenList = document.querySelector('div.dropdown-menu-element.dropdown-menu-enabled');
                    let list = hiddenList.querySelectorAll('[data-resin-target=openfolder]');

                    for (let item of list){
                        if ( item.textContent != 'All Files' ){
                            text += item.textContent + "\\";
                        }
                    }

                    for (let item of breadcrumb){
                        text += item.textContent + '\\';
                    }

                    text += lastBreadcrumb.textContent;
                    navigator.clipboard.writeText(text);
                    alert('エクスプローラーパスをコピーしました。');
                },500);
            })
        } catch (e) {
            setTimeout(() => {
                copyExplorerPath();
            }, 500);
        }
    };

    setTimeout(() => {
        copyExplorerPath();
    }, 100);

})();