Skip to content

Instantly share code, notes, and snippets.

@fabtho
Forked from boppy/README.md
Last active November 13, 2019 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabtho/44ed5825ea404fbb2809874901b18ad4 to your computer and use it in GitHub Desktop.
Save fabtho/44ed5825ea404fbb2809874901b18ad4 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:

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.

To create a bookmarklet make a fresh bookmark in you bookmark bar, edit it, name it "edit all" and fill this into the URL: "javascript:(window._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 (tested in in 8.7 / in 9.5). ;)

(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;
})();
@daCyberpunk
Copy link

Hi!
Danke fürs veröffentlichen diesen Hacks. Der eigentlich ned nötig sein sollte. Jemand muss wohl mal was fürs TYPO3 schreiben. Jedenfalls bis dahin:

Wer wie ich keine extra Browser Extension installieren möchte (vor allem keine die Zugriff auf ALLE besuchten Seiten haben wird), kann auch einfach den folgenden minified Schnipsel direkt ins Bookmarklet eintragen:
javascript: (function(){ function parseURL(e){var t,c,s,a=document.createElement("a"),l={};for(a.href=e,t=a.search.replace(/^\?/,"").split("&"),s=0;s<t.length;s++)l[(c=t[s].split("="))[0]]=c[1];return{protocol:a.protocol,host:a.host,hostname:a.hostname,port:a.port,pathname:a.pathname,search:a.search,searchObject:l,hash:a.hash}}function editAll(){try{const e=document.getElementById("typo3-contentIframe").contentDocument;let t,c=e.querySelectorAll("#typo3-filelist a.filelist-file-title, #typo3-filelist a.responsive-title");c=[].slice.call(c);let s=!1;c.forEach(e=>{let c=parseURL(e.dataset.url||e.href);!1===s?(s=c.searchObject,t=c.pathname):Object.entries(c.searchObject).forEach(([e,t])=>{"edit"===t&&(s[e]=t)})}),t+="?",Object.entries(s).forEach(([e,c])=>{t+=e+"="+c+"&"}),t=t.slice(0,-1);let a=document.createElement("a");a.href=t,a.classList.add("btn","btn-default"),a.title="Edit all visible files meta data",a.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>',(e.querySelector(".col-clipboard")||e.forms[0]).appendChild(a)}catch(e){console.error(e)}}editAll();})()

Bissl lang, aber passt rein. :-D
Bestes! Falk

@martinkrung
Copy link

Stimmt, das ist auch eine gute Möglichkeit und doch einfacher! Danke

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