Advertisement
gavin19

Vote Threshold

Feb 3rd, 2012
137
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.         threshold: {
  7.             type: 'text',
  8.             value: '-10',
  9.             description: 'Posts with less than the specified (negative) value will be hidden'
  10.         }
  11.     },
  12.     description: 'Filter subreddit posts which fall below the specified threshold.',
  13.     isEnabled: function () {
  14.         return RESConsole.getModulePrefs(this.moduleID);
  15.     },
  16.     include: Array(/https?:\/\/([a-z]+).reddit.com\/?(?:\??[\w]+=[\w]+&?)*/i),
  17.     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),
  18.     isMatchURL: function () {
  19.         return RESUtils.isMatchURL(this.moduleID);
  20.     },
  21.     applyThresholdFilter: function (ele) {
  22.         var votes,
  23.             thisPost,
  24.             thisVW,
  25.             vwThreshold = this.options.threshold.value;
  26.         for (var i=0, len=ele.length; i < len; i+=1) {
  27.             thisPost = ele[i];
  28.             if(thisPost.innerHTML && thisPost.innerHTML.match(/\-/)){
  29.                 thisVW = thisPost.innerHTML.replace(/\[|\]/g,'');
  30.                 if(thisVW>vwThreshold) {
  31.                     thisPost.parentNode.parentNode.parentNode.setAttribute('style','opacity:0.3');
  32.                 }
  33.             }  
  34.         }
  35.     },
  36.     go: function () {
  37.         if ((this.isEnabled()) && (this.isMatchURL())) {
  38.             document.body.addEventListener('DOMNodeInserted', function (event) {
  39.                 if ((event.target.tagName == 'DIV') && (event.target.getAttribute('id') && event.target.getAttribute('id').indexOf('siteTable') != -1)) {
  40.                     var ele = event.target.querySelectorAll('.thing .voteWeight');
  41.                     modules['voteThreshold'].applyThresholdFilter(ele);
  42.                 }
  43.             }, false);
  44.             setTimeout(function(){var ele = document.querySelectorAll('.sitetable .thing .voteWeight');
  45.             modules['voteThreshold'].applyThresholdFilter(ele);},3000);
  46.         }
  47.     }
  48. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement