Skip to content

Instantly share code, notes, and snippets.

@jwh315
Created December 15, 2018 21:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jwh315/808f5dc26ef823b551401e1dc9fa9dee to your computer and use it in GitHub Desktop.
Save jwh315/808f5dc26ef823b551401e1dc9fa9dee to your computer and use it in GitHub Desktop.
var cleanUp = {
domains: [],
getDomains: async function() {
let results = null;
let page = 0
do {
const response = await fetch(`https://prerender.io/api/cached-pages?page=${page}&pageSize=1000`);
const json = await response.json();
results = json;
json.map(item => cleanUp.domains.push(item.url));
console.log("Found domains " + json.length);
page++;
} while (results.length);
},
deleteDomain: async function(domain, cookie) {
console.log(`deleting domain ${domain}`);
let response = await fetch("https://prerender.io/api/remove-cached-url?url=" + encodeURIComponent(domain), {
method: "DELETE",
headers: {
"x-xsrf-token": cookie
}
});
console.log(`doamin deleted ${domain}`);
cleanUp.deleteDomain(cleanUp.domains.pop(), cookie);
},
getCookie: function() {
var name = 'XSRF-TOKEN';
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
},
init: async function() {
await cleanUp.getDomains();
cleanUp.deleteDomain(cleanUp.domains.pop(), cleanUp.getCookie());
console.log("done");
}
};
cleanUp.init();
@TylorS
Copy link

TylorS commented Jan 30, 2020

Thank you for this!

@AlmogCohen
Copy link

This is so fu**ing amazing! They should have implemented that in their UI though....

@AlmogCohen
Copy link

Actually, they should implement a batch delete official api...

@AlmogCohen
Copy link

I found another quick way for a few thousands of links

I navigate to https://prerender.io/?q=&pageSize=1000 and then I can use their button to concurrently delete all the 1000 within a few seconds

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