javascript - 使用 Tampermonkey 更改 HTML 图像的不透明度
问题描述
我从来没有在 Tampermonkey 中创建过任何东西,所以我很感激你的帮助。
一个简单的脚本如何将以下元素的不透明度更改为 1?:
<div style="position: absolute; top: 1171px; left: 452px; -ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=10)'; filter: alpha(opacity=10); -moz-opacity: 0.1; opacity: 0.1; -khtml-opacity: 0.1; opacity: 0.1; z-index: 19;">
<a href="https://eggcave.com/gobblers/find?code=l9PCaWSN4Qm2cwoHZMtU7fhLXx8x8j8RPlsu4YpfjSgFHXMvWWqN9mImdY2s5S1lNNaVaB1QD5cHeN3hKQazN4V2XKnje1ffDiLk20BLahA8YuprAjTilLtKDHzLJZAU">
<img src="https://static.eggcave.com/90by90/gobbler_3.png">
</a>
</div>
解决方案
该 HTML 不足以真正很好地插入图像,并且您没有指出该页面是否是 javascript (AJAX) 驱动的。 您可能需要链接到目标页面。(或以其他方式提供 MCVE。)
然而,在大多数情况下,以下完整的工作脚本就足够了:
// ==UserScript==
// @name _Be through with see-through pictures
// @match *://YOUR_SERVER.COM/YOUR_PATH/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
//- The @grant directives are needed to restore the proper sandbox.
waitForKeyElements ("div[style*=opacity] > a > img[src*='gobbler_']", deOpaqueifyParent);
function deOpaqueifyParent (jNode) {
var parentNd = jNode.closest ("div");
parentNd.css ( {
filter: "",
"-ms-filter": "",
"-moz-opacity": "",
"-khtml-opacity": "",
opacity: "1",
} );
}
只需根据需要更改@match
线路。
推荐阅读
- swift - SwiftUI:导航到视图而不获取后退按钮
- node.js - 续集钩子不触发
- r - R中glm(y~x, family=poisson(link=log))的residuals(XX)和XX$residuals的区别
- reactjs - 无法从反应挂钩状态中获取值
- jquery - 使用 ASP.NET Core + VueJS 上传文件
- python - 在 Python 中获取 JSON 格式的数据
- windows - Inno Setup - 右键单击文件时是否可以添加“使用 MyAppName 编辑”?
- javascript - Firestore + Cloud Functions:多个条件子句
- xcode - 通过给定的 xcode/clang 检测最低支持的 OSX 版本
- android - 如何在android中只运行一个cordova inappbrowser实例