Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modules['voteThreshold'] = {
- moduleID: 'voteThreshold',
- moduleName: 'Vote Threshold',
- //category: 'Filters',
- options: {
- keywords: {
- type: 'table',
- fields: [{
- name: 'Subreddit',
- type: 'text'
- }, {
- name: 'Vote threshold',
- type: 'text'
- }],
- value: [],
- description: 'Type in the subreddit name and then choose the minimum vote total for posts from that subreddit.'
- }
- },
- description: 'Filter subreddit posts which fall below the specified threshold.',
- isEnabled: function () {
- return RESConsole.getModulePrefs(this.moduleID);
- },
- include: Array(/https?:\/\/([a-z]+).reddit.com\/?(?:\??[\w]+=[\w]+&?)*/i),
- 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),
- isMatchURL: function () {
- return RESUtils.isMatchURL(this.moduleID);
- },
- applyThresholdFilter: function (ele) {
- if (this.options.keywords.value) {
- var votes, votesThreshold, thisPost, thisSR, subs = this.options.keywords.value;
- for (var i = 0, lene = ele.length; i < lene; i += 1) {
- thisPost = ele[i];
- thisSR = thisPost.querySelector('.subreddit').innerHTML.toLowerCase();
- for (var x = 0, lens = subs.length; x < lens; x += 1) {
- if (thisSR === subs[x][0]) {
- votes = Number(thisPost.querySelector('.score.unvoted').innerHTML);
- if (typeof (votes) === 'NaN') {
- votes = 0;
- }
- votesThreshold = Number(subs[x][1]);
- if (votes < votesThreshold) {
- thisPost.setAttribute('style', 'display:none !important');
- break;
- }
- }
- }
- }
- }
- },
- go: function () {
- if ((this.isEnabled()) && (this.isMatchURL())) {
- if (this.options.keywords.value) {
- document.body.addEventListener('DOMNodeInserted', function (event) {
- if ((event.target.tagName == 'DIV') && (event.target.getAttribute('id') && event.target.getAttribute('id').indexOf('siteTable') != -1)) {
- var ele = event.target.querySelectorAll('.thing');
- modules['voteThreshold'].applyThresholdFilter(ele);
- }
- }, false);
- var ele = document.querySelectorAll('.sitetable .thing');
- this.applyThresholdFilter(ele);
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement