Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么赢了';这个bookmarklet不能转换成用户脚本吗?_Javascript_Bookmarklet_Userscripts - Fatal编程技术网

Javascript 为什么赢了';这个bookmarklet不能转换成用户脚本吗?

Javascript 为什么赢了';这个bookmarklet不能转换成用户脚本吗?,javascript,bookmarklet,userscripts,Javascript,Bookmarklet,Userscripts,我正在尝试转换一个: 要与Opera和Midori一起使用的用户脚本。我跟着脚步走了进去,但运气不好。下面是我提出的代码,但似乎不起作用: // ==UserScript== // @name Darklooks // @description Eye-friendly colorscheme attempting to emulate Darklooks // @include http://* // @include https://* // @

我正在尝试转换一个:

要与Opera和Midori一起使用的用户脚本。我跟着脚步走了进去,但运气不好。下面是我提出的代码,但似乎不起作用:

// ==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)上进行了测试:

// ==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); 
} 
})();
(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);
    }
} ) ();