var pdApp = { version: '1.2.3', bookmarkver: '1.1', init : function() { pdApp.checkVersions(); if (window.pd_processing !== true) { document.title = $('#header-bottom-right .user a').first().text()+' | Power Delete Suite'; if (document.location.hostname.split('.').slice(-2).join('.') == 'reddit.com' && 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.setup.prepDom(); } 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/me'; } } setTimeout(pdApp.helpers.restoreSettings,500); return pdApp.version; } else { return 'PowerDeleteSuite is already running'; } }, checkVersions: function () { if (pdApp.debugging) { return true; } /* version alerts */ if (typeof window.bookmarkver === 'undefined' || window.bookmarkver !== pdApp.bookmarkver) { if (confirm('There\'s been an update to the bookmarklet. Would you like to go to the Github repo in order to get the latest version?')) { document.location.href = 'https://github.com/j0be/PowerDeleteSuite'; return false; } } pdApp.prevRunVersion = localStorage.getItem('pd_ver') ? localStorage.getItem('pd_ver') : '0'; localStorage.setItem('pd_ver',pdApp.version); if (pdApp.version !== pdApp.prevRunVersion) { if (confirm('You\'ve gotten the latest update! You are now running PowerDeleteSuite v'+pdApp.version+'. Would you like to open the changelog in a new tab?')) { $.ajax({ url: '/r/PowerDeleteSuite/new.json' }).then(function(data) { window.open('http://reddit.com'+data.data.children[0].data.permalink); }, function() { window.open('http://reddit.com/r/PowerDeleteSuite'); }); } } }, setup: { prepDom: function () { window.onerror = function() { window.pd_processing = false; alert('We ran into an error. Why not tell /u/j0be what you were doing to break it?'); pdApp.init(); }; $('.sitetable,.neverEndingReddit').remove(); if (pdApp.debugging) {$('#pd__central,#pd__style').remove('');} if ($('#pd__central').length === 0) { $('body>.content[role=\'main\']').append('
'); } if ($('#pd__style').length === 0) { $('head').first().append(''); } pdApp.setup.prepStyles(); pdApp.setup.prepCentral(); }, prepStyles: function () { $.ajax({ url: '/r/PowerDeleteSuite/about/stylesheet/.json', context: $('#pd__style') }).then(function(data) { $(this)[0].innerHTML = data.data.stylesheet; $('#pd__central').show(); }, function() { alert('Error retreiving CSS from /r/PowerDeleteSuite'); }); }, prepCentral: function () { $.ajax({ url: '/r/PowerDeleteSuite/wiki/centralform.json', context: $('#pd__central') }).then(function(data) { $(this).html($("").html(data.data.content_md).text()); if ($('#pd__stlye').html() === '') { $(this).hide(); } $(this).find('h2').first().text('Power Delete Suite v'+pdApp.version); pdApp.setup.prepSubs(); pdApp.setup.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()); }); $('#pd__sub-list').append(''); for (i=0;iCompleted after making '+pdApp.process.ajaxCalls+' calls to the reddit servers.
'+ (pdApp.process.edited > 0 ? 'If you need to re run the script, just click the bookmarklet again!
' ); document.title = $('#header-bottom-right .user a').first().text()+' | Power Delete Suite'; } }, filters: {}, debugging: false }; pdApp.init();