diff --git a/powerdeletesuite.js b/powerdeletesuite.js
index fce6c25..0eba829 100644
--- a/powerdeletesuite.js
+++ b/powerdeletesuite.js
@@ -1,5 +1,5 @@
var pd = {
- version: '1.3.1',
+ version: '1.4.0',
bookmarkver: '1.1',
init : function() {
pd.checks.versions();
@@ -98,6 +98,9 @@ var pd = {
if ($('#pd__stlye').html() === '') {
$(this).hide();
}
+ if (pd.debugging) {
+ $(this).find('.debugging').removeClass('debugging');
+ }
$(this).find('h2').first().text('Power Delete Suite v'+pd.version);
pd.setup.applySubList();
pd.setup.bindUI();
@@ -125,6 +128,8 @@ var pd = {
},
createProcessStream: function () {
window.pd_processing = true;
+ pd.exportItems = [];
+ pd.exportIds = [];
pd.task = {
after: '',
info: {
@@ -143,24 +148,27 @@ var pd = {
deleted: 0,
errors: 0,
ignored: 0,
+ exported: 0,
ignoreReasons: {
subs: 0,
gold: 0,
saved: 0,
mod: 0,
score: 0,
+ date: 0,
}
},
config: {
+ isExporting: $('#pd__export').is(':checked'),
isRemovingPosts: $('#pd__submissions').is(':checked'),
isRemovingComments: $('#pd__comments').is(':checked'),
isEditing: $('#pd__comments-edit').is(':checked'),
editText: $('#pd__comments-edit-text').val(),
},
paths: {
- sections: $('#pd__submissions').is(':checked') ?
- ['comments','submissions','search'] :
- ['comments','search','submissions'], /* Search is actually more efficient than submissions if we're not handling submissions (`self:1`) */
+ sections: ! $('#pd__submissions').is(':checked') && ! $('#pd__export').is(':checked') ?
+ ['comments','search','submissions'] : /* Search is actually more efficient than submissions if we're not handling submissions (`self:1`) */
+ ['comments','submissions','search'],
sorts : ['new','hot','top','controversial']
}
};
@@ -174,6 +182,11 @@ var pd = {
gt: $('#pd__score-dirtoggle').is(':checked'),
num: parseFloat($('#pd__score-num').val())
},
+ date: {
+ enabled: $('#pd__date').is(':checked'),
+ gt: $('#pd__date-dirtoggle').is(':checked'),
+ num: Math.floor((new Date).getTime()/1000)-(parseFloat($('#pd__date-num').val())*60)
+ },
gilded: $('#pd__gilded').is(':checked'),
saved: $('#pd__saved').is(':checked'),
mod: $('#pd__mod').is(':checked'),
@@ -206,13 +219,15 @@ var pd = {
});
$('.gt-toggle').change(function() {
var greaterThan = $(this).hasClass('greater');
- $(this).next('label').text(greaterThan ? 'Less than' : 'Greater than');
$(this).attr('class','gt-toggle hidden ' + (greaterThan ? 'less' : 'greater'));
});
$('.num-only').blur(function() {
$(this).val($(this).val().replace(/[^\d-]/g,''));
$(this).change();
});
+ $('.pd__insert').click(function() {
+ $($(this).attr('data-target')).val($(this).attr('data-value')).change();
+ });
},
},
helpers: {
@@ -221,7 +236,7 @@ var pd = {
return {valid:false,reason:'Please enter something to edit your comments / self posts to.'};
} else if (pd.filters.score && $('#pd_score-num').val() === '') {
return {valid:false,reason:'Please enter a score to filter with.'};
- } else if (!(pd.task.config.isRemovingPosts || pd.task.config.isEditing || pd.task.config.isEditing)) {
+ } else if (!(pd.task.config.isRemovingPosts || pd.task.config.isEditing || pd.task.config.isEditing || pd.task.config.isExporting)) {
return {valid:false,reason:'There are no actions chosen, so we\'ve got nothing to do. Please select an action.'};
}
return {valid:true,reason:'valid'};
@@ -237,12 +252,24 @@ var pd = {
(pd.filters.score.enabled && (
(pd.filters.score.gt === true && parseFloat(item.data.score) > pd.filters.score.num) ||
(pd.filters.score.gt === false && parseFloat(item.data.score) < pd.filters.score.num)
+ )),
+ date: !pd.filters.date.enabled ||
+ (pd.filters.date.enabled && (
+ (pd.filters.date.gt === true && parseFloat(item.data.created_utc) > pd.filters.date.num) ||
+ (pd.filters.date.gt === false && parseFloat(item.data.created_utc) < pd.filters.date.num)
))
};
for(var key in check) {if (! check[key]) {
pd.task.info.ignoreReasons[key] ++;
+ pd.task.items[0].pdIgnoreReasons = check;
}}
- return check.subs && check.gold && check.saved && check.mod && check.score;
+ return check.subs && check.gold && check.saved && check.mod && check.score && check.date;
+ },
+ csvEscape: function(str) {
+ return str.replace(/'/g,'"').replace(/"/g,'""');
+ },
+ csvCell: function(str) {
+ return '"'+str+'",';
},
getSettings: function() {
return localStorage.getItem('pd_storage') ? JSON.parse(localStorage.getItem('pd_storage')) : false;
@@ -278,6 +305,9 @@ var pd = {
actions: {
page: {
next: function() {
+ if (pd.debugging && pd.task.info.donePages % 5 == 3) {
+ pd.actions.page.shift();
+ }
if (pd.task.paths.sections.length > 0) {
pd.ui.updateDisplay();
pd.actions.page.handle();
@@ -298,17 +328,17 @@ var pd = {
url: pd.endpoints[pd.task.paths.sections[0]],
data: {
q: pd.task.paths.sections[0] == 'search' ?
- 'author:'+pd.config.user + (! pd.task.isRemovingPosts ? ' self:1' : '') :
+ 'author:'+pd.config.user + (! pd.task.config.isRemovingPosts && !pd.task.config.isExporting ? ' self:1' : '') :
null,
after: pd.task.after,
- sort: pd.task.paths.sorts[0]
+ sort: pd.task.paths.sorts[0],
+ t: 'all',
}
}).then(function(resp) {
if (resp.data) {
var children = resp.data.children;
pd.task.info.donePages ++;
if (children.length > 0) {
- pd.task.info.numPages ++;
pd.task.info.doneItems = 0;
pd.task.info.numItems = children.length;
pd.task.items = children;
@@ -348,9 +378,18 @@ var pd = {
}
},
handleSingle: function () {
- var item = pd.task.items[0];
pd.ui.updateDisplay();
- if (pd.helpers.shouldBeActedOn(item)) {
+ var item = pd.task.items[0],
+ shouldBeActedOn = pd.helpers.shouldBeActedOn(item),
+ earlyExitNewItems = pd.task.paths.sorts[0] == 'new' && pd.filters.date.gt === true && pd.task.items[0].pdIgnoreReasons && !pd.task.items[0].pdIgnoreReasons.date;
+
+ if (earlyExitNewItems) {
+ console.log('Skipping the rest of the things sorted by new');
+ pd.task.items[0].pdIgnored = true;
+ pd.actions.children.finishItem();
+ pd.actions.page.shift();
+ pd.actions.page.next();
+ } else if (shouldBeActedOn) {
if (!item.pdEdited && ((item.data.is_self || item.kind == 't1') && pd.task.config.isEditing)) {
pd.actions.edit(item);
} else if (!item.pdDeleted && ((item.kind == 't3' && pd.task.config.isRemovingPosts) || (item.kind == 't1' && pd.task.config.isRemovingComments))) {
@@ -371,7 +410,34 @@ var pd = {
pd.task.info.deleted += pd.task.items[0].pdDeleted ? 1 : 0;
pd.task.info.edited += pd.task.items[0].pdEdited ? 1 : 0;
pd.task.info.ignored += pd.task.items[0].pdIgnored ? 1 : 0;
+ if (pd.task.config.isExporting && !pd.task.items[0].pdIgnored) {
+ pd.actions.children.exportItem(pd.task.items[0]);
+ }
pd.task.items.splice(0,1);
+ },
+ exportItem: function(item) {
+ var str = '';
+ if (pd.exportItems.length == 0) {
+ str += pd.helpers.csvCell('Title');
+ str += pd.helpers.csvCell('Body');
+ str += pd.helpers.csvCell('Permalink');
+ str+= pd.helpers.csvCell('Actions');
+ pd.exportItems.push(str);
+ }
+
+ if (pd.exportIds.indexOf(item.data.id) == -1) {
+ str = '';
+ str += pd.helpers.csvCell(pd.helpers.csvEscape(item.data.title ? item.data.title : ''));
+ str += pd.helpers.csvCell(pd.helpers.csvEscape(item.data.body ? item.data.body : ''));
+ str += pd.helpers.csvCell(item.data.permalink ?
+ 'http://reddit.com'+item.data.permalink :
+ 'http://reddit.com/r/'+item.data.subreddit+'/comments/'+(item.data.link_id.replace(/^t\d_/,''))+'/x/'+item.data.id+'?context=3'
+ );
+ str+= pd.helpers.csvCell((item.pdEdited ? 'edited ' : '') + (item.pdDeleted ? 'deleted ' : ''));
+ pd.exportItems.push(str);
+ pd.exportIds.push(item.data.id);
+ pd.task.info.exported ++;
+ }
}
},
delete: function (item) {
@@ -435,65 +501,65 @@ var pd = {
ui: {
updateDisplay: function () {
$('#pd__central h2').first().html('Power Delete Suite v'+pd.version+'
'+pd.task.paths.sections[0]+'/'+pd.task.paths.sorts[0]+'');
+ pd.task.info.numPages = pd.task.info.donePages + ((pd.task.paths.sections.length - 1)*4) + (pd.task.paths.sorts.length);
$('#progress_page .bar').css('width',(Math.round(1000*pd.task.info.donePages/pd.task.info.numPages)/10)+'%');
- $('#progress_page .text').text(pd.task.info.donePages + ' / ' + pd.task.info.numPages);
+ $('#progress_page .text').attr('data-top', pd.task.info.donePages).attr('data-bottom',pd.task.info.numPages);
if (pd.task.info.numItems > 0) {
$('#progress_item .bar').css('width',(Math.round(1000*pd.task.info.doneItems/pd.task.info.numItems)/10)+'%');
- $('#progress_item .text').text(pd.task.info.doneItems + ' / ' + pd.task.info.numItems);
+ $('#progress_item .text').attr('data-top', pd.task.info.doneItems).attr('data-bottom',pd.task.info.numItems);
}
- $('#progress_desc').html(
- (pd.task.info.edited > 0 ? '
Completed after making '+pd.task.ajaxCalls+' calls to the reddit servers.
'+ - (pd.task.info.edited > 0 ? 'Completed after making '+pd.task.info.ajaxCalls+' calls to the reddit servers.
If you need to re run the script, click here to go back to the beginning!
'); } else { - el.innerHTML = - 'All Done! It seems like all '+pd.task.info.ignored+' items we came across were ignored.
'; - } - - if (pd.task.info.ignored > 0) { - var str = 'All Done! It seems like all '+pd.task.info.ignored+' items we came across were ignored.
If you need to re run the script, click here to go back to the beginning!
'); } + $('#pd__central .complete .summary .restart').click(function() { + pd.init(); + }); var numSubs = $('#pd__sub-list input:checked').length; $('#pd__sub-list input').prop('checked',false); var debugInfo = JSON.stringify($('#pd__form').serializeArray()) + ' number of subreddits: '+numSubs; - el.innerHTML += - 'If you need to re run the script, just click the bookmarklet again!
' + - '