I'm trying to convert a 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); } })();
to a userscript to use with Opera and Midori. I followed the steps in How to convert a bookmarklet into a Greasemonkey userscript but without much luck. Here's the code that I come up with, but which doesn't seem to function:
// ==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);
}
})();
What am I doing wrong?
It looks like there was a stray javascript:
embedded in the code.
Anyway, try this. It works, but I only tested on my primary browsers (Firefox and 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);
}
} ) ();