Advertisement
gavin19

RES - Mod helper

Nov 15th, 2011
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. modules['modHelper'] = {
  2.     moduleID: 'modHelper',
  3.     moduleName: 'Moderation Helper',
  4.     category: 'UI',
  5.     options: {
  6.         cannedReplies: {
  7.             type: 'table',
  8.             fields: [
  9.                 { name: 'label', type: 'text' },
  10.                 { name: 'body', type: 'text' }
  11.             ],
  12.             value: [],
  13.             description: 'Set a series of default replies below.'
  14.         }
  15.     },
  16.     description: 'Helps you moderate your subreddits',
  17.     isEnabled: function() {
  18.         return RESConsole.getModulePrefs(this.moduleID);
  19.     },
  20.     include: new Array(
  21.         /https?:\/\/([a-z]+).reddit.com\/[\?]*/i
  22.     ),
  23.     isMatchURL: function() {
  24.         return RESUtils.isMatchURL(this.moduleID);
  25.     },
  26.     go: function() {
  27.         if ((this.isEnabled()) && (this.isMatchURL())) {
  28.             document.body.addEventListener('DOMNodeInserted', function(event) {
  29.                 if (event.target.tagName == 'DIV' && hasClass(event.target, 'markdownEditor')) {
  30.                     if(modules['modHelper'].options.cannedReplies.value) {
  31.                     var replies = modules['modHelper'].options.cannedReplies.value;
  32.                    
  33.                         var selector = document.createElement('select');
  34.                         selector.setAttribute('style','width:60px;');
  35.                         var option = document.createElement('option');
  36.                         option.text = 'Canned Replies';
  37.                         selector.add(option);
  38.                         for(var i = 0;i<replies.length;i++) {
  39.                             var option = document.createElement('option');
  40.                             option.value = replies[i][1];
  41.                             option.text = replies[i][0];
  42.                             selector.add(option);
  43.                         }
  44.                         var textArea = event.target.parentNode.getElementsByTagName('textarea')[0]
  45.                         selector.addEventListener('change', function(e) {
  46.                             if(selector.value.indexOf('\\n')!==-1){
  47.                                 var a = selector.value.split('\\n');
  48.                                 for(var x=0,len=a.length;x<len;x+=1){
  49.                                     textArea.value += a[x];
  50.                                     textArea.value +="\n";
  51.                                 }
  52.                             } else {
  53.                             textArea.value += selector.value;
  54.                             }
  55.                         });
  56.                         event.target.appendChild( selector );            
  57.                 }
  58.                 }
  59.             });
  60.         }
  61.     }
  62. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement