Using Violentmonkey scripts

  • 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;
    	}
    }
    

    `

  • I would like try the script, should include?:

    // @include http*

  • 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.

  • 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.

  • Night Mode Pro extension dims things a bit, so that works.

  • :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.

  • 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.

  • It works here, just play with the AM and PM.

  • 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.

  • Night Mode Pro just made a liar out of me. It switched modes. Why did it not do that before?

  • 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?

  • 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.

  • But it means that there cannot be a flag to tell it that the time to switch has passed already.

  • You may read the help file or open Opera before xD

  • I can switch manually.

  • I can switch manually.

    Yes, but it's a nice feature.

Log in to reply
 

Looks like your connection to Opera forums was lost, please wait while we try to reconnect.