Skip to content

Instantly share code, notes, and snippets.

@dichen-cd
Created September 8, 2025 06:56
Show Gist options
  • Select an option

  • Save dichen-cd/deea516d04cb14bafbb8b343f329cca5 to your computer and use it in GitHub Desktop.

Select an option

Save dichen-cd/deea516d04cb14bafbb8b343f329cca5 to your computer and use it in GitHub Desktop.
Change Zhihu images to small size for faster loading 缩小知乎图片的尺寸
// ==UserScript==
// @name Zhihu Image Smaller
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Change Zhihu images to small size for faster loading.
// @author Gemini
// @match https://*.zhihu.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
const observer = new MutationObserver(mutations => {
for (const mutation of mutations) {
for (const node of mutation.addedNodes) {
if (node.nodeType === Node.ELEMENT_NODE) {
// Check if the added node is an image itself
if (node.matches('img.origin_image[data-size="normal"]')) {
node.setAttribute('data-size', 'small');
}
// Find images within the added node
const images = node.querySelectorAll('img.origin_image[data-size="normal"]');
images.forEach(img => {
img.setAttribute('data-size', 'small');
});
}
}
}
});
observer.observe(document.documentElement, {
childList: true,
subtree: true
});
// For images that might already be on the page when the script starts
// (though less likely with document-start)
document.querySelectorAll('img.origin_image[data-size="normal"]').forEach(img => {
img.setAttribute('data-size', 'small');
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment