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.

Difference between revisions of "User:Lethosor/spamblock.js"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
(Created page with "function spamBlockUser(username, element){ if(!element) element=$('<span>'); element=$(element) new mw.Api().post({ user: username, action: 'block', expiry: 'never', r...")
 
m (strikethrough)
 
(One intermediate revision by the same user not shown)
Line 13: Line 13:
 
}).done(function(d){console.log('done',d);element.text('Done')}).fail(function(e){console.log('fail', e);element.text('Error: '+e)});
 
}).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),
 +
    $this = $(this);
 +
  conf.find('[href=#yes]').click(function(e){
 +
    e.preventDefault();
 +
    conf.hide();
 +
    console.log('blocking ' + username);
 +
    spamBlockUser(username, prog);
 +
    $this.css('text-decoration', 'line-through');
 +
  });
 +
  conf.find('[href=#no]').click(function(e){
 +
    e.preventDefault();
 +
    conf.hide(); spamLink.show();
 +
  });
 +
  spamLink.click(function(e){
 +
    e.preventDefault();
 +
    spamLink.hide(); conf.show();
 +
  });
 +
});

Latest revision as of 14:44, 14 December 2013

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),
    $this = $(this);
  conf.find('[href=#yes]').click(function(e){
    e.preventDefault();
    conf.hide();
    console.log('blocking ' + username);
    spamBlockUser(username, prog);
    $this.css('text-decoration', 'line-through');
  });
  conf.find('[href=#no]').click(function(e){
    e.preventDefault();
    conf.hide(); spamLink.show();
  });
  spamLink.click(function(e){
    e.preventDefault();
    spamLink.hide(); conf.show();
  });
});