With 0.18 update the nsfw patch is missing yet, so in the meantime I found this userscript and modified it to work with NSFW.

P.S. I know this is not the best community for this, but nothing else fits.

Use your userscript manager of choice to install it. Violentmonkey, Tampermonkey

// ==UserScript==
// @name        Lemmy Image Expand (modified)
// @namespace   Violentmonkey Scripts
// @match       *://*/*
// @grant       none
// @version     1.0.1
// @author      SlyFabi
// @description Auto expands all image posts including NSFW ones.
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';
    // Thanks to CodingAndCoffee for isLemmy
    let isLemmy;
    try {
        isLemmy = document.head.querySelector("[name~=Description][content]").content === "Lemmy";
    } catch (_er) {
        isLemmy = false;
    }

    if(isLemmy) {
      // https://stackoverflow.com/questions/18177174/how-to-limit-handling-of-event-to-once-per-x-seconds-with-jquery-javascript
      function throttle(func, interval) {
        var lastCall = 0;
        var nextCall = -1;
        return function() {
            var now = Date.now();
            clearTimeout(nextCall);
            if (lastCall + interval < now) {
                lastCall = now;
                func.apply(this, arguments);
            } else {
              nextCall = setTimeout(function() {
                lastCall = Date.now();
                func.apply(this, arguments);
              }, interval);
            }
        };
      }

      const targetNode = document.getElementById('app');
      const config = { attributes: false, childList: true, subtree: true };
      let observer = null;
      const callback = throttle(function(mutationsList) {
        if(observer != null) {
          observer.disconnect();
        }

        setTimeout(function() {
          let postList = [];
          document.querySelectorAll('.post-listing a.text-body svg.icon use').forEach(function(postIcon) {
            const imgPreview = postIcon.parentElement.parentElement;
            if(postIcon.getAttribute('xlink:href') !== "/static/assets/symbols.svg#icon-image") {
              return;
            }
            postList.push(imgPreview);
          });

          let uniqueList = postList.reduce((unique, o) => {
            if(!unique.some(obj => obj.getAttribute('href') === o.getAttribute('href'))) {
              unique.push(o);
            }
            return unique;
          },[]);

          uniqueList.forEach(function(imgPreview) {
            const postListing = imgPreview.closest(".post-listing");
            const isExpanded = postListing.querySelector('.img-expanded') != null;
              if(!isExpanded) {
              imgPreview.click();
            }
            //console.log('UElement: ' + imgPreview + ' Exp: ' + isExpanded);
          });
          /*postList.forEach(function(imgPreview) {
            imgPreview.style.pointerEvents = 'none';
            //console.log('Element: ' + imgPreview);
          });*/

          setTimeout(function() {
            observer = new MutationObserver(callback);
            observer.observe(targetNode, config);
          }, 500);
        }, 500);
      }, 1000);

      setTimeout(function() {
        callback([]);
      }, 500);
    }
})();
You are viewing a single thread.
View all comments
8 points

It seems the update broke quite a few things especially instance based edits, I have faith they’ll be fixed sooner rather than later though. Such is the growing pains of newly mass adopted software, it seems. Fix ten things, break twenty things.

permalink
report
reply

Ask Lemmy NSFW

!asklemmynsfw@lemmynsfw.com

Create post

Think /r/AskLemmy but way more NSFW.

Treat this community like a cross between /c/AskLemmy, /c/Sex, and /c/Fetishes.

RULES:

  • All posts must be in the form of a question and be largely NSFW.

  • Only text posts are allowed. Links can be posted if they are very relevant.

POST GUIDELINES:

  • Try to avoid questions that can simply be googled or have yes/no answers.

  • Search before you post. Your question may have been asked before.

  • If you ask medical/physical questions don’t always trust the comments here.

COMMENT GUIDELINES:

  • Avoid low-effort comments. Lone images, memes, jokes etc.

  • Treat all questions as if they’re real, no matter how ridiculous.

  • Follow reddiquette with all reponses to avoid downvotes & removal.

Community stats

  • 599

    Monthly active users

  • 465

    Posts

  • 5K

    Comments