Update reddit-image-inline.user.js

Post link redirect to comments
This commit is contained in:
2024-12-12 07:40:31 +01:00
committed by GitHub
parent 276ea125ff
commit 797d66ed37

View File

@@ -1,8 +1,8 @@
// ==UserScript==
// @name Inline Reddit images
// @name Inline Reddit images and Comment Redirect
// @namespace https://www.reddit.com
// @version 2024-05-21
// @description Embed images posted as comments
// @version 2024-12-12
// @description Embed images posted as comments and redirect post links to comments
// @author luxick
// @updateURL https://raw.githubusercontent.com/luxick/scripts/master/reddit-image-inline.user.js
// @downloadURL https://raw.githubusercontent.com/luxick/scripts/master/reddit-image-inline.user.js
@@ -15,6 +15,7 @@
(function() {
'use strict';
// Handle image inlining
let xpath = "//a[text()='<image>']";
var element;
var result = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
@@ -31,5 +32,22 @@
image.src = elem.href;
image.style = "max-width: 300px";
elem.parentElement.appendChild(image);
elem.remove();}
elem.remove();
}
// Only proceed with link rewriting if we're not already in a comments section
if (!window.location.pathname.includes('/comments/')) {
// Handle post link redirection
const postLinks = document.querySelectorAll('a.title');
postLinks.forEach(link => {
// Find the comments link for this post
const thing = link.closest('.thing');
if (thing) {
const commentsLink = thing.querySelector('a.comments');
if (commentsLink) {
link.href = commentsLink.href;
}
}
});
}
})();