Created
May 9, 2013 00:17
-
-
Save agentlame/5544664 to your computer and use it in GitHub Desktop.
multibantest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Multi Ban | |
| // @namespace reddit.com/r/agentlame | |
| // @description universal ban button | |
| // @include http://www.reddit.com/* | |
| // @include http://reddit.com/* | |
| // @include http://*.reddit.com/* | |
| // @downloadURL https://github.com/agentlame/multiban/raw/master/multiban.user.js | |
| // @version 1.0 | |
| // ==/UserScript== | |
| function globalbanbutton() { | |
| var banSubs = ["al_dev", "agentlame"]; | |
| var buttonName = 'ban'; | |
| addlinks(); | |
| // Add ban button to all users | |
| function addlinks() { | |
| $('.thing .entry').each(function () { | |
| var banneduser = $(this).find('.author:first').text(); | |
| if (banneduser) { | |
| $(this).find('.buttons li:last').before('<li><a href="javascript:;" class="global-ban-button" user="' + banneduser + '">' + buttonName + '</a></li>'); | |
| } | |
| }); | |
| } | |
| // RES NER support. | |
| $('div.content').on('DOMNodeInserted', function (e) { | |
| if (e.target.parentNode.id && e.target.parentNode.id === 'siteTable' && e.target.className.match(/sitetable/)) { | |
| addlinks(); | |
| } | |
| }); | |
| $('.global-ban-button').live('click', banPopup); | |
| // Ban button clicked | |
| function banPopup() { | |
| var banauthor = $(this).attr('user'); | |
| // Make box & add subreddit radio buttons | |
| var popup = $('\ | |
| <div class="ban-popup">\ | |
| <h2>/u/' + banauthor + '</h2><span>\ | |
| <label id="user" style="display:none">' + banauthor + '</label> \ | |
| <table><tbody /></table>\ | |
| <div class="buttons">\ | |
| <label for="type-ban"><input class="ban-type" type="radio" id="type-ban" value="ban" action="friend" name="type-ban">ban</label> / \ | |
| <label for="type-unban"><input class="ban-type" type="radio" id="type-unban" value="unban" action="unfriend" name="type-ban">unban</label> \ | |
| <span class="right">\ | |
| <button class="save">yis</button>\ | |
| <button class="cancel">naw</button>\ | |
| </span>\ | |
| <span class="status error"><br><br>saving...</span>\ | |
| <div>\ | |
| <div>') | |
| .appendTo('body') | |
| .css({ | |
| left: event.pageX - 50, | |
| top: event.pageY - 10, | |
| display: 'block' | |
| }); | |
| $(banSubs).each(function () { | |
| popup.find('tbody').append('<tr><th><input type="radio" class="ban-sub" name="ban-sub" value="' + this + '" id="ban-' + this + '"></th><td><label for="ban-' + this + '">/r/' + this + '</label></td></tr>'); | |
| }); | |
| return false; | |
| } | |
| // 'cancel' button clicked | |
| $('body').delegate('.ban-popup .cancel', 'click', function () { | |
| $(this).parents('.ban-popup').hide(); | |
| }); | |
| // 'save' button clicked | |
| $('body').delegate('.ban-popup .save', 'click', function () { | |
| var button = $(this), | |
| popup = button.parents('.ban-popup'), | |
| banType = popup.find('.ban-type:radio:checked').val(), | |
| action = popup.find('.ban-type:radio:checked').attr('action'), | |
| status = popup.find('.status').show(), | |
| subreddit = popup.find('.ban-sub:radio:checked').val(), | |
| user = popup.find('#user').text(); | |
| if (!subreddit) return status.text('error, no subreddit selected'); | |
| if (!banType) return status.text('error, no action selected'); | |
| $.post('/api/' + action, { | |
| uh: reddit.modhash, | |
| type: 'banned', | |
| name: user, | |
| r: subreddit, | |
| api_type: 'json' | |
| }) | |
| .done(function () { | |
| $('.ban-popup').hide(); | |
| }); | |
| }); | |
| } | |
| // Add scripts/style to page | |
| (function () { | |
| var css = '\ | |
| .ban-popup { max-width:500px;padding:10px 15px;background-color: #FAFAFA;border: 1px solid #369;position:absolute;z-index:10000} \ | |
| .ban-popup .right{ float:right }\ | |
| .ban-popup .status{ display:none; }\ | |
| .ban-popup tbody tr{ width: 200px; vertical-align:top; border-bottom:1px solid gray;display:block;padding:5px }\ | |
| .ban-popup th{ padding-right:10px }\ | |
| .ban-popup .buttons{ padding-top:10px }'; | |
| // Add CSS | |
| var style = document.createElement('style'); | |
| style.type = "text/css"; | |
| style.textContent = css; | |
| document.head.appendChild(style); | |
| // Add script | |
| var script = document.createElement('script'); | |
| script.textContent = "(" + globalbanbutton.toString() + ')();'; | |
| document.head.appendChild(script); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment