Skip to content

Instantly share code, notes, and snippets.

@boppy
Last active November 8, 2019 15:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save boppy/14a6dfe69b7ca1aa08c7515c6acd0060 to your computer and use it in GitHub Desktop.
Save boppy/14a6dfe69b7ca1aa08c7515c6acd0060 to your computer and use it in GitHub Desktop.
Quick'n'dirty mass edit for TYPO3 file list in Chrome

Regarding TYPO3 CMS Feature #60907.

IMPORTANT: Superseded by fabthos Fork.


To manipulate Websites I use this Chrome Extension: User JavaScript and CSS

To have a "edit all"-Button I use the following script on the TYPO3-Domain, with an additional bookmarklet to call _editAllMetaData. It inserts a button in the file table's header or, if not present, it appends it to the search form.

It's quick'n'dirty, but it's working like a charme (at least in 8.7). ;)

(function(){
    
    function parseURL(url) {
        var parser = document.createElement('a'), searchObject = {}, queries, split, i;
        parser.href = url;
        queries = parser.search.replace(/^\?/, '').split('&');
        for( i = 0; i < queries.length; i++ ) {
            split = queries[i].split('=');
            searchObject[split[0]] = split[1];
        }
        return {
            protocol: parser.protocol,
            host: parser.host,
            hostname: parser.hostname,
            port: parser.port,
            pathname: parser.pathname,
            search: parser.search,
            searchObject: searchObject,
            hash: parser.hash
        };
    }

    function editAll(){
        try {
            const iframe = document.getElementById('typo3-contentIframe').contentDocument;
            let all = iframe.querySelectorAll('#typo3-filelist a.filelist-file-title, #typo3-filelist a.responsive-title');
            all = [].slice.call(all);
            let url;
            let final = false;
            all.forEach(e => {
                let o = parseURL(e.dataset.url || e.href);
                if(final === false){
                    final = o.searchObject;
                    url = o.pathname;
                } else {
                    Object.entries(o.searchObject).forEach(([name, val]) => {
                        if(val === 'edit'){
                            final[name] = val;
                        }
                    });
                }
            });
            url += '?';
            Object.entries(final).forEach(([name, val]) => {
                url += name +'='+ val +'&';
            });
            url = url.slice(0, -1);

            let elm = document.createElement('a');
            elm.href = url;
            elm.classList.add('btn', 'btn-default');
            elm.title = 'Edit all visible files meta data';

            elm.innerHTML = '<span class="t3js-icon icon icon-size-small icon-state-default icon-actions-document-select"><span class="icon-markup"><img src="/typo3/sysext/core/Resources/Public/Icons/T3Icons/actions/actions-open.svg" width="16" height="16"></span></span>';

            (iframe.querySelector('.col-clipboard') || iframe.forms[0]).appendChild(elm);
        } catch(e){
            console.error(e);
        }
    }
    window._editAllMetaData = editAll;
})();
@fabtho
Copy link

fabtho commented Nov 8, 2019

hi boby

Thanks for this, I added some text how to make a bookmarklet and this also works in TYPO3 9.5! Cant make a pull request with gist..

https://gist.github.com/fabtho/44ed5825ea404fbb2809874901b18ad4/revisions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment