var pdApp = {
init: function () {
document.title = $('#header-bottom-right .user a').first().text()+' | Power Delete Suite';
console.log('init');
if (window.pd_processing !== true) {
if (document.location.href.match('/user/') && $('.titlebox h1').first().text() === $('#header-bottom-right .user a').first().text()) {
pdApp.config = {
uh : $('#config').innerHTML ?
$('#config').innerHTML.replace(/.*?modhash.{1}: .{1}/,'').replace(/[^a-z0-9].*/,'') :
$('#config')[0].innerHTML.replace(/.*?modhash.{1}: .{1}/,'').replace(/[^a-z0-9].*/,''),
user : $('#header-bottom-right .user a').first().text()
};
pdApp.prepDom();
pdApp.parseSettings();
} else {
if (confirm('This script is designed to be run from your own user profile. Would you like to navigate there?')) {
document.location = 'http://reddit.com/u/'+ $('#header-bottom-right .user a').first().text();
}
}
}
},
prepDom: function () {
$('.sitetable,.neverEndingReddit').remove();
$('#pd__central,#pd__style').html(''); /*Debugging*/
if ($('#pd__central').length === 0) {
$('body>.content[role=\'main\']').append('
');
}
if ($('#pd__style').length === 0) {
$('head').first().append('');
}
pdApp.prepStyles();
pdApp.prepCentral();
$('#pd__central').wrapInner('');
},
prepStyles: function () {
$.ajax({
url: 'https://www.reddit.com/r/PowerDeleteSuite/about/stylesheet/.json',
context: $('#pd__style')
}).then(function(data) {
$(this)[0].innerHTML = data.data.stylesheet;
}, function() {
alert('Error retreiving CSS from /r/PowerDeleteSuite');
});
},
prepCentral: function () {
$.ajax({
url: 'https://www.reddit.com/r/PowerDeleteSuite/wiki/centralform.json',
context: $('#pd__central')
}).then(function(data) {
$(this).html($("").html(data.data.content_md).text());
pdApp.prepSubs();
pdApp.bindUI();
}, function() {
alert('Error retreiving markup from /r/PowerDeleteSuite');
});
},
prepSubs: function () {
var sub_arr = [], i, sid;
$('#per-sr-karma tbody th').each(function () {
sub_arr.push($(this).text());
});
sub_arr = sub_arr.sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
for (i=0;i');
}
$('#side-mod-list li').each(function() {
$('.sub--'+$(this).text().replace('/r/','')).prepend('[M]');
});
if (! localStorage.getItem('pd_storage')) {
$('#pd__sub-list input').prop('checked',true);
}
},
bindUI: function() {
$('.pd__q').click(function(e) {e.preventDefault(); alert($(this).closest('[data-help]').attr('data-help'));});
$('#pd__form').submit(function(e) {
e.preventDefault();
pdApp.saveSettings();
pdApp.process.init();
});
},
parseSettings: function () {
if (localStorage.getItem('pd_storage')) {
var i, temp_arr = JSON.parse(localStorage.getItem('pd_storage'));
$('#pd__form input').prop('checked',false).val('');
for (i=0;i 0) {
$('#pd__central').html('');
$('#pd__central').append('