【发布时间】:2017-12-08 11:51:46
【问题描述】:
我正在尝试编写一个 Greasemonkey 脚本来替换 .css 文件的一行。
all.css的原行是
#header {
background: transparent url('img/bg-graph-top.png?v=7e4ce14d05fb') no-repeat 50% -25px;
}
我想用
替换它#header {
background: transparent url('https://upload.wikimedia.org/wikipedia/commons/0/09/Dummy_flag.png') no-repeat 50% -25px;
}
基于https://stackoverflow.com/a/6854437/9072294,我尝试像这样编写我的第一个用户脚本:
// ==UserScript==
// @name swap
// @include http://tex.stackexchange.com/*
// @include https://tex.stackexchange.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// ==/UserScript==
var desiredImage = "https://upload.wikimedia.org/wikipedia/commons/0/09/Dummy_flag.png";
//--- Straight image swap:
$('img/bg-graph-top.png?v=7e4ce14d05fb').attr ('src', desiredImage);
/*--- Replace the link's -- with the logo as a background -- contents with just a plain image.
Since this image is transparent, clear the old BG image.
Also constrain the new img to its container.
*/
$('#header all').css ('background-', 'none')
.append ('<url>').find ('img/bg-graph-top.png?v=7e4ce14d05fb') .attr ('src', desiredImage).css ();
但是图像没有改变:(
【问题讨论】:
标签: css greasemonkey userscripts tampermonkey