为什么获胜't将这个bookmarklet转换为用户脚本
Why won't this bookmarklet convert to a userscript?
我正在尝试转换bookmarklet:
javascript:(function(){var newSS, styles='* { background: white ! important; color: black !important } :link, :link * { color: #0000EE !important } :visited, :visited * { color: #551A8B !important }'; if(document.createStyleSheet) { document.createStyleSheet(%22javascript:'%22+styles+%22'%22); } else { newSS=document.createElement('link'); newSS.rel='stylesheet'; newSS.href='data:text/css,'+escape(styles); document.getElementsByTagName(%22head%22)[0].appendChild(newSS); } })();
到与Opera和Midori一起使用的用户脚本。我遵循了"如何将bookmarklet转换为Greasemonkey用户脚本"中的步骤,但运气不佳。这是我想出的代码,但似乎不起作用:
// ==UserScript==
// @name Darklooks
// @description Eye-friendly colorscheme attempting to emulate Darklooks
// @include http://*
// @include https://*
// @include about:blank*
// ==/UserScript==
(function() {
var newSS, styles='* { background: #555753 ! important; color: #D3D7CF !important } :link, :link * { color: #00008B !important } :visited, :visited * { color: #551A8B !important }'; if(document.createStyleSheet) { document.createStyleSheet("javascript:'" styles "'"); } else { newSS=document.createElement('link'); newSS.rel='stylesheet'; newSS.href='data:text/css,' escape(styles); document.getElementsByTagName("head")[0].appendChild(newSS);
}
})();
我做错了什么?
代码中似乎嵌入了一个零散的javascript:
。
不管怎样,试试这个。它有效,但我只在我的主要浏览器(Firefox和Chrome)上进行了测试:
(function () {
var newSS;
var styles = '* { background: white ! important; color: black !important } :link, :link * { color: #0000EE !important } :visited, :visited * { color: #551A8B !important }';
if (document.createStyleSheet) {
document.createStyleSheet(styles);
}
else {
newSS = document.createElement('link');
newSS.rel = 'stylesheet';
newSS.href = 'data:text/css,' + escape(styles);
document.getElementsByTagName("head")[0].appendChild(newSS);
}
} ) ();
相关文章:
- 如何在JavaScript中将字符串转换为函数引用
- 如何在Javascript中将JSon对象转换为数组
- 使用JS将数组转换为json对象
- 如何使用json将对象列表从java转换为javascript
- 偶尔结结巴巴地说“;堆叠的”;translate()上的转换(v4.0.0-alpha40)
- 为什么在单独的函数中应用时转换会闪烁/断断续续(D3)
- 在Javascript中转换对象数组
- 将数字转换为一定数量的硬币
- 将纯文本URL转换为可单击链接
- 当图像转换为本地存储的DataURL时,EXIF被删除
- 如何使用js将SNAPSHOT内部版本号转换为3位数的整数
- 如何将TypeScript对象转换为普通对象
- 检测个位数整数时正在转换毫秒
- 从javascript到jquery的转换
- DOM事件通过JSON转换为java
- 将圆柱体转换为弯管
- 混合 ui-sref 和 $state.go 在 Angular ui-router 中进行状态转换
- 为什么获胜't将这个bookmarklet转换为用户脚本
- 如何将JavaScript代码转换为bookmarklet ?
- 如何将bookmarklet转换为Greasemonkey用户脚本