我在 FF57 中使用 Greasemonkey 4.1beta4(最新测试版)。
使用以下脚本(供参考,这里是完整的脚本)
确实创建了对话框,但不幸的是它有一个灰色的空方块,应该是关闭图标:
// ==UserScript==
// @name jQuery UI dialog
// @include /^https?:\/\/hg\.mozilla\.org.*pushloghtml.*/
// @require https://code.jquery.com/jquery-2.1.4.min.js
// @require https://code.jquery.com/ui/1.12.1/jquery-ui.min.js
// @resource css http://code.jquery.com/ui/1.12.1/themes/redmond/images/ui-icons_469bdd_256x240.png
// @grant GM.getResourceUrl
// ==/UserScript==
// I use an ajax request in the beginning in order to inject the CSS file, otherwise it's blocked by the page's CSP
$.ajax({
url:'http://code.jquery.com/ui/1.12.1/themes/redmond/jquery-ui.min.css',
success:function(data){
$('<style></style>').appendTo('head').html(data);
}
});
var div = document.createElement('div');
$('div.page_footer').append(div);
div.id = 'dialog';
$('#dialog').dialog({
});
脚本适用的示例页面:
https ://hg.mozilla.org/mozilla-central/pushloghtml?startdate=1+day+ago&enddate=now
我在这个问题中看到
问题是我不包括精灵图像(我使用它的主题http://code.jquery.com/ui/1.12.1/themes/redmond/images/ui-icons_469bdd_256x240.png
)。
background
因此,基于此回复,我一直在尝试将精灵图像(PNG)用作该元素的(CSS) 。
以下是我迄今为止的 4 次不成功的尝试(将以下每个部分附加到上面):
GM.getResourceUrl()
(内部async/await
,由于 GM 4.x)
(在这种情况下,关闭框只是将颜色变为浅蓝色)
(async function() {
var stylesheet = `
<style>
.ui-dialog-titlebar-close {
background: url('` + await GM.getResourceUrl("css1") + `') repeat scroll -93px -128px rgba(0, 0, 0, 0) !important;
border: medium none;
}
</style>`;
$('head').append(stylesheet);
})();
将 PNG 编码为 base64 并尝试附加它:(
在这种情况下,PNG 确实已加载(如 FF'S Inspector 中所示),但关闭框只是将颜色更改为浅蓝色)
var stylesheet = `
<style>
.ui-dialog-titlebar-close {
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAADwCAMAAADYSUr5AAAABGdBTUEAALGPC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HqQsq3ctr2uchD0/YBXuoJaPlW+4Wkll0dpi/TnjQxUFs70Vzr9lbN9Ad50daKTpAvaf4Hfd/ABdAPQyHUlotoNPj3Fu8Oh/Dyd5ddb5LZ0vHtm/wlGf8RPP/0kzP4IcbLi/hqgd3odshq9p6TDuEMsv2AK+fMTAoL9EfV/h3xS6r8+AqboM+gsBNh+tlEo2L7FQnwWcCJK/VcmIDwE1KdvtTHx0BCBEIHeISVIfipLBk6a/EHQ9wMsk1o9CepJjE5SQGX3pGqdJGn7dJI102t+XLIaA40cxKYfY10fo23lMDbtyHR1pNrKYWzale3qSreVIyIiIiIiIjyoHIczk3sP8vcDw/IFJAD8BBRfWEHhJ0DQP3rYb5QfSQgemRAE9TeXTP78Xd8RLeDSzwGX/SkQERERERERsW4k58cTCJ6ChKz9QdeE/H2gPiMRgb6uQAC93+dJ/3VYANX3XOlvWkBxvL34chDQ7L2Z+hocqtIXdg7Iapj64zte6n9+bKCrBZT5z6/+XS3g3Ovf9Sng0P/CzgEBaP3Pjw0ELaANlN71/4iInuP/VPKCJpghgS4AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTYtMDktMTRUMTI6MzA6NDAtMDQ6MDA8nFfaAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE1LTEwLTE5VDE3OjUzOjI5LTA0OjAwi40o4wAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAAASUVORK5CYII=')
repeat scroll -93px -128px rgba(0, 0, 0, 0) !important;
border: medium none;
}
</style>`;
$('head').append(stylesheet);
在这种情况下,以下是 Web 控制台中显示的内容:
内容安全策略:该页面的设置阻止在
data:image/png;base64,iVBORw0KGgoAAAANSU...
(“img-srchttps://hg.mozilla.org
”) 处加载资源。
ajax 请求,并将响应用作 PNG
(关闭框只是将颜色更改为浅蓝色)
$.ajax({
url:'http://code.jquery.com/ui/1.10.3/themes/smoothness/images/ui-icons_888888_256x240.png',
type: 'POST',
contentType: 'image/png',
data: {},
success:function(data){
$('.ui-dialog-titlebar-close').css('background', 'url(' + data + ')');
}
});
XMLHttpRequest(); (这里是目标 PNG -as blob- 它被页面的 CSP 阻止)
var oReq = new XMLHttpRequest();
oReq.open("post", 'http://code.jquery.com/ui/1.10.3/themes/smoothness/images/ui-icons_888888_256x240.png', true );
oReq.responseType = "blob";
oReq.onload = function ( oEvent )
{
var blob = oReq.response;
var imgSrc = URL.createObjectURL( blob );
$('.ui-dialog-titlebar-close').css('background', 'url(' + imgSrc + ')');
};
oReq.send( null );
在这种情况下,以下是 Web 控制台中显示的内容:
https://hg.mozilla.org/b0197e3c-3323-4f43-bdc8-3c2fb663748d
内容安全策略:该页面的设置阻止了在 blob: (“img-srchttps://hg.mozilla.org
”)处加载资源。
如何使 X 按钮出现?