-
I've tried a few ways, but as always, I dunno how. var whitelist = [
'Pepa', 'Max-Steel'
];
var blacklist = [
'John Wick 1', 'John Wick 2'
];
function filterMessage() {
if (whitelist.some(i => msg.title.indexOf(i) != -1)) { //is this fine?
msg.isImportant = true;
return MessageObject.Accept;
} else {
if (blacklist.some(i => msg.title.indexOf(i) != -1)) { //is this fine?
msg.assignLabel(msg.findLabelId('Boring/Futa/Furry/3D/CGI')); //are slash `/` even allowed here?
}
return MessageObject.Accept;
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Firstly, why not have two labels? Something like:
This way, you can see what's matched your wanted list and then everything else that matches your unwanted list is still there for review. So it looks like you want this to be marked Important:
and this to be in a label:
Then what do you want to do with everything else? Do you only want the articles matching either of the conditions above in the database? Or do you want the above to happen and also keep all other articles? This part is unclear to me. Anyway, the main problem part is the 'else if' statement. The syntax is slightly incorrect but enough to stop it from working altogether. You need to change this:
to this:
I changed the condition to be case-insensitive but you can adjust if necessary. So the full working filter would be:
At the very end is:
but if you still want to keep everything else, obviously change it to:
and those articles will be neither marked Important, nor in a label but they'll still be there in the feed. I'd also avoid using slashes in label names. Usually you'd need to escape special characters with a backslash but why risk it? Javascript requires escaping special characters but if you can create a label with special characters then it could become a bit messy. In the example above I call the label 'Unwanted'. Probably best to keep it simple. You can also obviously remove the line:
if you really don't want that. |
Beta Was this translation helpful? Give feedback.
-
Wait - what are you calling a 'label'? Labels aren't separated by a comma. Are you talking about variables?:
Yes, this highlights the importance of doing your own testing instead of blindly using something someone else told you would work - just like I did. Oops! Glad you figured out how to adapt it to your own situation. The '(!' at the beginning of the line is to negate, meaning 'NOT'. So I obviously got it a bit wrong there while I was copy/pasting one of my own filters. |
Beta Was this translation helpful? Give feedback.
-
I see what you're referring to now. That's just a visual thing which I suppose doesn't bother me. Also, I'm using a DevBuild version which has the label names disabled for now so all I see in those columns are numbers. It doesn't affect anything other than whether or not you like seeing it that way but you figured out a solution you like best for that anyway. I got my filters by simply learning just like you. I was a bit stuck when I first started but filters are powerful and once you get the idea of how to construct them it becomes easier. All you really need is to learn the basics of Javascript and you don't really need to go much beyond that. In fact, what I do is take the time to create a filter, do lots of testing, then pretty much copy and paste it for other filters and adapt as needed. Filters become simpler when you get the hang of them. However, mine look extremely complex now but it's just because they contain many of the different elements. It's basically:
The first filter is the hardest - then it's just copy/paste. It also helps to use something that can help you visualise things. There are many online Javascript editors. Now I use Kate (part of KDE Plasma), set the highlighting to Javascript and then it will colourise everything and will highlight matching parentheses and curly braces. You'll find your own workflow that suits you. I'm by no means an expert - I'm still learning myself. |
Beta Was this translation helpful? Give feedback.
-
Hi guys, so is the discussion solved? If not please feel free to ask me questions about each single issue you have. |
Beta Was this translation helpful? Give feedback.
Firstly, why not have two labels? Something like:
This way, you can see what's matched your wanted list and then everything else that matches your unwanted list is still there for review.
So it looks like you want this to be marked Important:
and this to be in a label:
Then what do you want to do with everything else? Do you only want the articles matching either of the conditions above in the database? Or do you want the above to happen and also keep all other articles? This part is unclear to me.
Anyway, the main problem part is the 'else if' statement. The syntax is sligh…