');
$('div [class="_2o3t fixed_elem"] div[class="clearfix uiHeaderTop"] ').append(' ');
$("#script-delete-button").bind('click', function () {
buttonStart();
});
}
function buttonStart() {
olderThan = $('#script-age-input').val() * 1000 * 60 * 60 * 24;
if ($('#checkbox-likes').prop('checked')) {
validActions.push("unlike");
}
if ($('#checkbox-comments').prop('checked')) {
validActions.push("remove_comment");
}
if ($('#checkbox-posts').prop('checked')) {
validActions.push("delete");
}
clickEntries()
.then(console.log("Process finished"));
}
function clickEntries() {
var promise = new Promise(function (resolve, reject) {
//click on the editing button and get the timestamp
$('body').find('span[class=_-xe]').each(function () {
console.log(this);
$(this).click();
});
resolve();
});
return promise;
}
//Reads the information of the previously clicked entries
function retrieveEntryInformation() {
$('body').find('a[ajaxify][rel=async-post]').each(function () {
var ajaxify = $(this).attr('ajaxify');
var index = arrAjaxify.indexOf(ajaxify);
if (index > -1) {
console.log("Ajaxify already in array");
}
else {
console.log("Adding to array: " + ajaxify);
arrAjaxify.push(ajaxify);
checkAndDeleteEntry(ajaxify, $(this)).then(console.log("Checked and deleted if necessary"));
}
});
}
function parseDeleteTime(ajaxify) {
try {
var storyId = ajaxify.match(reStoryId)[1];
var deleteParent = $("#" + storyId).parent().parent().parent().attr("id");
if (deleteParent === undefined) {
return null;
}
var date = deleteParent.split("_");
var year = date[3];
var month = date[4];
var finalDate = new Date(year, month-1, 0, 0, 0, 0).getTime();
return finalDate;
}
catch (err) {
console.log("Cannot parse request because: " + err);
}
}
// Check if the entry matches the actions (e.g. like, post) which should be deleted and whether or not is old/young enough
function checkAndDeleteEntry(ajaxify, finding) {
var promise = new Promise(function (resolve, reject) {
if (reDelete.test(ajaxify)) {
var index = validActions.indexOf("delete");
if (index > -1) {
time = parseDeleteTime(ajaxify);
if (time > Date.now() - olderThan) {
console.log("Entry is new enough");
console.log("Now deleting the post");
$(finding).children('span').click();
}
else {
console.log("Nope, that seems to be too old to delete");
resolve();
}
}
resolve();
}
else{
time = parseTimestamp(ajaxify);
if (time > Date.now() - olderThan) {
console.log("Entry is new enough");
var index = validActions.indexOf(parseAction(ajaxify));
if (index > -1) {
console.log("Now deleting the like or comment");
$(finding).children('span').click();
}
}
}
resolve();
});
return promise;
}
injectUI();