Forums / Discussion / General

233,618 total conversations in 7,806 threads

+ New Thread


Sticky Sticky
Image Filtering Userscript

Last posted May 04, 2024 at 04:16AM EDT. Added Feb 19, 2019 at 10:21PM EST
54 posts from 28 users

This is my attempt at writing a filter for galleries that will hide content based on its entry or uploader username.

With the script on, every entry page and user profile will have a button that will add them to the filter.



All the galleries will then be filtered according to what you wanted to hide. A menu with your options will also show up at the bottom right of the page.

A known limitation is that images that are too small can't be filtered by the uploader because they are missing the little info bar, but you rarely see those kind of upload sizes.

Update:
I've also made another script that achieves filtering by replacing the old layout with a new one. It can also toggle the filters on/off and the change is immediately shown. NSFW/spoilers can also be unhidden automatically.

If you want to try it out, you have to first install Tampermonkey and then click the following link to trigger the installation of the script:

https://github.com/standoda/kym-isotope-filtering/raw/master/isotope_image_filtering.user.js

Last edited Oct 23, 2022 at 09:48PM EDT

Dude… it actually works for me. And it even works for Trending images, not just New images.

Mad respect. Thanks for actually providing solutions for KYM's problems despite not having any obligation to do so, and against all odds.

Also, do you think you could make this work with tags..? Entry names and user names are very useful indeed, but if you could somehow make it work for tags, we could make it a KYM user's habit of verbally tagging NSFW images as "nsfw" from now on (maybe even as "fanart" for the ones not necessarily lewd enough to have a NSFW tag but still close enough to the concept) in the actual tags and tackle that problem out too. It could really mark a before-and-after in people's browsing experience if possible to pull off. But still, even without it, good job, man. I hope people do not have too many compatibility issues with this; it at least works fine with me, I can assure you (Chrome user on desktop PC).

Last edited Feb 19, 2019 at 10:58PM EST

Pictures marked as NSFW can be easily filtered as well. I've updated the script to include a filter for NSFW and spoilers.

Now from my understanding the actual tags of each upload can only be seen when you open the page of the image. So filtering for those tags will require the script to make an abnormal amount of requests to the website and that will get you banned.

The website is using some kind of auto-tagging system for pictures that we can see from gallery pages and so we can use that for scripting purposes, but such tags are either too simplsitic or a total mess because they include whatever text is detected in images.
Although I have to say that it does a pretty good job at tagging anime pictures as "Cartoon Anime", but it often misses some stuff or it tags as anime what could be considered a western illustration.

Made your OP post permanently editable should you wish to do so. Also enjoy a sticky.


The website is using some kind of auto-tagging system for pictures that we can see from gallery pages and so we can use that for scripting purposes, but such tags are either too simplsitic or a total mess because they include whatever text is detected in images.

KYM uses Google cloud vision.

Last edited Feb 20, 2019 at 12:31PM EST

PatrickBateman96 wrote:

It says a lot about admins competence when some random user who barely uses the site essentially does their job for them.

I mean… is that technically not how Trending images work too..? About 95% of the Trending stuff is user-submitted and it gives KYM a good chunk of its page views, specially on off-seasons while nothing viral like Bowsette, Ugandan Knuckles or Harambe is happening to give the site millions of clicks.

@e

Can confirm, the NSFW filter works perfectly. Thank you. Now I will just direct people to this thread whenever people start whining about "too much NSFW" existing. In fact, can a mod sticky this thread..? The more people know about this, the better. I, on my part, will soon whip up an image post to try and promote this script around, since the forums are essentially dead, so getting a Trending image about this should help a lot.

Last edited Feb 20, 2019 at 10:31PM EST

Thank you for the comments and thanks for the perm edit @RandomMan

I think something even better can be achieved if the grid layout that kym currently uses is updated to the new one that supports filtering called Isotope

With a few lines of code I managed to replace the old Masonry grid with Isotope and the result was pretty cool:

This way filtering is more straightforward and you have full support for hiding/showing elements, but we still have to see if it holds up when you have a lot of pics loaded.

You can try the new layout with this other script, which includes all the filters from before but now you can toggle them on/off and see the change in real time:

https://github.com/standoda/kym-isotope-filtering/raw/master/isotope_image_filtering.user.js

I left the transitions on for some eye candy, if I work on the script again I might include something that turns them off idk.

Last edited Feb 22, 2019 at 10:40PM EST

I have no doubt this will be extremely helpful for those who don't want to see the Grotesque Steve images. This is absolutely impressive

First script works like a charm on my account. Isotope does not, unfortunately, also it puts the KYM Facebook link behind the trending pictures for some reason. Still, awesome job on you filter, bro.

Triplem wrote:

First script works like a charm on my account. Isotope does not, unfortunately, also it puts the KYM Facebook link behind the trending pictures for some reason. Still, awesome job on you filter, bro.

I was hiding the "stay up-to-date" banners with uBlock Origin so I didn't notice that anomaly.

I just updated the script so that they stay hidden, can you try the Isotope script again? If it doesn't work, what browser are you using and can you see errors in the console when you open the dev tools with F12?

I can run the script fine on the latest versions of Chrome, Firefox and Opera.

e wrote:

I was hiding the "stay up-to-date" banners with uBlock Origin so I didn't notice that anomaly.

I just updated the script so that they stay hidden, can you try the Isotope script again? If it doesn't work, what browser are you using and can you see errors in the console when you open the dev tools with F12?

I can run the script fine on the latest versions of Chrome, Firefox and Opera.

The banners are back to their place, but the Isotope filtering part still doesn't seem to work.
I'm using Firefox, fully updated to my knowledge.
And yes, last time I tried to copy-paste the Isotope script, there were a lot of errors; most noticeably, the script formed two giant lines.
It might also interest you that ever since the new layout update – the square display of the trending pictures, a month ago – , I get a black screen whenever I left-click one, instead of the picture properly appearing.
Well, don't work on that too hard though. As previously stated, it isn"t either your job or responsability, and you've pulled an enourmous task so far already. Your script is really great the way it is.

PatrickBateman96 wrote:

It says a lot about admins competence when some random user who barely uses the site essentially does their job for them.

Gonna ignore the snark for a second because I know the quality of the user making it. I saw a similar comment mention this as well but also including that mods often tell users it's impossible. So you know what time it is…….

STORY TIME

Come and gather around children, take a seat on RM's manly squat legs, as I tell you how KYM's coding is pretty broken:

(Meaning this is a general reply towards others thinking this since I know this is a popular stance)

For starters: We mean it when we tell users some demands are impossible. After the "Show fewer ponies" button, we got demands for making it customizable and possibly link it to your account settings.

"Yeah but the show fewer ponies button means this is possible!!!"

Well that's where you're wrong. You see, the button is only available on the all-images tab of the site. Which uses the following url:

https://knowyourmeme.com/photos

If you activate the filter, your url changes to this:

https://knowyourmeme.com/photos?fewer-ponies=1

It's not saved to your account, it's not saved to your browser, it's just a link and you will need to reactivate it upon each gallery visit. The filter is not actually a filter, it just directs you to a seperate cache of the image gallery. This is, to my understanding from limited communication with our former coder, why it's difficult to make a custom filter: It requires a seperate cache for each filter setting.

This is also why a similar browser extension for NSFW actually made by a mod works best as an extension. Linking your preferred account NSFW settings would require a seperate gallery cache for each user account. A million images times a million accounts, we don't have that server space.

"But that sounds retarded!"

It is retarded. That's how bad KYM's site coding is. The coding is simply very dated, from a time when they simply never expected the site to reach this size. Fixing it can be done, but requires the galleries to be build from the ground up. I hope it sounds reasonable that when your coder is 1 guy priorities are different.

One thing I assume possible is something similar as the pony button but for example with NSFW or certain entry types (subcultures, memes, etc). But I need a refresh from the coder to confirm.

"But Daddy RM, the extensions!"

Ye you see, site extensions break the limits of what is allowed within the site's coding. They are to go… even… further… beyond…

Extensions are the Super Saiyan 3 of customization… just saiyan

They link to your browser, not the site cache or your user profile. This makes them more functionable, but even then they can break the site (the earlier mentioned NSFW tag remove filter for example had an issue where it would send too many requests to the site). Logging out doesn't affect them, switching desktops does.

Add to that what I mentioned before, we got 1 coder. Currently he's working on fixing that issues where the galleries can break. The old coder spend a lot of time on improving the mobile version. A professional site coder has different priorities and limitations than a guy who loves making a script extension. For example the staff prefers updates to entry categorization above gallery filters (and understandably so).

But the above includes a lot of dated knowledge. We got a new coder with a ton of Ruby on Rails experience. He's still trying to get used to the site entrails, but he'll get there. Maybe he can look at it from a different way and make things work. I myself definitely need an update on KYM's inner-workings, so never quote me on anything about it. We linked him this thread, the rest is a waiting game.

Improves are possible, unfortunately never as easy as we'd hope.

Story time over, go to bed.

Last edited Feb 24, 2019 at 06:11PM EST

I can't get it to filter anything other than NSFW. To be clear, the format is (for example) |furries|? Do we just type that in with spaces in the "Entry Filters" box? It's not working for me.

gnbman wrote:

I can't get it to filter anything other than NSFW. To be clear, the format is (for example) |furries|? Do we just type that in with spaces in the "Entry Filters" box? It's not working for me.

Try using the "Add to Filter" button when you open the entry page. When you edit the text field manually you have to hit save and then reload the page.

By the way if you're browsing a gallery of an entry you were filtering then it only filters for users or nsfw/spoilers, otherwise it would hide everything and it wouldn't make sense.

If you care enough, i have a script that un-hide the NSFW images in the list, if you like to incorporate it in your script;


(function() {

var $ = window.jQuery;
function reveal() {
var mod = false;
var x = document.getElementsByClassName("img-nsfw");
for(var i in x){
if(x[i].getAttribute != null && x[i].src != x[i].getAttribute("data-original-image-url")){
x[i].src = x[i].getAttribute("data-original-image-url");
x[i].style.border = "1px solid #ff0000";
x[i].style.height = "auto";
mod = true;
}
}

if(mod){ $("#photo_gallery").masonry(); } } window.setInterval(function(){ reveal(); }, 500);

})();

This is awesome. Thanks for posting this.

We have some ideas to add filtering like this to the site, though I'm not sure when we will be able to roll it out. I will update with more info when we have it figured out.

Hey guys, you have identified one of the big issues we are addressing.

I see that this approach is done by selecting entries you want to hide.

Could you give me some specific examples of your use cases? For instance, which entries do you want to hide and why? And if you could hide some but not all of that content, where would you draw the line?

Is the main goal to hide the anime?

What is it about the emotional triggers of the content that makes you want to avoid it? If it's not obvious from your other comments. Thanks!

Mike wrote:

Hey guys, you have identified one of the big issues we are addressing.

I see that this approach is done by selecting entries you want to hide.

Could you give me some specific examples of your use cases? For instance, which entries do you want to hide and why? And if you could hide some but not all of that content, where would you draw the line?

Is the main goal to hide the anime?

What is it about the emotional triggers of the content that makes you want to avoid it? If it's not obvious from your other comments. Thanks!

"Is the main goal to hide the anime?"

that's the funniest thing i've heard all day

Thank you @Don.

@jajaja
I was thinking about including the unveiling of hidden pictures as well, thanks for the input.

By the way you if you want to unhide the pictures only when new ones are shown, I've found that you can overwrite a function that is called for unveiling new images at every scroll. Check out this script for how I would do it:

https://pastebin.com/raw/5PvtA9vN

It's very short and there's no need to attach to events like layoutComplete or have a timer.

That's for a stand-alone script, implementing the unhiding in my first or second script would be better done by using the same function that is iterating new pictures to set the filter.

P.S. The unhiding script linked above would not work with the isotope script because it's removing the calls to the unveiling function. The first script instead might be improved by using this unveil instead of hooking the layoutComplete.

leatherfootclone wrote:

"Is the main goal to hide the anime?"

that's the funniest thing i've heard all day

Destroy anime. The danger is no joke.


Admin feedback was better than I expected. So consider me excited.

I guarantee my earlier post was no bullshit, mod knowledge was very dated. But a new coder and much better communication between staff and mods can really work miracles it seems. I could never expect this feedback a couple of years ago.

Don't plan on using it myself. Still, if this works it will be great. Mods have been wanting this for around half a decade. Big categories I can think of off the top of my head there being large demand to be able to hide (and this would include the children of these type of entries)

  • Politics
  • Donald Trump
  • Twitter hastags/controversies
  • Controversies in general

The biggest complaint on the site for the last few years seems to be the political and controversy related content. I think that if any one specific thing to hide would have a positive impact on the userbase, it would be this.

  • Internet Paraphilas

Most people don't really wanna see weird fetish images unless that is their fetish. That having been said, this one might also be the one people will want a lot of options on. A Macrophila pic might be something a person would be perfectly fine with seeing, but they are grossed out by people being turned into balloons.

  • Anime/Manga

Most people are okay with anime/manga (and related content, but those who aren't are pretty vocal about it.) Might also include other things that are anime-esque like Touhou, Gacha games, Fire Emblem, RWBY, etc.

  • Deliberately racist content (Happy Merchant, Sheeeit, A Wyatt Man comics, etc.)

Deliberately racist content should be pretty obvious (though how far you wanna stretch that it is going to be a slippery slope. These examples should be easy to agree about at least)

  • Entries that are made of generally creepy, disturbing, or otherwise unsettling images (Smile.jpg, Creepypasta, Trypophobia, Mouth Eyes, Creepy Steve)

Disturbing images should be pretty obvious, though of as with paraphilas, what disturbs some won't disturb others. The ones I listed everyone generally agrees that they are intended to try to disturb, even if personally you might not have a reaction to those images.

Last edited Feb 25, 2019 at 08:17PM EST

ralphie1231 wrote:

Jesus Christ man, thank you soooooooo much. Now I'm not gonna have 50 fucking crying wojaks shoved into my face whenever I go to images.

I tested it myself for this purpose and it does not seem to be working. I tried both user filtering and gallery filtering and, at best, it seems to work for the first page on "New", but everything after that remains unfiltered. It probably has something to do with the fact that your current URL changes when you browse down on images.

Nedhitis wrote:

I tested it myself for this purpose and it does not seem to be working. I tried both user filtering and gallery filtering and, at best, it seems to work for the first page on "New", but everything after that remains unfiltered. It probably has something to do with the fact that your current URL changes when you browse down on images.

Works fine for me on Chrome 84.0.4147.135 64-bit.

Nedhitis wrote:

I tested it myself for this purpose and it does not seem to be working. I tried both user filtering and gallery filtering and, at best, it seems to work for the first page on "New", but everything after that remains unfiltered. It probably has something to do with the fact that your current URL changes when you browse down on images.

Yeah, I've had the same problem too. You'll have to download it from this link: https://github.com/standoda/kym-isotope-filtering/raw/master/isotope_image_filtering.user.js
This changes the layout so that the images are filtered from every page.

It works, but is a pain in ass. I suggest adding to filter while hovering over image.

Thanks, anyway.

Last edited Aug 25, 2020 at 04:44PM EDT

The isotope script was updated, now there's filtering buttons in the sidebar of the image overlay.
The images are scanned all over again when adding/removing filters using those overlay buttons (or when manually saving the filter lists), so provided that you're still on the same gallery page, a refresh to apply the changes is not needed.

I just noticed a bug of your extension that manifests during the loading of new pictures in a gallery. Take notes, 'cause it's a bit complex to follow:
The first 20 pictures that you get after clicking on the link to the gallery work just fine. If you load 20n more by scrolling down, however, you cannot immediately do this navigation thing where you click on one picture to see it, then click on the left or right arrow to see the previous or next one. Only the 20 pictures from the beginning seem to be registered for this service at first (for instance, if at this point you click on the 2nd picture of the gallery, it'll be marked "2/20" instead of "2/40", and clicking the right arrow when you're viewing the 20th picture will bring you back to the 1st picture instead of displaying the 21st picture).
It is possible to add the other pictures to this navigation service, but first you have to manually click on each of them. Somehow, it also looks like the order of these pictures in the gallery is taken into account (continuing from the previous example, if I click on picture n° 24, it'll be added to the list, and marked "21/21"; if I then click on picture n°40, it'll be added, and marked "22/22"; and if I then click on picture n° 30, it'll be added, and marked "22/23", because picture n°30 comes before picture n°40 in the gallery).
It's nothing of a catastrophic bug, only an anomaly that inconveniences a select few of the users, but it could be something to look at.

Last edited Oct 01, 2023 at 04:41AM EDT

Triplem wrote:

I just noticed a bug of your extension that manifests during the loading of new pictures in a gallery. Take notes, 'cause it's a bit complex to follow:
The first 20 pictures that you get after clicking on the link to the gallery work just fine. If you load 20n more by scrolling down, however, you cannot immediately do this navigation thing where you click on one picture to see it, then click on the left or right arrow to see the previous or next one. Only the 20 pictures from the beginning seem to be registered for this service at first (for instance, if at this point you click on the 2nd picture of the gallery, it'll be marked "2/20" instead of "2/40", and clicking the right arrow when you're viewing the 20th picture will bring you back to the 1st picture instead of displaying the 21st picture).
It is possible to add the other pictures to this navigation service, but first you have to manually click on each of them. Somehow, it also looks like the order of these pictures in the gallery is taken into account (continuing from the previous example, if I click on picture n° 24, it'll be added to the list, and marked "21/21"; if I then click on picture n°40, it'll be added, and marked "22/22"; and if I then click on picture n° 30, it'll be added, and marked "22/23", because picture n°30 comes before picture n°40 in the gallery).
It's nothing of a catastrophic bug, only an anomaly that inconveniences a select few of the users, but it could be something to look at.

Script was updated to load the navigation gallery as expected.
I actually left that out on purpose and choose to only load the images on clicks, since I never used that and I found some unexpected behavior with the original code.

Boring bug report ahead:
I was supposed to replicate/copy whatever the website was doing to add those images, but I found that the original code was doing something weird, where it basically called the addition of the same images hundreds of times, and apparently it's still doing that.

Basically one would expect the new images to be added in bulk each time a new page loaded, instead the website is re-processing the entire gallery to be added there, triggered for every single new image loaded, not every page.

So after the first page is loaded normally, the second page will append 22 items (20 images + 2 ads), this will trigger 22*40=880 calls to load the images to that navigation gallery.
The end result is the same as if the images were added correctly so this was never catched I guess.

Back then I was thinking of reporting this in its own thread but I kinda forgot about it.
Hopefully this post will be helpful if any dev wants to have a look at it.

From the main JS file, a breakpoint on the following line can show it being called several times for new pages:

$(this).find("a.photo").each(function() {

blank profile pic wrote:

@e
I filtered the Bing Image Creator gallery, but it still shows up when I go to the Image Search. Anything I can do about that?

Can you confirm that the usual "Trending" and "All" galleries work fine at filtering?
When you "search the database" instead there's a bit of an inconsistency where the website is not exposing the entry in the item's URL, which is what's used by the script.

e wrote:

Can you confirm that the usual "Trending" and "All" galleries work fine at filtering?
When you "search the database" instead there's a bit of an inconsistency where the website is not exposing the entry in the item's URL, which is what's used by the script.

Just checked, they do work. But I almost never visit Trending anyway since I'm not really interested in it. If there's not much that can be done about the search database, then I apologize if it sounds like I'm asking for too much. I figure this stuff can't exactly be easy (especially what with everything I've heard about the code up to now (I myself am very far from an expert on this stuff)).

O HAI! You must login or signup first!