-
-
Save jewel-andraia/4297203 to your computer and use it in GitHub Desktop.
This file contains 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
filterTitle: function(title, reddit) { | |
var reddit = (reddit) ? reddit.toLowerCase() : null; | |
return this.arrayContainsSubstring(this.options.keywords.value, title.toLowerCase(), reddit); | |
}, | |
filterDomain: function(domain, reddit) { | |
var reddit = (reddit) ? reddit.toLowerCase() : null; | |
var domain = (domain) ? domain.toLowerCase() : null; | |
return this.arrayContainsSubstring(this.options.domains.value, domain, reddit); | |
}, | |
filterSubreddit: function(subreddit) { | |
return this.arrayContainsSubstring(this.options.subreddits.value, subreddit.toLowerCase(), null, true); | |
}, | |
filterFlair: function(flair, reddit) { | |
var reddit = (reddit) ? reddit.toLowerCase() : null; | |
return this.arrayContainsSubstring(this.options.flair.value, flair.toLowerCase(), reddit); | |
}, | |
unescapeHTML: function(theString) { | |
var temp = document.createElement("div"); | |
$(temp).html(theString); | |
var result = temp.childNodes[0].nodeValue; | |
temp.removeChild(temp.firstChild); | |
delete temp; | |
return result; | |
}, | |
arrayContainsSubstring: function(obj, stringToSearch, reddit, fullmatch) { | |
stringToSearch = this.unescapeHTML(stringToSearch); | |
var i = obj.length; | |
while (i--) { | |
if ((typeof(obj[i]) != 'object') || (obj[i].length<3)) { | |
if (obj[i].length == 1) obj[i] = obj[i][0]; | |
obj[i] = [obj[i], 'everywhere','']; | |
} | |
var searchString = obj[i][0]; | |
var applyTo = obj[i][1]; | |
var applyList = obj[i][2].toLowerCase().split(','); | |
var skipCheck = false; | |
switch (applyTo) { | |
case 'exclude': | |
if (applyList.indexOf(reddit) != -1) { | |
skipCheck = true; | |
} | |
break; | |
case 'include': | |
if (applyList.indexOf(reddit) == -1) { | |
skipCheck = true; | |
} | |
break; | |
} | |
// if fullmatch is defined, don't do a substring match... this is used for subreddit matching on /r/all for example | |
if ((!skipCheck) && (fullmatch) && (obj[i] != null) && (stringToSearch.toLowerCase() == searchString.toLowerCase())) return true; | |
if ((!skipCheck) && (!fullmatch) && (obj[i] != null) && (stringToSearch.indexOf(searchString.toString().toLowerCase()) != -1)) { | |
return true; | |
} | |
} | |
return false; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment