Skip to content

Instantly share code, notes, and snippets.

@TCNOco
Forked from jkctech/GyazoDeleter.md
Last active January 23, 2023 01:34
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 TCNOco/9fd372e229e32a7f442ebec45d8fa088 to your computer and use it in GitHub Desktop.
Save TCNOco/9fd372e229e32a7f442ebec45d8fa088 to your computer and use it in GitHub Desktop.
Mass delete Gyazo pictures on your account page through some JavaScript

Delete all images from Gyazo

There isn't a way to mass delete images offered by Gyazo, other than Deleting your account. Sucks for you if you paid for there service.

This repo is based on the older repo by @jkctech. I updated their script for adding a Select All and Delete All button, as well as created a drastically improved "delete all" script that works with the API directly.

As long as you're comfortable using the Console section of your browser, you can use this. (Last tested on 23rd Jan 2023)

OPTION 1: Add Select All and Delete All buttons

Copy paste the contents of selectall_delete_buttons.js in a chrome developer console on https://gyazo.com/captures.

2 buttons will appear in the navbar.

Click the "Delete All" button to execute an automatic mass deleter for all visible items (this will take about 5 seconds to complete).

Click the "Select All" button to only mass select all visible items.

After deleting a couple of items, the Gyazo UI likes to get glitched. Reload the page and repeat the mentioned steps above.

OPTION 2: Mass delete images from Gyazo

Copy paste the contents of massDeleteCollect.js in a chrome developer console on https://gyazo.com/captures BUT DO NOT HIT ENTER.

Head to the Network tab, then select and delete an image normally.

Without refreshing the page at all in this process, click the delete request in the network log (it should be the last entry).

On the Headers section you can scroll to the bottom until you see x-csrf-token. Copy that, and enter it into the second line between the quotes, so you end up with var x_csrf_token = "XYZABC".

Then enter the total number of images you would like to delete at the very top of the script, where you see var totalItems = 300. Instead set 300 to your desired number of images to delete. Usually the max seems to be around 3000. Any higher causes things to break and Gyazo's servers to time you out.

Then hit enter to collect a large number of images to delete. You will see multiple Processing [x/10] appear. Just wait for it to reach [10/10], for example.

Now to actually delete those images. Copy the contents of massDeleteRun.js and paste it into the same console. Then hit enter.

Just remember to wait some time! Refreshing the page every few seconds will show you that the images are slowly being deleted from Gyazo's server, even though we sent them hundreds of delete requests.

var totalItems = 300
var x_csrf_token = ""
// Set this to say 30 if you collected asked Gyazo to delete 3,000 images, so it can get the next X images
var pageOffset = 0
var currentItem = 0
var currentPage = 0
var deleteRequests = []
var totalProcessed = 0
while (currentItem < totalItems) {
currentItem += 100;
currentPage++;
var allItems = []
fetch(`https://gyazo.com/api/internal/images?page=${pageOffset + currentPage}&per=100`, {
"headers": {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9",
"sec-ch-ua": "\"Not_A Brand\";v=\"99\", \"Google Chrome\";v=\"109\", \"Chromium\";v=\"109\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "no-cors",
"sec-fetch-site": "same-origin"
},
"referrer": "https://gyazo.com/captures",
"referrerPolicy": "origin-when-cross-origin",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
}).then(function (r) {
r.json().then(arr => {
for (x = 0; x < arr.length; x++) {
allItems.push(arr[x].alias_id)
}
totalProcessed++;
console.log(`Processing [${totalProcessed}/${totalItems/100}]...`);
var i = 0
var total = 0
var group = []
while (total <= allItems.length){
group.push(allItems[total])
i++;
total++;
if (total == allItems.length || i == 10){
var imagesList = '{\"encoded_image_ids\":[\"' + group.join('\",\"') + '\"]}'
deleteRequests.push({
"headers": {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9",
"content-type": "application/json",
"sec-ch-ua": "\"Not_A Brand\";v=\"99\", \"Google Chrome\";v=\"109\", \"Chromium\";v=\"109\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-csrf-token": x_csrf_token
},
"referrer": "https://gyazo.com/captures",
"referrerPolicy": "origin-when-cross-origin",
"body": imagesList,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
i = 0
group = []
}
}
})
});
}
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
for (i = 0; i < totalItems/10; i++) {
console.log(`Running delete request [${i + 1}/${totalItems/10}]`)
fetch("https://gyazo.com/api/internal/images_deletions", deleteRequests[i]);
sleep(500)
}
// Select all visible items on the page
function selall()
{
$(".checkmark").trigger("click");
}
// Execute deletion
function del()
{
// Select all
selall();
// 2 Seconds to finish selecting items
setTimeout(function(){
// Find the sidebar delete button and click it
$(".explorer-overlay-side-block-items").find("li").trigger("click");
// 500ms delay for modal
setTimeout(function(){
// Click delete button
$(".btn-danger").trigger("click");
}, 500);
}, 2000);
}
// Add buttons to navbar
$(".explorer-action-btn-toolbar").append('<button onclick="del()" class="btn btn-warning" style="margin-right: 8px;">Delete All</button>');
$(".explorer-action-btn-toolbar").append('<button onclick="selall()" class="btn btn-info">Select All</button>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment