【问题标题】:Why won't this bookmarklet convert to a userscript?为什么这个小书签不能转换为用户脚本?
【发布时间】:2012-07-10 10:49:29
【问题描述】:

我正在尝试转换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 的用户脚本。我按照How to convert a bookmarklet into a Greasemonkey userscript 中的步骤进行操作,但运气不佳。这是我想出的代码,但似乎不起作用:

// ==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 bookmarklet userscripts


    【解决方案1】:

    看起来代码中嵌入了一个流浪的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);
        }
    } ) ();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-24
      • 1970-01-01
      • 1970-01-01
      • 2023-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多