r/userscripts • • Jul 07 '26

Pixiv slop block userscript

I was tired of seeing slop on pixiv so i've developer an userscript to remove it in some way, it can be found here

https://github.com/MonoS/Pixiv-Slop-Block

It does not work on mobile version of the site, but it does when switching to Desktop Mode.

I've never written an usescript before, but it was pretty simple, any suggestion is welcome.

4 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/MonoS94 Jul 08 '26

I refactored the code and made the logo less jarring, what do you think?

1

u/Kqyxzoj Jul 08 '26

Yeah, nice, the new logo is much less visually distracting. I also like how the new one blends into the canvas background now. This is much better! On the visual side I have one last detail, that white heart symbol on the AI-slop images. Personally I would want to remove it on the AI-slop images. Again for visual distraction reasons. But maybe you want to keep it because it is uesful to you. In the event that you would like to get rid of the visual distraction of that white heart on slop-AI images ... that white heart probably is located in the same enclosing <div> or <span> as the image itself. So should be pretty easy to find / select that element. You could do: in the same for-loop as you use for the slop-AI image replacement, you just delete the element that contains the white heart thingy. So right after illusts[key].url = noAIBannerSVG;. Another way would be to add a "noAIBanner" or something class to either the enclosing element or the heart thingy itself. And then add a ".noAIBanner" or similar CSS style element that turns it 100% transparent. I think adding filter: and then with opacity value of 0, that should probably do the trick. That way the white heart element is still there, but it is totally transparent.

As for javascript side, yeah, that's also a lot better. There are still a few things about the foreach loop that can be simplified, but I'll just mention the most straightforward change... Currently you iterate over the keys, but then only ever use the referenced value, not the key itself. In that case it is simpler to just iterate over the values right away, no need for that key intermediate step.

So Object.keys(illusts).forEach(key => { would become Object.values(illusts).forEach(item => {. And then you replace every illusts[key] with item. That'll remove 5 explicit key lookups from the loop. After you've done that you'll probably notice that you now have bannedUsers.some(i => item.userId == i) in there. Which you can simplify to bannedUsers.includes(item.userId). There are more incremental improvements, but these were the main ones I think. Oh yeah, this one: .aiType==2. You may want to create a meaningfully named constant for that 2 value. That way anyone reading it at least will have some idea where that magic 2 value comes from.

Bit longer than intended, but oh well.

1

u/MonoS94 Jul 08 '26

I think you are mistaking what this script does, both the list of tags and the aiType indicator are not available on the HTML side, all the logic is being done on the raw payload data, that's why i have to replace the thumbnail with another one (in theory i could put nothing, but as I said I prefer to know which images are slop), my script does not change any HTML after receiving the data. Looking at the payload i've found a flag called isBookmarkable, that when set to false make the user unable to click on the heart and also make it dimmer, i'll implement that.