// ==UserScript== // @name Mallet // @namespace drupal // @description Kill comments in bulk on a user's tracker. Hi killes! // @author Brandon Bergren (bdragon) // @version 0.1 // @include http://drupal.org/user/*/track // @include http://d6.drupal.org/user/*/track // ==/UserScript== // Make shortcuts to jQ and Drupal objects. $ = unsafeWindow.jQuery; Drupal = unsafeWindow.Drupal; // Bail out in (the unlikely) case that JS has been disabled. if (Drupal === undefined) { alert('JS is disabled in target?'); return false; } // User id to consider. var uid = unsafeWindow.document.location.href.toString() .replace(/^.*\/([^\/]+)\/track$/, "$1"); // List of nodes to consider. var nodeUrls = []; // List of comment delete forms to process. var killUrls = []; Drupal.behaviors.malletSearchNodes = function (context) { $('#tracker tr td:nth-child(2) a:not(.malletSearchNodes-processed)', context) .addClass('malletSearchNodes-processed') .each(function (i, val) { // Build the node list from the tracker table. nodeUrls.push(val.toString()); }); } Drupal.behaviors.malletAddButton = function (context) { if ($('#mallet-button', context).size() === 0) { var delB = /\/comment\/delete\//; var comment; $('#tracker table:first-child', context) .before('
'); $('#mallet-button', context).one('click', function() { // Wait until everything's calmed down again before showing the big red button. $('#mallet-button', context).one('ajaxStop', function () { $('#mallet-button', context).after(' '); $('#mallet-kill-button', context).one('click', function() { if (confirm('Are you absolutely sure you want to MASS-DELETE comments for this user?')) { $('#mallet-button', context).one('ajaxStop', function () { alert('Done!'); }); // Recurse the kill urls and forge the confirmation pages for everything. $('#mallet-log', context).empty(); $.each(killUrls, function(i, val) { $.get(val, {}, function (data, textStatus) { $('#mallet-log', context).append('Running ' + val.toString() + '...
'); var formData = $('form#comment-confirm-delete', data).serialize(); // Simulate the Delete button being clicked. formData = formData + '&op=Delete'; // DANGER -- This line goes and does it! $.post(val, formData); }); }); } }); }); //width: 600px; height: 300px; overflow: scroll; $(this).after(''); $.each(nodeUrls, function (i, val) { // Debug check -- limit how much it actually processes. //if (i < 3) { $.get(val, {}, function (data, textStatus) { $('#mallet-log', context).append('From ' + val + ':
'); $('.comment', data).each(function (i) { comment = this; $('.author a', this).each(function (i) { if (this.toString().replace(/.*\//, "") == uid) { $('#mallet-log', context).append(comment); $('.links a', comment).each(function (i) { if (delB.test(this.toString())) { killUrls.push(this.toString()); } }); } }); }); }); //} }); }); } } // Force attaching behaviors -- Drupal skips this when things weren't previously // "dynamic" (I think.) $(unsafeWindow.document).ready(function () { Drupal.attachBehaviors(unsafeWindow.document); });