From 35e61729bfadf5e4dbafe489a20b251dace2a869 Mon Sep 17 00:00:00 2001 From: j0be Date: Mon, 30 Jan 2017 17:46:30 -0500 Subject: [PATCH] v1.2.3 * Added a new filter for filtering based on score * Made it possible to run from a different subdomain than "www" * Added bookmarklet version checking to announce when there is a new version of it that is needed to be downloaded * Bookmarklet does a location check without jquery to make sure that people who don't read the instructions saying to run it from your profile will get an alert telling them to run it from their profile. * Improved css --- powerdeletesuite.js | 116 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 92 insertions(+), 24 deletions(-) diff --git a/powerdeletesuite.js b/powerdeletesuite.js index a8367e9..1e67f35 100644 --- a/powerdeletesuite.js +++ b/powerdeletesuite.js @@ -1,19 +1,14 @@ var pdApp = { - version: '1.2.2', + version: '1.2.3', + bookmarkver: '1.1', init : function() { - /* version alerts */ - 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?')) { - window.open('https://www.reddit.com/r/PowerDeleteSuite/'); - } - } + pdApp.checkVersions(); if (window.pd_processing !== true) { document.title = $('#header-bottom-right .user a').first().text()+' | Power Delete Suite'; - console.log('init'); - if (document.location.href.match('/user/') && $('.titlebox h1').first().text() === $('#header-bottom-right .user a').first().text()) { + 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].*/,'') : @@ -32,10 +27,40 @@ var pdApp = { 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(); - $('#pd__central,#pd__style').remove(''); /*Debugging*/ + if (pdApp.debugging) {$('#pd__central,#pd__style').remove('');} if ($('#pd__central').length === 0) { $('body>.content[role=\'main\']').append('
'); } @@ -47,7 +72,7 @@ var pdApp = { }, prepStyles: function () { $.ajax({ - url: 'https://www.reddit.com/r/PowerDeleteSuite/about/stylesheet/.json', + url: '/r/PowerDeleteSuite/about/stylesheet/.json', context: $('#pd__style') }).then(function(data) { $(this)[0].innerHTML = data.data.stylesheet; @@ -58,7 +83,7 @@ var pdApp = { }, prepCentral: function () { $.ajax({ - url: 'https://www.reddit.com/r/PowerDeleteSuite/wiki/centralform.json', + url: '/r/PowerDeleteSuite/wiki/centralform.json', context: $('#pd__central') }).then(function(data) { $(this).html($("