DU Community Help
Related: About this forumDU3 Mail multi-select delete GreaseMonkey script
Last edited Sun Dec 22, 2013, 03:45 AM - Edit history (3)
Want to have check boxes to select multiple DU Mails and delete them without having to open them? If you use FireFox and have the GreaseMonkey add-on installed this script will give you that functionality. (This should also work with Chrome/TamperMonkey or Opera(WebKit)/TamperMonkey - although I have not tested it in anything other than FireFox.)
This version is for testing. It will open an alert dialog to show the delete URL that would load and then loads the page to view the DU Mail that would be deleted. Once you are sure things are working as intended on your system, you can comment out the test lines and uncomment the lines that will actually perform the deletions (search for the text FOR TESTING to see what to to).
By default the script will bring up a confirm dialog before deleting each DU Mail, to defeat that you can set confirmEachDeleteFlag at the beginning of the code to false and no confirmation will be required.
[div class="excerpt" style="margin-left:1em; border:1px solid #bfbfbf; border-radius:0.4615em; box-shadow:-1px -1px 3px #999999 inset;"]// ==UserScript==
// @name DU Mail multi-select delete
// @description auto-loads selected DU Mail delete URLs
// @include http://www.democraticunderground.com/?com=inbox*
// @version 1
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
var confirmEachDeleteFlag=true;
function selectToggle(cbox) {
if(cbox.innerHTML==String.fromCharCode(9744))
cbox.innerHTML=String.fromCharCode(9746);
else
cbox.innerHTML=String.fromCharCode(9744);
}
function checkAll(stat) {
var msgs=document.getElementsByClassName("PM-delete-select" ;
for(var i=0,lgth=msgs.length;i<lgth;i++) {
if(stat==true)
msgs[i].innerHTML=String.fromCharCode(9746);
else
msgs[i].innerHTML=String.fromCharCode(9744);
}
}
function deleteNextMessage() {
var sent=location.search.indexOf('sent');
var page=GM_getValue("lstPage" ;
var list=GM_getValue("selMsgs" ;
if(list.length) {
var msgs=list.split(',');
var next=msgs.pop();
list=msgs.join();
GM_setValue("selMsgs",list);
// CONFIRM DELETE MESSAGE
try {
var cftx='Delete the following message?\n\n';
var mtch='view='+next+'"';
var tofm='FROM';
if(sent!=-1) {
mtch='viewsent='+next+'"';
tofm='TO';
}
var lmnt=document.getElementsByTagName("tbody" ;
var tbrw=lmnt[0].getElementsByTagName("tr" ;
for(var i=tbrw.length-1;i>=0;i--) {
var usnm=tbrw[i].getElementsByTagName("a" [0];
var ttle=tbrw[i].getElementsByTagName("a" [1];
if(ttle.outerHTML.indexOf(mtch)!=-1) {
cftx=cftx+'\n'+tofm+': '+usnm.innerHTML+'\n\nTITLE: '+ttle.innerHTML;
break;
}
}
}
catch(err) {
cftx=cftx+next;
}
var cnfm=false;
if(confirmEachDeleteFlag==true)
cnfm=confirm(cftx);
if((cnfm==true)||(confirmEachDeleteFlag==false)) {
if((page.length)&&(sent==-1)) {
// location.replace(page+'&action=delete&mid='+next+'#autoDeleting');
// FOR TESTING COMMENT OUT THE LINE ABOVE THIS AND UNCOMMENT THE TWO BELOW
alert('HREF='+page+'&action=delete&mid='+next+'#autoDeleting');
location.replace(page+'&view='+next+'#autoDeleting');
}
else if(page.length) {
// location.replace(page+'&action=deletesent&mid='+next+'#autoDeleting');
// FOR TESTING COMMENT OUT THE LINE ABOVE THIS AND UNCOMMENT THE TWO BELOW
alert('HREF='+page+'&action=deletesent&mid='+next+'#autoDeleting');
location.replace(page+'&viewsent='+next+'#autoDeleting');
}
else if(sent==-1) {
// location.replace('http://'+location.hostname+'/?com=inbox&action=delete&mid='+next+'#autoDeleting');
// FOR TESTING COMMENT OUT THE LINE ABOVE THIS AND UNCOMMENT THE TWO BELOW
alert('http://'+location.hostname+'/?com=inbox&action=delete&mid='+next+'#autoDeleting');
location.replace('http://'+location.hostname+'/?com=inbox&view='+next+'#autoDeleting');
}
else {
// location.replace('http://'+location.hostname+'/?com=inbox&action=deletesent&mid='+next+'#autoDeleting');
// FOR TESTING COMMENT OUT THE LINE ABOVE THIS AND UNCOMMENT THE TWO BELOW
alert('http://'+location.hostname+'/?com=inbox&action=deletesent&mid='+next+'#autoDeleting');
location.replace('http://'+location.hostname+'/?com=inbox&viewsent='+next+'#autoDeleting');
}
}
else {
deleteNextMessage();
}
}
else if(page.length) {
location.replace(page);
}
}
function deleteSelected() {
var cnfm=confirm("Delete selected messages?" ;
if(cnfm==true) {
var list="";
GM_setValue("selMsgs",list);
var page=location.href;
fdst=page.indexOf('&action=');
if(fdst==-1)
GM_setValue("lstPage",page);
else
GM_setValue("lstPage",page.slice(0,fdst));
var msgs=document.getElementsByClassName("PM-delete-select" ;
var cmpr = String.fromCharCode(9746);
for(var i=0,lgth=msgs.length;i<lgth;i++) {
if(msgs[i].innerHTML==cmpr) {
var mgid=msgs[i].id.slice(4);
list=list+mgid+',';
}
}
if(list.length) {
list=list.slice(0,-1); // remove end comma
GM_setValue("selMsgs",list);
deleteNextMessage()
}
}
else {
checkAll(false);
}
}
function addButton(prnt,text,nwid,plce) {
var dbtn=document.createElement("input" ;
dbtn.type='button';
dbtn.id=nwid;
dbtn.style.margin='0.6154em 0.6154em 0.6154em 0em';
dbtn.value=text;
if(plce=='top')
prnt.insertBefore(dbtn,lmnt.firstChild);
else
prnt.appendChild(dbtn);
}
// DELETE SELECTED EMAILS
if(location.hash=='#autoDeleting') {
deleteNextMessage();
}
// CREATE CHECKBOXES ON PAGE
else if(location.search.indexOf('&view')==-1) {
try {
// REMOVE FOCUS FROM MEMBER SEARCH TEXT FIELD
document.getElementById("search" .blur();
}
catch(err) {
}
try {
// ADD COLUMN HEADING
trow=document.getElementsByTagName("thead" [0].getElementsByTagName("tr" [0];
tbhd=document.createElement("th" ;
labl=document.createTextNode("Select" ;
tbhd.appendChild(labl);
trow.insertBefore(tbhd,trow.getElementsByTagName("th" [0]);
// ADD CHECKBOXES
trow=document.getElementsByTagName("tbody" [0].getElementsByTagName("tr" ;
for(i=0,lgth=trow.length;i<lgth;i++) {
inst=trow[i].insertCell(0);
inst.className="PM-delete-select";
inst.style.textAlign="center";
inst.style.cursor="pointer";
inst.innerHTML="☐";
titl=trow[i].getElementsByClassName("title" [0].getElementsByTagName("a" [0].outerHTML;
snip=titl.slice(29);
strt=snip.indexOf('=') + 30;
last=snip.indexOf('"') + 29;
idnm='del_'+titl.slice(strt,last);
inst.id=idnm;
inst.onclick=function(){selectToggle(this);};
}
// ADD BUTTONS
lmnt=document.getElementsByClassName("default-table-container" [0];
addButton(lmnt,"Select All","sel_all_btn","bottom" ;
document.getElementById("sel_all_btn" .onclick=function(){checkAll(true);};
addButton(lmnt,"Deselect All","sel_none_btn","bottom" ;
document.getElementById("sel_none_btn" .onclick=function(){checkAll(false);};
addButton(lmnt,"Delete Selected","delete_btn","bottom" ;
document.getElementById("delete_btn" .onclick=function(){deleteSelected();};
addButton(lmnt,"Delete Selected","delete_btn_top","top" ;
document.getElementById("delete_btn_top" .onclick=function(){deleteSelected();};
addButton(lmnt,"Deselect All","sel_none_btn_top","top" ;
document.getElementById("sel_none_btn_top" .onclick=function(){checkAll(false);};
addButton(lmnt,"Select All","sel_all_btn_top","top" ;
document.getElementById("sel_all_btn_top" .onclick=function(){checkAll(true);};
}
catch(err) {
}
}
Apparently the DU software strips out some javascript keywords so this didn't work and GreaseMonkey needs the added grant declarations to work right - updated to a working version.