Last active
August 29, 2015 14:05
-
-
Save sanmai/3c7eeb0f57d619f9e038 to your computer and use it in GitHub Desktop.
Adds a delete link at Gallery Stats
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
// ==UserScript== | |
// @name Adds a delete link at Gallery Stats | |
// @namespace http://userscripts.org/users/163777 | |
// @include http://submit.shutterstock.com/darkroom/gallery.mhtml* | |
// @include http://submit.shutterstock.com/show_component.mhtml | |
// @require http://code.jquery.com/jquery.min.js | |
// @version 2 | |
// @updateURL https://gist.githubusercontent.com/sanmai/3c7eeb0f57d619f9e038/raw/Delete_link_at_Gallery_Stats.user.js | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
/* if more than that, don't show download link */ | |
var maxDownloads = 10; | |
/* only show delete link for content older than X days */ | |
var recentDays = 180; | |
var deadline = new Date(); | |
deadline.setDate(deadline.getDate() - recentDays); | |
deadline = deadline.toISOString().match(/(\d{4})-(\d{2})/).slice(1).join(""); | |
$("#stats_table .photo_name").each(function () { | |
var totalPurchases = $(this).next().text(); | |
var monthUploaded = $(this).next().next().next().text().match(/(\d{4})-(\d{2})/).slice(1).join(""); | |
var $firstLink = $("a:first", this); | |
var imageId = $firstLink.attr("href").match(/\d+/)[0]; | |
var editURL = "http://submit.shutterstock.com/edit_media.mhtml?type=photos&approved=1&id=" + imageId; | |
$firstLink.attr('href', editURL); | |
totalPurchases < maxDownloads && monthUploaded < deadline && | |
$('<a>').text("Permanently delete ID " + imageId).attr("href", editURL).on("click", function () { | |
var response = prompt("Enter number of purchases for the image in subject:", "0"); | |
if (response == totalPurchases) { | |
console.log("Removing ID " + imageId + " with " + totalPurchases + " purchases"); | |
var parentRow = $(this).closest("tr"); | |
GM_xmlhttpRequest({ | |
method: "POST", | |
url: "http://submit.shutterstock.com/show_component.mhtml", | |
data: "component_path=edit%2Fdelete_media.md&media_type=photos&item_ids=" + imageId, | |
headers: { | |
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", | |
"X-Requested-With": "XMLHttpRequest", | |
"X-Prototype-Version": "1.7", | |
"Referer": editURL | |
}, | |
onload: function (response) { | |
console.log("Removed ID " + $.parseJSON(response.response)[0]); | |
parentRow.hide(); | |
}, | |
onerror: function (response) { | |
console.log(response); | |
} | |
}); | |
} | |
return false; | |
}).appendTo(this); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment