Skip to content

Instantly share code, notes, and snippets.

@SeinopSys
Last active August 29, 2015 14:00
Show Gist options
  • Save SeinopSys/5e918adadb5af4a2f977 to your computer and use it in GitHub Desktop.
Save SeinopSys/5e918adadb5af4a2f977 to your computer and use it in GitHub Desktop.
deviantArt Correspondence Message Cleaner
(function(pageStepDelay,screwComments){
var halfStepDelay = pageStepDelay / 2;
if (!/\.deviantart\.com$/.test(window.location.host) || !/^\/notifications\/?$/.test(window.location.pathname))
return false;
function notify(message,visibleForMS,callback){
console.log(message);
if (visibleForMS !== false) visibleForMS = typeof visibleForMS === 'number' ? visibleForMS : 3000;
var heightTally = 0, $notifs = $('body > .corrclean');
if ($notifs.length > 0){
$notifs.each(function(){
heightTally += $(this).outerHeight()+10;
});
}
var $corrclean = $(document.createElement('div')).addClass('corrclean').css({
position: 'fixed',
'z-index': 5e2,
right: '0px',
top: '-90px',
margin: '10px 10px 0px 0px',
'background-color': '#dae4d9',
'background-image': 'url(http://st.deviantart.net/minish/gruzecontrol/gmtop.gif?1)',
'background-repeat': 'repeat-x',
'border': '1px solid #a6b2a6',
'border-radius': '5px',
'box-shadow': '0px 0px 10px black',
color: '#000',
padding: '10px',
}).appendTo(document.body);
$corrclean.text(message).animate({top:heightTally+'px'},500,function (){
if (typeof callback === 'function') callback();
if (visibleForMS !== false) setTimeout(function(){
$('body > .corrclean').fadeOut(400,function(){
$(this).remove();
});
},visibleForMS+3000);
});
}
var accepted = 0,
hasComments = 0,
$mczoneTitle = $('.mczone-title:contains(Correspondence):visible'),
tally = {accepted:0,hasComments:0,checked:0}, tallyFunc = function(obj){
if (typeof obj !== "object"){
var waswere = function(n){return n>1?'were':'was'},
message = "Checking finished. ";
if (tally.accepted > 0 || tally.hasComments > 0){
if (tally.accepted > 0) message += tally.accepted+"/"+tally.checked+" accepted & removed, ";
if (tally.hasComments > 0){
message += tally.hasComments+(tally.accepted>0?'':' out of '+tally.checked)+" message"+(tally.checked!==1?'s':'')+" ";
if (screwComments) message += "had comments but "+waswere(tally.hasComments)+" removed anyway";
else message += waswere(tally.checked)+" not removed due to comments";
}
else message += "none had comments";
}
else if (tally.checked === 1) message += "The only item was not accepted";
else message += "None of the "+tally.checked+" items were accepted";
notify(message+'.');
return;
}
$.each(['accepted','hasComments','checked'],function(i,key){
if (obj[key] > 0) tally[key] += obj[key];
});
return obj;
};
window.CCTimeout = 0;
if ($mczoneTitle.length === 0) return false;
else $mczoneInner = $mczoneTitle.next();
var $mczoneFooter = $mczoneInner.next().find('.td-footer');
if ($mczoneFooter.css('visibility') === 'visible'){
var $prevPage = $mczoneFooter.find('a.l').next(),
i = 0,
goFwd = function(){
notifyBegin();
// Check It
console.group('Checking initiated');
window.CCStart = new Date().getTime();
checkit(1);
// Move to each new page and check them
var $nextPage = $mczoneFooter.find('a.r'), i = 1;
recur = function (){
CCTimeout = pageStepDelay+(i*pageStepDelay);
setTimeout(function(){
checkit(i);
},halfStepDelay);
setTimeout(function(){
$nextPage = $mczoneFooter.find('a.r');
if ($nextPage.length && CCTimeout < 100000){
$nextPage.on('click',recur).trigger('click');
}
else if (CCTimeout >= 100000){
console.groupEnd();
notify('Paginator function overflow: Max execution time of 100 seconds exceeded');
return tallyFunc();
}
else {
console.groupEnd();
return tallyFunc();
}
},pageStepDelay);
i++;
};
setTimeout(function(){
if ($nextPage.length) $nextPage.on('click',recur).trigger('click');
else {
console.log('Ran out of pages, this was the first and last check');
tallyFunc();
}
},pageStepDelay);
};
// Move to first page
function notifyBegin(){ notify('Checking started, Correspondence Cleaner will now look through all pages...') }
if ($prevPage.length){
window.location.hash = 'page=correspondence-1';
setTimeout(function(){
goFwd();
},pageStepDelay);
}
else goFwd();
}
else {
checkit(1);
tallyFunc();
}
function checkit(p,recheck){
var a = 0,
h = 0,
$mczoneInner = $mczoneTitle.next(),
$mczIChild = $mczoneInner.children(),
c = $mczIChild.length+0;
console.group('Checking '+c+' items'+(recheck === true?' again':'')+' on page #'+p+(recheck === true?' due to removed items':'')+' @ '+((new Date().getTime()) - window.CCStart)+'ms...');
$mczIChild.each(function(i){
var $this = $(this),
$vote = $this.find('.vote-float'),
voteText = $vote.text().trim(),
remove = function(){ $this.find('.mcx').trigger('click') };
if (/^(Accepted|Decided)/.test(voteText)){
if (/No\s+Comments$/i.test(voteText)){
a++;
remove();
console.log('#%d was accepted and had no comments, removed.',i);
}
else {
h++;
if (screwComments) remove();
console.log('#%d is accepted and has comments, '+(screwComments?'removed':'skipping')+'.',i);
}
}
else console.log('#%d is not accepted, moving on.',i);
});
if (h+a > 0) checkit(p,true);
else if (recheck === true)
console.groupEnd();
console.log('%d items checked.',c);
console.groupEnd();
return tallyFunc({accepted:a,hasComments:h,checked:recheck === true?0:c});
}
})(1000,false);
javascript:(function(e,t){function r(e,t,n){console.log(e);if(t!==false)t=typeof t==="number"?t:3e3;var r=0,i=$("body > .corrclean");if(i.length>0){i.each(function(){r+=$(this).outerHeight()+10})}var s=$(document.createElement("div")).addClass("corrclean").css({position:"fixed","z-index":500,right:"0px",top:"-90px",margin:"10px 10px 0px 0px","background-color":"#dae4d9","background-image":"url(http://st.deviantart.net/minish/gruzecontrol/gmtop.gif?1)","background-repeat":"repeat-x",border:"1px solid #a6b2a6","border-radius":"5px","box-shadow":"0px 0px 10px black",color:"#000",padding:"10px"}).appendTo(document.body);s.text(e).animate({top:r+"px"},500,function(){if(typeof n==="function")n();if(t!==false)setTimeout(function(){$("body > .corrclean").fadeOut(400,function(){$(this).remove()})},t+3e3)})}function d(e,n){var r=0,i=0,s=o.next(),u=s.children(),f=u.length+0;console.group("Checking "+f+" items"+(n===true?" again":"")+" on page #"+e+(n===true?" due to removed items":"")+" @ "+((new Date).getTime()-window.CCStart)+"ms...");u.each(function(e){var n=$(this),s=n.find(".vote-float"),o=s.text().trim(),u=function(){n.find(".mcx").trigger("click")};if(/^(Accepted|Decided)/.test(o)){if(/No\s+Comments$/i.test(o)){r++;u();console.log("#%d was accepted and had no comments, removed.",e)}else{i++;if(t)u();console.log("#%d is accepted and has comments, "+(t?"removed":"skipping")+".",e)}}else console.log("#%d is not accepted, moving on.",e)});if(i+r>0)d(e,true);else if(n===true)console.groupEnd();console.log("%d items checked.",f);console.groupEnd();return a({accepted:r,hasComments:i,checked:n===true?0:f})}var n=e/2;if(!/\.deviantart\.com$/.test(window.location.host)||!/^\/notifications\/?$/.test(window.location.pathname))return false;var i=0,s=0,o=$(".mczone-title:contains(Correspondence):visible"),u={accepted:0,hasComments:0,checked:0},a=function(e){if(typeof e!=="object"){var n=function(e){return e>1?"were":"was"},i="Checking finished. ";if(u.accepted>0||u.hasComments>0){if(u.accepted>0)i+=u.accepted+"/"+u.checked+" accepted & removed, ";if(u.hasComments>0){i+=u.hasComments+(u.accepted>0?"":" out of "+u.checked)+" message"+(u.checked!==1?"s":"")+" ";if(t)i+="had comments but "+n(u.hasComments)+" removed anyway";else i+=n(u.checked)+" not removed due to comments"}else i+="none had comments"}else if(u.checked===1)i+="The only item was not accepted";else i+="None of the "+u.checked+" items were accepted";r(i+".");return}$.each(["accepted","hasComments","checked"],function(t,n){if(e[n]>0)u[n]+=e[n]});return e};window.CCTimeout=0;if(o.length===0)return false;else $mczoneInner=o.next();var f=$mczoneInner.next().find(".td-footer");if(f.css("visibility")==="visible"){var l=f.find("a.l").next(),c=0,h=function(){p();console.group("Checking initiated");window.CCStart=(new Date).getTime();d(1);var t=f.find("a.r"),i=1;recur=function(){CCTimeout=e+i*e;setTimeout(function(){d(i)},n);setTimeout(function(){t=f.find("a.r");if(t.length&&CCTimeout<1e5){t.on("click",recur).trigger("click")}else if(CCTimeout>=1e5){console.groupEnd();r("Paginator function overflow: Max execution time of 100 seconds exceeded");return a()}else{console.groupEnd();return a()}},e);i++};setTimeout(function(){if(t.length)t.on("click",recur).trigger("click");else{console.log("Ran out of pages, this was the first and last check");a()}},e)};function p(){r("Checking started, Correspondence Cleaner will now look through all pages...")}if(l.length){window.location.hash="page=correspondence-1";setTimeout(function(){h()},e)}else h()}else{d(1);a()}})(1e3,false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment