您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Auto expands all image posts except NSFW ones.
当前为
// ==UserScript== // @name Lemmy Image Expand // @namespace Violentmonkey Scripts // @match *://*/* // @grant none // @version 1.0 // @author SlyFabi // @description Auto expands all image posts except 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; const isNsfw = postListing.querySelector('.thumbnail.img-blur') != null; if(!isExpanded && !isNsfw) { 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); } })();