2012-07-10 97 views
1

我想一個bookmarklet轉換:爲什麼不能將這個書籤轉換爲一個userscript?

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

到userscript與Opera和綠使用。我遵循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); 
} 
})(); 

我在做什麼錯?

回答

2

它看起來像嵌入代碼中有一個流浪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); 
    } 
})(); 
+0

Thanks!它在Opera和Midori中都能像預期那樣運作。 – landroni 2012-07-10 12:12:15

相關問題