Unable to load image
Reported by:

tampermonkey script to make make old.reddit more tolerable

  • For large screens, centres text so it's not way over on the left (some subs have custom html styles, hence the two sections)
  • Expands images automatically
  • Hides the image hiphopcirclejerk stuck over their sub (thx j cole drama)
// ==UserScript==
// @name         old_reddit_improver
// @namespace    http://tampermonkey.net/
// @version      2024-01-26
// @description  Make old.reddit.com more usable
// @author       You
// @match        https://old.reddit.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=reddit.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    console.log('---- tampermonkey initiated ----');

    // Remove hhcj pic.
    let earl = document.querySelector('a[href="#EARL"]');
    if (earl) {
        earl.style.display = 'none';
    }

    // Centre page body.
    let body1 = document.querySelector('div[id="siteTable"]');
    if (body1) {
        body1.style = 'width: 70%; margin: auto;';
        console.log('body1:', body1);
    }
    let body2 = document.querySelector('div[class="commentarea"]');
    if (body2) {
        body2.style = 'width: 70%; margin: auto;';
        console.log('body2:', body2);
    }
    console.log('ran centre aligner');

    // Expand images.
    let xpath = "//a[text()='<image>']";
    let iter = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
    let array = [];
    let text_elem = iter.iterateNext();
    while (text_elem) {
        array.push(text_elem);
        text_elem = iter.iterateNext();
    }
    array.forEach(i => {
        let img_tag = new Image();
        img_tag.src = i.href;
        img_tag.style.maxWidth = '500px';
        i.parentElement.appendChild(img_tag);
        i.parentElement.removeChild(i);
    })
    console.log('---- tampermonkey complete ----');
})();
15
Jump in the discussion.

No email address required.

Can you make a tampermonkey script that just delivers a ransomware payload whenever you go to reddit?

Jump in the discussion.

No email address required.

:ipgra#bber:


Transform your Marseys! :marseywave:
/e/marseybooba.webp
www.pastebin.com/Jj9URfVi

Jump in the discussion.

No email address required.

The bread crumbs are piling up. After some tracking I found your IP: 80.92.56.88

Out of luck, son (snap)

Jump in the discussion.

No email address required.

That's fricking horrible lmao

Jump in the discussion.

No email address required.

What does it do? I'm guessing it makes the <image> links actually show the image they link to, meaning that you don't need to click on the images, but I am not a programmer.

Jump in the discussion.

No email address required.

>centre page body

What do you think it do?

Jump in the discussion.

No email address required.

Center align isn't that bad, most comment sections have a lot of empty space on the right side of the screen (assuming that side isn't filled with ads). I was more worried about the new image and removeChild parts of it

Jump in the discussion.

No email address required.

Iterator that finds all the image links:

let xpath = "//a[text()='<image>']";`
let iter = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);

Move iterator items into an array, since iterators become invalid once the document changes:

let array = [];
let text_elem = iter.iterateNext();
while (text_elem) {
    array.push(text_elem);
    text_elem = iter.iterateNext();
}

For each link, create a literal image with its attributes. Add it to the document and remove the now-unnecessary link:

array.forEach(i => {
    let img_tag = new Image();
    img_tag.src = i.href;
    img_tag.style.maxWidth = '500px';
    i.parentElement.appendChild(img_tag);
    i.parentElement.removeChild(i);
})

Nothing malicious.

Jump in the discussion.

No email address required.

There's a whole section dedicated to image expansion, are you blind?

Jump in the discussion.

No email address required.

https://media.giphy.com/media/l4FGuhL4U2WyjdkaY/giphy.webp

Jump in the discussion.

No email address required.

Are you a literal NPC? First you had trouble counting to two, now you're just copy and pasting your replies. Do you need some time to update before you can type anything new?

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.