Last active
March 17, 2022 14:43
-
-
Save freakdesign/a1636414cce682c2c444 to your computer and use it in GitHub Desktop.
Get a CSV list of all files within the Files section of a Shopify account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Get a list of all files within the Shopify Admin (/admin/settings/files) | |
This needs to be run within the Chrome Browser. Paste into the debug console and run... | |
A text file will download when done. | |
*/ | |
(function(){ | |
var debug = false; // enable logging | |
var fileArray = []; | |
var saveList = function(fileArray){ | |
console.log('============ DONE. DOWNLOAD FILE ============'); | |
var a = document.createElement("a"); | |
document.body.appendChild(a); | |
a.style = "display: none"; | |
var blob = new Blob(["\ufeff",fileArray],{type:'text/plain'}), | |
link = window.URL.createObjectURL(blob); | |
a.href = link; | |
a.download = 'shopify-files-list' + '.txt'; | |
a.click(); | |
window.URL.revokeObjectURL(link); | |
}; | |
var getFiles = function(url){ | |
if(typeof(url) === 'undefined'){ var url = '/admin/settings/files?limit=250' } | |
$.ajax({ | |
url: url, | |
success: function(d){ | |
var html = $(d); | |
var fields = html.find('.next-input.next-input--readonly'); | |
for (var i = 0; i < fields.length; i++) { | |
if(debug){ console.log('Adding ' + fields[i].value) } | |
fileArray.push(fields[i].value); | |
}; | |
var next = html.find('#pagination-links li:last a'); | |
if(!next.length || next.hasClass('disabled')){ | |
if(fileArray.length){ saveList(fileArray) } | |
return; | |
} | |
var nextUrl = next[0].href; | |
console.log(nextUrl) | |
if(nextUrl.indexOf('direction=next')>-1){ | |
if(debug){ console.log('Fields grabbed. Next page now...') } | |
getFiles(nextUrl); | |
}else{ | |
saveList(fileArray); | |
} | |
} | |
}); | |
} | |
getFiles(); | |
})(); |
Seems like jquery is not anymore on Shopify Admin
Here is the fix.
Before running the above code, you can add jquery to console
fetch('https://code.jquery.com/jquery-latest.min.js').then(r => r.text()).then(r => eval(r))
Might help others.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, looks like this has stopped working now. Would you be able to update please?
Thanks