Using Violentmonkey scripts
-
concretable last edited by
How do you get a Violentmonkey script actually to be used? I imported a script that is supposed to be used with any site, but it is not being used. The code is here:
`
// ==UserScript==
// @name Brightness Fixer
// @author Frenzie
// @version 0.4
// @description Applies darker stylesheets based on the presence of bright backgrounds and includes a day/night switch.
// ==/UserScript==var bodyBackground = /*@Body background@string@*/'peachpuff'/*@*/; var maxIterations = /*@Max iterations@int@*/50/*@*/; var night = /*@Enable automatic night style@bool@*/false/*@*/; var nightTime = [/*@_Night start (hours)@int@*/19/*@*/, /*@_Night end (hours)@int@*/10/*@*/]; var thresHoldDay = /*@Brightness threshold day@int@*/245/*@*/; var thresHoldNight = /*@Brightness threshold night@int@*/242/*@*/; // from http://userstyles.org/styles/14836 var CSSDay = '\
// * {
// color: #000000 !important;
//
// }
a {color: #0000F4;}
li,html {
background-color: #98FB98 !important;
}
body {
background-color: peachpuff !important;
}
tr,td {
background-color: #90D4FF !important;
}
div {
background-color: #c0c0c0 !important;
}
pre,blockquote {
background-color: yellow !important;
}
select, textarea,
input[name=q], input[type=text], input[type=password], input[type=file] {
background-color: #c6e6e6 !important;
color: #222222 !important;
border-color: #aaaaaa !important;
border: 1px dotted #aaaaaa !important;
}
input[type=button], input[type=submit], input[type=reset] {
background-color: #f3f3b3 !important;
color: #222222 !important;
border-color: #aaaaaa !important;
}
';function getRGBColor(node,prop) { var rgb=getComputedStyle(node, null).getPropertyValue(prop); var r,g,b; if (node == document.documentElement && rgb == 'transparent') { node.style.backgroundColor = bodyBackground; return false; } if (/#([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})([A-Fa-f0-9]{2})/.exec(rgb)) { r=parseInt(RegExp.$1, 16); g=parseInt(RegExp.$2, 16); b=parseInt(RegExp.$3, 16); return [r, g, b]; } return false; } function addStyle(type) { var style = document.createElement('style'); style.setAttribute('type', 'text/css'); style.textContent = (type == 'night') ? CSSNight : CSSDay; //document.body.previousSibling.appendChild(style);// previousSibling might be a comment or something //document.getElementsByTagName('head')[0].appendChild(style);// valid, but might be superseded document.documentElement.appendChild(style);// not valid, but will supersede potential STYLE elements in document.body } function determineBrightness (color) { if (color) return (color[0]*299 + color[1]*587 + color[2]*114) / 1000; else return false; } function adjustBrightness(brightness) { if (night) { if ( ( hours < nightTime[0] && hours >= nightTime[1] ) && (brightness > thresHoldDay) ) { addStyle('day'); return true; } else if ( ( hours >= nightTime[0] || hours < nightTime[1] ) && (brightness > thresHoldNight) ) { addStyle('night'); return true; } } else if (brightness > thresHoldDay) { addStyle('day'); return true; } return false; } var allElem = document.getElementsByTagName('*'); for ( var i=0; i<allElem.length && i<maxIterations;// attempt not to impact performance too much vs. effectiveness i++ ) { var color = getRGBColor(allElem[i],'background-color'); //opera.postError(i+' rgb:'+color+' brightness:'+determineBrightness(color)); if (color && adjustBrightness(determineBrightness(color))) { break; } }
`
-
concretable last edited by
I listed the whole thing, but it does not work. It was originally a greasemonkey script, according to the person who got it for me. I have a problem with white backgrounds, which is why I wanted to use it. It worked fine with Presto Opera, but the structure of that was very different from the current Webkit Opera.
I am now using a script which I modified to create yellow backgrounds if the background is too light. The other one was nicer. It could use a different background for different elements. I do not know enough about javascript to specify the elements to change.
-
zalex108 last edited by
You may try Stylish and search in Userstyles.org "Global Dark" themes, they could be used as a Userscript too with Tamper / Violent Monkey extensions.
-
zalex108 last edited by
:eek: Wow!
I've give it a try and found a very welcome option, Schedule for the dark background!!
I've used dark background styles long time ago and lately I was thinking about an automatic enable / disable depending on the time and this extension does the trick!Thanks for posting it! :yes:
:cheers:
I have to test the schedule.
-
concretable last edited by
The issue with dimming things is solved. I found another script for Violentmonkey that does dim overly light pages.
Interestingly, with Night Mode Pro, I input a schedule to use for switching to night mode, but that does not work. I can switch manually, though.
-
concretable last edited by
AM and PM? I thought that HH:MM meant 24-hour time. That is what I use with the computer's operating system.
I tried to submit a bug report, but mybrowseraddon.com just gives an error message when I try. I did allow it to set cookies, since I have seen problems with CAPTCHAs when cookies are blocked. It does not matter what browser I use either.
-
concretable last edited by
Night Mode Pro just made a liar out of me. It switched modes. Why did it not do that before?
-
concretable last edited by
Night Mode Pro just made a liar out of me. It switched modes. Why did it not do that before? Does Opera have to be running at the time for it to switch?
-
zalex108 last edited by
Night Mode Pro just made a liar out of me.
:lol:
Don't worry, sometimes trust in others could make us seem to be a liar.Does Opera have to be running at the time for it to switch?
I suppose, since the extension works in Opera and don't have another process or service in the background to keep them alive.
-
concretable last edited by
But it means that there cannot be a flag to tell it that the time to switch has passed already.