Advertisement
gavin19

RES - Vote Threshold

Oct 17th, 2011
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. modules['voteThreshold'] = {
  2.     moduleID: 'voteThreshold',
  3.     moduleName: 'Vote Threshold',
  4.     //category: 'Filters',
  5.     options: {
  6.         keywords: {
  7.             type: 'table',
  8.             fields: [{
  9.                 name: 'Subreddit',
  10.                 type: 'text'
  11.             }, {
  12.                 name: 'Vote threshold',
  13.                 type: 'text'
  14.             }],
  15.             value: [],
  16.             description: 'Type in the subreddit name and then choose the minimum vote total for posts from that subreddit.'
  17.         }
  18.     },
  19.     description: 'Filter subreddit posts which fall below the specified threshold.',
  20.     isEnabled: function () {
  21.         return RESConsole.getModulePrefs(this.moduleID);
  22.     },
  23.     include: Array(/https?:\/\/([a-z]+).reddit.com\/?(?:\??[\w]+=[\w]+&?)*/i),
  24.     exclude: Array(/https?:\/\/([a-z]+).reddit.com\/r\/[-\w\.]+/i, /https?:\/\/([a-z]+).reddit.com\/[-\w\.\/]+\/comments\/[-\w\.]+/i, /https?:\/\/([a-z]+).reddit.com\/user\/[-\w\.]+/i, /https?:\/\/([a-z]+).reddit.com\/message\/[-\w\.]+/i),
  25.     isMatchURL: function () {
  26.         return RESUtils.isMatchURL(this.moduleID);
  27.     },
  28.     applyThresholdFilter: function (ele) {
  29.         if (this.options.keywords.value) {
  30.             var votes, votesThreshold, thisPost, thisSR, subs = this.options.keywords.value;
  31.             for (var i = 0, lene = ele.length; i < lene; i += 1) {
  32.                 thisPost = ele[i];
  33.                 thisSR = thisPost.querySelector('.subreddit').innerHTML.toLowerCase();
  34.                 for (var x = 0, lens = subs.length; x < lens; x += 1) {
  35.                     if (thisSR === subs[x][0]) {
  36.                         votes = Number(thisPost.querySelector('.score.unvoted').innerHTML);
  37.                         if (typeof (votes) === 'NaN') {
  38.                             votes = 0;
  39.                         }
  40.                         votesThreshold = Number(subs[x][1]);
  41.                         if (votes < votesThreshold) {
  42.                             thisPost.setAttribute('style', 'display:none !important');
  43.                             break;
  44.                         }
  45.                     }
  46.                 }
  47.             }
  48.         }
  49.     },
  50.     go: function () {
  51.         if ((this.isEnabled()) && (this.isMatchURL())) {
  52.             if (this.options.keywords.value) {
  53.                 document.body.addEventListener('DOMNodeInserted', function (event) {
  54.                     if ((event.target.tagName == 'DIV') && (event.target.getAttribute('id') && event.target.getAttribute('id').indexOf('siteTable') != -1)) {
  55.                         var ele = event.target.querySelectorAll('.thing');
  56.                         modules['voteThreshold'].applyThresholdFilter(ele);
  57.                     }
  58.                 }, false);
  59.                 var ele = document.querySelectorAll('.sitetable .thing');
  60.                 this.applyThresholdFilter(ele);
  61.             }
  62.         }
  63.     }
  64. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement