v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

User:Lethosor/spamblock.js

From Dwarf Fortress Wiki
< User:Lethosor
Revision as of 01:47, 14 December 2013 by Lethosor (talk | contribs) (works!)
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files
function spamBlockUser(username, element){
if(!element) element=$('<span>');
element=$(element)
new mw.Api().post({
  user: username,
  action: 'block',
  expiry: 'never',
  reason: 'Unacceptable username: Suspected spammer. [[DF:Unblock|See this page]] if you believe this block was made in error.',
  autoblock: 1,
  nocreate: 1,
  noemail: 1,
  token: mw.user.tokens.values.editToken,
}).done(function(d){console.log('done',d);element.text('Done')}).fail(function(e){console.log('fail', e);element.text('Error: '+e)});
}
$('ul > li').filter(function(){return $(this).text().match(/User account.*was created/i)}).each(function(){
  var blockLink = $(this).find('a:contains(block)').append(' | '),
    username = $(this).find('a:not(:contains(User creation log)):nth(0)').text(),
    span = $('<span>').insertAfter(blockLink),
    spamLink = $('<a href="#">').text('Spam block').appendTo(span),
    conf = $('<span>Are you sure? <a href="#yes">Yes</a> <a href="#no">No</a>').hide().appendTo(span),
    prog = $('<span>').appendTo(span);
  conf.find('[href=#yes]').click(function(e){
    e.preventDefault();
    conf.hide();
    console.log('blocking ' + username);
    spamBlockUser(username, prog);
  });
  conf.find('[href=#no]').click(function(e){
    e.preventDefault();
    conf.hide(); spamLink.show();
  });
  spamLink.click(function(e){
    e.preventDefault();
    spamLink.hide(); conf.show();
  });
});