Topic: My Greasemonkey Scripts - Large Thumbnails, Automatic Ordering, Options At The Top, & Saved Tags Search / Autotag

Posted under General

Hello everyone,

I have a few greasemonkey / tampermonkey scripts that I made for myself. Originally I was planning on making these better and then sharing, but it's been quite a while since I've worked on them and I've sort of lost interest.
I'm posting these here in case anyone else might want them, since I don't plan to develop them any further.

One note: the "include" urls are intentionally vague so it's not obvious what these are for. That means they could possibly run on other sites, although I haven't experienced this. You could update the @include to specifically target e621.net

1. Large Thumbnails:

Description:
This one automatically rescales all thumbnails to the "large" size. Could be easily modified to pick a whatever scale you want. Could be updated with an options UI.

Code:

// ==UserScript==
// @name         ReScaler
// @namespace    ReScaler
// @version      1.1
// @description  Scales up the thumbnails
// @author       ReScaler
// @include      /^https\://?.+1\.net/posts/
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js#sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=
// @run-at       document-start
// ==/UserScript==

this.$ = this.jQuery = jQuery.noConflict(true);

// Settings
const cropImages = true,
      thumbWidth = 280,
      thumbHeight = 320;

// Main Script
(function() {
    'use strict';

    // Reset the attached stylesheet
    $("<style>")
        .appendTo("head")
        .html(`
            div#posts-container {
                display: grid;
                grid-template-columns: repeat(auto-fill, ${thumbWidth}px);
                justify-content: space-between;
            }
            article.post-preview {
                width: ${thumbWidth}px;
                ${cropImages ? ("height: " + thumbHeight + "px") : ""};
            }
            article.post-preview img {
                max-width: 100%;
                max-height: 100%;
                width: ${thumbWidth}px;
                ${cropImages ? ("height: " + (thumbHeight - 16) + "px") : ""};
                object-fit: ${cropImages ? "cover" : "contain"};
            }
        `);

    window.addEventListener('DOMContentLoaded', (event) => {
        // Rewrite the thumbnail URLs
        $("article.post-preview").each((index, entry) => {
            let $thumb = $(entry);
            $thumb.find("source").remove();

            let $img = $thumb.find("img").first();
            if($thumb.attr("data-large-file-url")) { $img.attr("src", $thumb.attr("data-large-file-url")); }
        });
    });

})();

2. Automatic Ordering

Description:
This script automatically replaces any ordering with whatever ordering is set in the script. For me, it's "score." Could be easily modified to pick your favorite ordering. Could be updated with an options UI to set the default ordering.

Code:

// ==UserScript==
// @name         OrderBy
// @namespace    OrderBy
// @version      0.1
// @description  Order by score
// @author       OrderBy
// @include      /^https\://?.+1\.net/posts\?tags=/
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    // Order by score
    if ( !window.location.href.includes('+order') ){
        window.location.replace(`${window.location.href}+order%3Ascore`);
    }
})();

3. Options At The Top

Description:
This script simply moves the "Options" section in the side panel of a post to the top, above "Tags." This makes it easier to favorite something, add it to a pool, download it, etc.

Code:

// ==UserScript==
// @name         TopOptions
// @namespace    TopOptions
// @version      0.1
// @description  Move options to top of sidebar
// @author       TopOptions
// @include      /^https\://?.+1\.net/posts/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    // Re-order sidepanel
    $('#post-options').insertBefore('#tag-list');
    $('#post-options').css('padding-bottom', 10);
})();

4. Saved Tags

Description:
This script adds an "Autotag" input to the side panel in the posts section. Any comma-separated tags which are added here will be automatically appended to the search. For me, I have "animated," but this can be easily changed at any time via the side panel menu without changing the code. This will be saved as well, so you don't need to update the code at all if you just want this functionality. The interface is not polished, so to update the tags simply type them in the "Autotag" input and they will be automatically saved as they change. To apply them, refresh the page.

If you have any tags you want to always be appended, you can set them as strings in "defaultQueryTags," e.g.,

defaultQueryTags = ["animated"];

If you want to set different default tabs for the "posts" page vs the "search" page, you can set "redirectPostsPage = true" and set the default tags in defaultPostsTags.

// ==UserScript==
// @name         Autotag
// @namespace    Autotag
// @version      0.5
// @description  Automatically add tags to search
// @author       Autotag
// @include      /^https\://?.+1\.net/posts/
// @grant        none
// @run-at       document-start
// ==/UserScript==

/* Options *///////////////////////////
//~ Show auto-tag input form in sidebar
const showOptions = true;
//~ Default tags for query page (i.e., site.net/posts?tags=something)
const defaultQueryTags = [];
//~ Redirect "Posts" page to query page with search tags set to defaultPostsTags
const redirectPostsPage = false;
//~ Default tags for posts page (i.e, site.net/posts). Does nothing if redirectPostsPage !== true
const defaultPostsTags = [];
//////////////////////////////////////

// LocalStorage identifier - just to keep keys unique
const storageTag = "tm-autotag-323DDS"

// "query" or "posts"
// Set upon script launch. Do not modify.
let page = "query";

function _tmLogContext(level){
    return (msg) => {
        msg = `tm-Autotag: ${msg}`;
        if (typeof msg !== 'string') return;
        switch(level){
            case 'info':
                return console.info(msg);
            case 'warn':
                return console.warn(msg);
            case 'error':
                return console.error(msg);
            default:
                return console.log(msg);
        }
    };
}

// Hijack the console
const logger = {
    'log': _tmLogContext('log'),
    'info': _tmLogContext('info'),
    'warn': _tmLogContext('info'),
    'error': _tmLogContext('info')
};

// Trim whitespace, replace remaining whitespace with underscore, replace ':' with HTML colon
function formatTags(tags){
    tags.forEach((el, idx, arr) => {
        arr[idx] = el.toLowerCase().trim().replace(/\s*:\s*/g, '%3A').replace(/%3a/g, '%3A').replace(/\s+/g, '_');
    });
}

// Get tags from LocalStorage if available, else return defaults
// Sets tags in LocalStorage to default values if they are missing or invalid
function getTags(){
    if (!showOptions) return (page === "posts") ? defaultPostsTags : defaultQueryTags;
    let storageName = (page === "posts") ? "postsTags" : "queryTags";
    let _tags = [];
    try {
        _tags = JSON.parse(localStorage[`${storageTag}-${storageName}`]);
    } catch(err){
        logger.error(`Failed parsing setting: ${localStorage[`${storageTag}-${storageName}`]}`);
        logger.error(`Error: ${err}`);
    }
    if (!Array.isArray(_tags)){
        _tags = (page === "posts") ? defaultPostsTags : defaultQueryTags;
        localStorage[`${storageTag}-${storageName}`] = JSON.stringify(_tags);
    } else {
        formatTags(_tags);
    }
    return _tags;
}

// Sets tags in the page URL. Does NOT update tags in LocalStorage
function setTags(tags){
    if (!Array.isArray(tags)) return;
    let paramString = "";
    let location = window.location.href;
    for (let tag of tags){
        if ( !location.includes(`+${tag.split('%3A')[0]}`) && !location.includes(`tags=${tag.split('%3A')[0]}`) && !paramString.includes(`+${tag.split('%3A')[0]}`)){
            paramString += `+${tag}`;
        }
    }
    if (paramString.length > 0){
        if (page === "posts") paramString = `?tags=${paramString.slice(1)}`;
        window.location.replace(`${window.location.href}${paramString}`);
    }
}

// Inject the auto-tags input
function buildOptions(){
    let _localTags = getTags();
    let autotagshowOptions = $(`<section id="autotag-showOptions"><div>Auto-Tag</div><div><p style="font-size:10px">Comma-separated list of tags:</p><input type="text" name="autotag-tags" id="autotag-tags" value="${_localTags.join(", ").replace(/%3a/gi, ":")}" data-shortcut="a" title="Shortcut is a", style="width:100%"></div></section>`);
    autotagshowOptions.css({'padding-top': 8,
                            'padding-right': 4,
                            'padding-bottom': 8});
    autotagshowOptions.insertAfter('#search-box');
    setTags(_localTags);
    $('#autotag-tags').change(() => {
        let newTags = $('#autotag-tags').val().split(",");
        formatTags(newTags);
        let storageName = (page === "posts") ? "postsTags" : "queryTags";
        localStorage[`${storageTag}-${storageName}`] = JSON.stringify(newTags);
    });
}

(function() {
    'use strict';

    // Do nothing if we're on the posts page and redirectPostsPage is not enabled
    if (/\/posts$/mi.test(window.location.href) && redirectPostsPage !== true) return;

    // Don't run if there's an actual query, this is currently broken
    if(/\/posts\/\d+(\?|\&)q=/i.test(window.location.href)) return;

    // Set page location
    if (window.location.href.includes("?tags=")){
        page = "query";
    } else {
        page = "posts"
    }

    // Ensure default tags are valid
    if (!Array.isArray(defaultQueryTags)) defaultQueryTags = [];
    formatTags(defaultQueryTags);
    if (!Array.isArray(defaultPostsTags)) defaultPostsTags = [];
    formatTags(defaultPostsTags);

    // Create LocalStorage keys if they are missing
    if (localStorage[`${storageTag}-postsTags`] === null || localStorage[`${storageTag}-postsTags`] === undefined){
        logger.log('Creating posts page settings data');
        localStorage[`${storageTag}-postsTags`] = JSON.stringify(defaultPostsTags);
    }
    if (localStorage[`${storageTag}-queryTags`] === null || localStorage[`${storageTag}-queryTags`] === undefined){
        logger.log('Creating query page settings data');
        localStorage[`${storageTag}-queryTags`] = JSON.stringify(defaultQueryTags);
    }

    // Actually set the proper tags
    setTags(getTags());

    // If auto-tag input is enabled, inject it into the DOM once it's finished loading the page
    if (showOptions === true){
        window.addEventListener('DOMContentLoaded', (event) => {
            buildOptions();
        });
    }
})();

Let me know if this helps anyone. I may be willing to make updates / fixes but my time for this will be limited.

Cheers,
teerac

Updated

Thanks for the scripts!
I've used the rescaler one for a while now, but it seems like it recently broke. Any ideas for a fix?

203f98h2908h9f said:
Thanks for the scripts!
I've used the rescaler one for a while now, but it seems like it recently broke. Any ideas for a fix?

0 clue
It's broken for me too.

therealchud said:
0 clue
It's broken for me too.

I tried the rescaler script just now and it seems to work for me, on desktop Firefox 115.13.0, with Tampermonkey 5.1.1.

In the Tampermonkey editor, there are some warnings that one of the statements (the @include /^https\://?.+1\.net/posts/, near the top) might break in Chrome, once Chrome moves to "Manifest v3". This is Google's latest attempt to kill uBlock Origin and other ad blockers. I don't know if that's what is breaking the script, but that's my guess at what's doing it.

If it's broken in Chrome, and you install Firefox, Tampermonkey, and the rescaler script, and then it works, then that points the finger at Chrome.

I'm told that RE621 has similar functionality for displaying larger thumbnails, but I'm not too familiar with it.

kora_viridian said:
I tried the rescaler script just now and it seems to work for me, on desktop Firefox 115.13.0, with Tampermonkey 5.1.1.

In the Tampermonkey editor, there are some warnings that one of the statements (the @include /^https\://?.+1\.net/posts/, near the top) might break in Chrome, once Chrome moves to "Manifest v3". This is Google's latest attempt to kill uBlock Origin and other ad blockers. I don't know if that's what is breaking the script, but that's my guess at what's doing it.

If it's broken in Chrome, and you install Firefox, Tampermonkey, and the rescaler script, and then it works, then that points the finger at Chrome.

I'm told that RE621 has similar functionality for displaying larger thumbnails, but I'm not too familiar with it.

115.13.0 is an ESR release, so this points to the issues being some update to the standard firefox, damn

203f98h2908h9f said:
115.13.0 is an ESR release, so this points to the issues being some update to the standard firefox, damn

Special, for you, today: I downloaded desktop Firefox 129.0 and tried it there. It still works for me.

Details:
Brand-new installation of Firefox 129.0, no previous data imported. Installed Tampermonkey 5.1.1 and the rescaler script (1. Large Thumbnails in the OP). Went to https://e621.net/posts . The script worked and I got large thumbnails.

Added uBlock Origin 1.59.0, with all default settings, and let it update its filter lists. Went to a different page of the recent posts. The script worked and I got large thumbnails.

Turned Firefox's "Enhanced Tracking Protection" from "standard" (the default) up to "script", and let it reload all my tabs. Went to a different page of the recent posts. The script worked and I got large thumbnails.

One possible problem:
The rescaler script tries to load a Javascript library (jQuery) from an external site. If that fails, maybe due to some kind of privacy or security software on your machine, then the rescaler script might not work.

Test:
In a new tab, go to https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js#sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo= . You should see a bunch of code that starts with /*! jQuery v3.4.1 | (c) JS Foundation and other contributors | jquery.org/license */ on the top line. If you don't see that line, or if you get some kind of "blocked" or "not found" page, then figure out what software on your machine is doing the blocking. It could be another browser plugin, or it could be anti-virus software, or possibly other things.

kora_viridian said:
Special, for you, today: I downloaded desktop Firefox 129.0 and tried it there. It still works for me.

Details:
Brand-new installation of Firefox 129.0, no previous data imported. Installed Tampermonkey 5.1.1 and the rescaler script (1. Large Thumbnails in the OP). Went to https://e621.net/posts . The script worked and I got large thumbnails.

Added uBlock Origin 1.59.0, with all default settings, and let it update its filter lists. Went to a different page of the recent posts. The script worked and I got large thumbnails.

Turned Firefox's "Enhanced Tracking Protection" from "standard" (the default) up to "script", and let it reload all my tabs. Went to a different page of the recent posts. The script worked and I got large thumbnails.

One possible problem:
The rescaler script tries to load a Javascript library (jQuery) from an external site. If that fails, maybe due to some kind of privacy or security software on your machine, then the rescaler script might not work.

Test:
In a new tab, go to https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js#sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo= . You should see a bunch of code that starts with /*! jQuery v3.4.1 | (c) JS Foundation and other contributors | jquery.org/license */ on the top line. If you don't see that line, or if you get some kind of "blocked" or "not found" page, then figure out what software on your machine is doing the blocking. It could be another browser plugin, or it could be anti-virus software, or possibly other things.

I do applaud the effort, but just to make sure, since you only mention large thumbnails which is not the issue, you're getting high quality version of the thumbnails? Because just getting large thumbnails is not the issue; the scaling part is. We're not getting those high quality versions, instead we're just getting the original thumbnails stretched out, making them pixelated.
Just tested this on a completely fresh linux machine in firefox (both ESR and Standard) and just like my main machine, I'm still getting large thumbnails, but the subsequent rescaling fails. Starting to think I have to look at tampermonkey versions or something...

Access to the jQuery site is not the problem, but thank you for mentioning to check that as well

203f98h2908h9f said:
Because just getting large thumbnails is not the issue; the scaling part is.

The problem descriptions I was working with were "it seems like it recently broke" and "It's broken for me too". There was no description of what "broke" actually meant. There was also no browser name or version, no userscript manager name or version, no information on desktop or mobile. So I was flying mostly blind. I was interpreting "broke" to mean that the thumbnails were displayed in exactly the same way as the vanilla site, or possibly that the thumbnails didn't display at all.

We're not getting those high quality versions, instead we're just getting the original thumbnails stretched out, making them pixelated.

I was getting the stretched, pixelated versions too. Without any other information, I thought that's how the original userscript was supposed to work.

Now that we have lifted the foreskin of ignorance and applied the wire brush of enlightenment, I think I fixed it. :D

Changing the last non-parentheses-and-braces line of OP's script to

if($thumb.attr("data-large-url")) { $img.attr("src", $thumb.attr("data-large-url")); }

makes it work for me, on desktop Firefox 115.13.0, with Tampermonkey 5.1.1. The thumbnails display in a larger size and are a high-quality image - not stretched or pixelated.

This code has no warranty. If it breaks you get to keep all the pieces.

The problem is, I think, that e621's markup changed. The individual thumbnail entries don't have a data-large-file-url attribute anymore - now it's data-large-url. The data-large-url has a URL of the form https://static1.e621.net/data/sample/0d/db/0ddbeefdeadf00d.jpg . On one random image that's on the front page now, that URL goes to an 850x1097 JPEG. (The vanilla thumbnail URL for that image has /preview/ in it instead of /sample/, and goes to a 116x150 JPEG.)

To find exactly when it changed, I tried searching for those attributes in the e621 code , but I couldn't find it. (Note that code search is now privacywalled on Github - you have to log in.) Looking at the most recent post in the changelog thread here, I think it probably changed when this commit went into production. That probably happened on either 2024-07-29 (the headline in that forum post) or 2024-08-05 (the date of that forum post).

edit: fixed URL

Updated

kora_viridian said:
The problem descriptions I was working with were "it seems like it recently broke" and "It's broken for me too". There was no description of what "broke" actually meant. There was also no browser name or version, no userscript manager name or version, no information on desktop or mobile. So I was flying mostly blind. I was interpreting "broke" to mean that the thumbnails were displayed in exactly the same way as the vanilla site, or possibly that the thumbnails didn't display at all.

I was getting the stretched, pixelated versions too. Without any other information, I thought that's how the original userscript was supposed to work.

Now that we have lifted the foreskin of ignorance and applied the wire brush of enlightenment, I think I fixed it. :D

Changing the last non-parentheses-and-braces line of OP's script to

if($thumb.attr("data-large-url")) { $img.attr("src", $thumb.attr("data-large-url")); }

makes it work for me, on desktop Firefox 115.13.0, with Tampermonkey 5.1.1. The thumbnails display in a larger size and are a high-quality image - not stretched or pixelated.

This code has no warranty. If it breaks you get to keep all the pieces.

The problem is, I think, that e621's markup changed. The individual thumbnail entries don't have a data-large-file-url attribute anymore - now it's data-large-url. The data-large-url has a URL of the form https://static1.e621.net/data/sample/0d/db/0ddbeefdeadf00d.jpg . On one random image that's on the front page now, that URL goes to an 850x1097 JPEG. (The vanilla thumbnail URL for that image has /preview/ in it instead of /sample/, and goes to a 116x150 JPEG.)

To find exactly when it changed, I tried searching for those attributes in the e621 code , but I couldn't find it. (Note that code search is now privacywalled on Github - you have to log in.) Looking at the most recent post in the changelog thread here, I think it probably changed when this commit went into production. That probably happened on either 2024-07-29 (the headline in that forum post) or 2024-08-05 (the date of that forum post).

edit: fixed URL

That's on me for sure, I thought the original script description included that bit, sorry for being rude like that!!!

And yup, can confirm modifying that last line makes everything work flawless again, really appreciate it!
Also nice that you found the commit in question, just goes to show that front-end really isn't my specialty

203f98h2908h9f said:
Seems like this one is broken again :<

I was using a userscript from this post for a while https://e621.net/forum_topics/25970. It recently broke and I just spent today modifying it and trying to fix it. I imagine its the same change that broke this script is what broke the rescaling. I'm not gonna mess around with the rescaling userscript to fix it but maybe you'll like this better. You might also be able to get a hint to fix the rescaler script as well.

To use it:

  • Mouse over image you want to view
  • Hit left shift to open the viewer which will load the full size image centered on your screen (it will take up at most 97% of the screen, you can change that % by modifying TEsetting_width/height)
  • Hit left shift again to close the preview. If you opened a webm and started playing it you need to click somewhere not on the controls of the webm player for left shift to work again

I added an element to get webm videos to also be loadable and playable. Makes looking through search results a breeze. Right now it explicitly matches for e621.net, e6ai.net, and e926.net. It should be easy to add any others which use the same backend.
You can also change which key you need to press to load the image and close the image by changing TEsetting_key to the code value you get from this website https://www.toptal.com/developers/keycode when you press the key.

It also works with user's avatar images :P

Here's the script:

// ==UserScript==
// @name         e6 Thumbnail enlarger
// @namespace    n/a
// @version      0.3
// @description  hold shift :D
// @author       reBane edit by Potsu
// @match        https://e621.net/*
// @match        https://e6ai.net/*
// @match        https://e926.net/*
// @grant        none
// ==/UserScript==

var logging = true; // Set this to 'false' to turn off logging


var TEenabled = false;
var TEinitialized = false;
var TEsetting_width = "97vw";
var TEsetting_height = "97vh";
var TEsetting_key = 'ShiftLeft';

var pbox;
var pboximg;
var pboxvideo;

var lastEvent = {pageX:0, pageY:0, target:{}};

window.addEventListener('keydown', (event) => {
    if (event.code == TEsetting_key) TEtoggle()
});

window.onload = function() {
    // Your function to run when the page has loaded
    console.log("Page has loaded!");
    TEinit(); // Call your custom function
};


function log(message) {
    if (logging) {
        console.log(message);
    }
}

function TEinit() {
    if (TEinitialized == true) { return; }
    TEinitialized = true;

    // Create display elements
    pbox = document.createElement("div");
    pbox.style.position = "fixed";
    pbox.style.top = "50%";
    pbox.style.left = "50%";
    pbox.style.transform = "translate(-50%, -50%)";
    pbox.style.width = TEsetting_width;
    pbox.style.height = TEsetting_height;
    pbox.style.placeItems = "center";
    pbox.style.zIndex = "99";
    pbox.style.display = "none";

    pboximg = document.createElement("img");
    pboximg.style.width = "100%";
    pboximg.style.height = "100%";
    pboximg.style.objectFit = "contain";
    pboximg.setAttribute('alt', 'Loading...');

    // Create video element for webm files
    pboxvideo = document.createElement("video");
    pboxvideo.style.objectFit = "contain";
    pboxvideo.setAttribute('alt', 'Loading...');
    pboxvideo.setAttribute('controls', 'true'); // Optional: Add controls for video

    // Initially use img element
    pbox.appendChild(pboximg);
    pbox.appendChild(pboxvideo);
    document.body.appendChild(pbox);

            // Attach event listeners to thumbnails
    document.querySelectorAll("a").forEach(a=> {
        a.addEventListener('mouseenter', function(e){ log(e); lastEvent = e; });
        a.addEventListener('mouseleave', ()=>{ log("exited"); lastEvent=null; });
    });

    log("Thumbnail enlarger initialized");
}

function TEtoggle(event) {
    if (!TEinitialized) {TEinit();}
    if (!TEenabled && lastEvent != null) {
        TEenabled = true;
        TEimg(lastEvent);
        log("Enabled Previews");
    }
    else if (TEenabled) {
        TEenabled = false;
        pboxvideo.pause();
        pbox.style.display = "none";
        log("Disabled Previews");
    }
}

function TEimg(event) {
    log(event);
    var dataset = null;
    if (!TEenabled){ log("Not enabled"); return 0;}
    if (event.srcElement.parentElement.dataset.fileUrl) { dataset = event.srcElement.parentElement.dataset; }
    if (dataset === null) { log("No content, returning"); TEenabled = false; return 0;}

    if (dataset.fileExt === 'webm')
    {
        // Load video
        if (!pboxvideo.src || pboxvideo.src != dataset.fileUrl)
        {
            pboxvideo.src = dataset.fileUrl;

            var factor = window.innerWidth / dataset.width;
            if (factor * dataset.height > window.innerHeight)
            {
                pboxvideo.style.height = "100%";
                pboxvideo.style.width = "";
            }
            else
            {
                pboxvideo.style.width = "100%";
                pboxvideo.style.height = "";
            }
        }
        pboxvideo.style.display = "block";
        pboximg.style.display = "none"; // Hide image
    }
    else
    {
        if (!pboximg.src || pboximg.src != dataset.fileUrl)
        {
            pboximg.src = dataset.fileUrl; // loading image
        }
        pboximg.style.display = "block";
        pboxvideo.style.display = "none"; // Hide video
    }

    pbox.style.display = "block";

    log("Loaded: " + dataset.fileUrl);
    log("Image dimensions: " + dataset.width + "x" + dataset.height);
}

e: the webm controls were wonky in the first version so I updated that. Second edit because the sizing got broken as well. I don't really know what I'm doing (thanks chatGPT) so if you have any improvements feel free to post them.

Updated

I do appreciate you posting that script, even thought it isn't quite what I'm looking for since I want all images to be rescaled up. I'm gonna try and look through their github to see what might have changed

Edit: partially found the issue, anything using

post-preview

has been changed to

thumbnail

. Only problem now is that the crop is mobile screen like, everything else works

Updated

Bah, took some deep digging and chatGPT spouting endless lines of useless nonsense, but finally got it working again. Keep in mind that this one is hardcoded to 8 images per row because I'm a hack who has no idea what they're doing and it fits on their screen. Change this setting if that's too many per row, or too few

// ==UserScript==
// @name         E621 ReScaler
// @namespace    bitwolfy.com
// @version      1.1
// @description  Scales up the thumbnails on e621.net
// @author       bitWolfy
// @match        https://e621.net/posts*
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js#sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=
// @grant        none
// ==/UserScript==

this.$ = this.jQuery = jQuery.noConflict(true);
// Settings
const cropImages = true,
      thumbWidth = 280,
      thumbHeight = 320,
      imagesPerRow = 8;




// Main Script
(function() {
    'use strict';

    // Function to update the grid dynamically
    function updateGridColumns() {
        const postsContainer = document.querySelector("section.posts-container");

        if (postsContainer) {
            // Set grid-template-columns for fixed columns
            postsContainer.style.gridTemplateColumns = `repeat(${imagesPerRow}, ${thumbWidth}px)`;
        }
    }

    // Reset the attached stylesheet

    $("<style>")
        .appendTo("head")
        .html(`

            div#posts-container {
                display: grid;
                gap: 1rem;
                justify-content: space-between;

            }
            article.thumbnail {
                width: ${thumbWidth}px;
                max-width: ${thumbWidth}px;

            }
            article.thumbnail img {
                max-width: 100%;
                max-height: 100%;
                ${cropImages ? ("height: " + (thumbHeight - 16) + "px") : ""};
                object-fit: ${cropImages ? "cover" : "contain"};
            }
        `);

    // Rewrite the thumbnail URLs
    $("article.thumbnail").each((index, entry) => {
        let $thumb = $(entry);
        $thumb.find("source").remove();

        let $img = $thumb.find("img").first();
        if($thumb.attr("data-large-url")) { $img.attr("src", $thumb.attr("data-large-url")); }
    });

    $(document).ready(() => {
        updateGridColumns();
    });
})();
  • 1