Skip to content

Instantly share code, notes, and snippets.

@jimmijazz
Forked from ridem/Download-Shopify-CDN-Assets.md
Last active November 26, 2018 04:06
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 jimmijazz/19fccd095b2ccacf782384c813e72ce4 to your computer and use it in GitHub Desktop.
Save jimmijazz/19fccd095b2ccacf782384c813e72ce4 to your computer and use it in GitHub Desktop.
Download all Shopify CDN assets from a store
function fetchPageAssets(){
var downloader = $("<a id='download-file' href='' download=''></a>")
$(".ui-title-bar").append(downloader)
// Original wasn't selecting properly. Made a bit more dynamic
var start_pos = $(input).parents("tr[bind-class]").attr('bind-class').indexOf('[');
var end_pos = $(input).parents("tr[bind-class]").attr('bind-class').indexOf(']', start_pos);
var lastItem = $(input).parents("tr[bind-class]").attr('bind-class').substring(start_pos+1, end_pos)
assets.each(function(index, input) {
$('#download-file').attr('href', input.value);
$('#download-file')[0].click();
if (index + 1 == assets.length) {
var lastItem = $(input).parents("tr[bind-class]").attr('bind-class').substring(25,36)
$.ajax({
url: "/admin/settings/files?direction=next&last_id="+lastItem+"&last_value="+ lastItem+"&limit=100&order=id+desc",
}).done(function(data) {
var mutationObserver = new MutationObserver(function(mutations, observer) {
mutations.forEach(function(mutation) {
if (mutation.target.id && mutation.target.id == "assets-table") {
fetchPageAssets()
observer.disconnect()
}
})
});
mutationObserver.observe(document, {
childList: true,
subtree: true
});
var newDoc = document.open("text/html", "replace");
newDoc.write(data);
newDoc.close();
})
}
})
}
fetchPageAssets()
function fetchPageAssets() {
var assets = $("#assets-table .next-input--readonly")
assets.each(function (index, input) {
files.push(input.value)
if (index + 1 == assets.length) {
var start_pos = $(input).parents("tr[bind-class]").attr('bind-class').indexOf('[');
var end_pos = $(input).parents("tr[bind-class]").attr('bind-class').indexOf(']', start_pos);
var lastItem = $(input).parents("tr[bind-class]").attr('bind-class').substring(start_pos+1, end_pos);
$.ajax({
url: "/admin/settings/files?direction=next&last_id=" + lastItem + "&last_value=" + lastItem + "&limit=100&order=id+desc",
}).done(function (data) {
var mutationObserver = new MutationObserver(function (mutations, observer) {
mutations.some(function (mutation) {
if (mutation.target.id &&
mutation.target.id == "assets-area" &&
mutation.addedNodes[0].nextElementSibling.innerHTML.indexOf("empty") > -1
) {
downloadListFile()
observer.disconnect()
return true;
} else if (mutation.target.id &&
mutation.target.id == "assets-area" &&
mutation.previousSibling.className == "ui-layout ui-layout--full-width"
) {
fetchPageAssets()
observer.disconnect()
return true;
}
})
});
mutationObserver.observe(document, {
childList: true,
subtree: true
});
var newDoc = document.open("text/html", "replace");
newDoc.write(data);
newDoc.close();
})
}
})
}
function downloadListFile() {
var downloader = $("<a id='download-file' href='' download='shopify-files.txt'></a>")
$(".ui-title-bar").append(downloader)
var data = 'data:application/octet-stream;base64,' + window.btoa(files.join(','));
$('#download-file').attr('href', data);
$('#download-file')[0].click();
}
var files = []
fetchPageAssets()

This was 99.99% from here - ridem/Download-Shopify-CDN-Assets.md I've just updated to work with new admin DOM elements and provided instructions.

Instructions

  1. Go to your Shopify admin/settings/files page
  2. Open your browser Dev tools, go to the console

Then, depending on the option you choose:

Option 1 - Download all the files directly (might crash you browser)

  1. Make sure your browser is set to download files automatically and doesn't ask for the download location every time
  2. Paste the content of the console_download_files.js file, and press enter
  3. Your browser will automatically fetch each page and download every file on it. It might ask you to accept "multiple downloads" (Chrome)

Option 2 - Download a .txt file containing the list of the files to download

  1. Paste the content of the console_download_list.js file, and press enter
  2. Your browser will automatically fetch each page and download the list of all the files on the CDN. You'll then be able to use any file download manager to import the list and safely download everything.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment