简体   繁体   English

如何使用Tampermonkey或Fashion更改所有名称为x.png和x.png的图像?

[英]How do I change all images with the name x.png with x.png with Tampermonkey or Stylish?

I'm currently making a dark theme for my local router, the images it uses are terrible, I want to replace them, but they are added with JavaScript, after lots of research with Tampermonkey/Greasemonkey and also Stylish, I couldn't find any way to do it. 我目前正在为本地路由器制作一个黑暗的主题,它使用的图像很糟糕,我想替换它们,但是在经过Tampermonkey / Greasemonkey和时尚的大量研究之后,它们已经添加了JavaScript,我找不到任何方式做到这一点。

Only idea I had was replace images with the file name say wan_up.png with another image. 我唯一的想法是用另一个图像替换文件名为wan_up.png的图像。

Use CSS in Stylish or similar extension. 在时尚或类似扩展名中使用CSS。

#your-selector-here {
    height: 0 !important;
    width: 0 !important;
    /* these numbers match the new image's dimensions */
    padding-left: 32px !important;
    padding-top: 32px !important;
    background: url(http://example.com/your/image/here) no-repeat !important;
    background-size: 32px 32px; /* modern CSS property to scale the new image */
}

Use MutationObserver API to alter the image element before it's shown. 使用MutationObserver API在显示图像元素之前先对其进行更改。

There are many wrappers for MutationObserver, here's an example based on setMutationHandler : MutationObserver的包装器很多,这是一个基于setMutationHandler的示例:

// ==UserScript==//
// @name           Replace image
// @match          http://192.168.0.1/*
// @run-at         document-start
// @require        https://greasyfork.org/scripts/12228/code/setMutationHandler.js
// ==/UserScript==

setMutationHandler({
    processExisting: true,
    selector: 'img[src*="wan_up"]',
    handler: images => images.forEach(img => {
        img.src = 'http://foo/bar.png';
    })
});

Edit the URL in @match, selector for the image to replace, new image URL accordingly. 编辑@match中的URL,选择要替换的图像的选择器,相应地更改新的图像URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tampermonkey 方法为页面上的所有“.jpg.webp”和“.png.webp”图像删除“.webp”扩展名? - Tampermonkey method to drop the “.webp” extension for all “.jpg.webp” and “.png.webp” images on a page? 如何在Cordova中将图像(.png)绘制到画布上? - How do I draw images (.png) to canvas in Cordova? 如何在 javascript 中根据名称显示 png 图像? - How do I show png images based on their names in javascript? 如何将头像 URL 转换为.png? - How do I convert an avatar URL to .png? 几秒钟后如何使用javascript将.gif文件更改为.png文件? - How do I change a .gif file to a .png file after a couple of seconds using javascript? 如何在 javascript 中将 png 图像的像素的 512x512 高度图数组放大到 2017x2017 像素,以用作虚幻引擎 4 中的高度图? - How do you upscale a 512x512 to 2017x2017 heightmap array of pixels of a png image in javascript for use as a heightmap in Unreal Engine 4? 如何在x时间内更改频道名称,然后将该名称恢复为原始名称,然后进行循环处理? - How can I change a channel name by x time, then return the name to the original one, and do a loop with that? 如何更改画布的“ x”和“ y”? - How do I change the 'x' and 'y' of a canvas? 如何让我的不和谐从 gif 中识别 png? - How do i make my discord recognize png from gifs? 如何将 webp 数据 URI 转换为 png - How do I convert webp data URI to png
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM