User Javascript for Opera needs fixing

Opera web browser and M2 mail client from Opera Software. (for Windows, Macintosh and Linux.)

User Javascript for Opera needs fixing

Postby Anonymosity » Thu 28 Oct, 2010 1:59 am

I want to add a user javascript to Opera to dim the background colour of a page if it is too light. I tried adapting the .js file from a Firefox extension, but it is not working. Is there any way to fix it so that it will work automatically?
Code: Select all
const nsIDOMNodeFilter = Components.interfaces.nsIDOMNodeFilter;

window.addEventListener("load", function() { killBrightBackgrounds.init(); }, false);

var killBrightBackgrounds = {

   init: function() {
      var appcontent = document.getElementById('appcontent');
      appcontent.addEventListener('DOMContentLoaded', this.onPageLoad, true);
   },

         var
      reduction = 38,
      threshold = 480,
      doc = aEvent.originalTarget,

      filter = function(aNode) {

         var r, g, b,
         rgb = doc.defaultView.getComputedStyle(aNode, null).getPropertyValue(property);

         if (/rgb\((\d+),\s(\d+),\s(\d+)\)/.exec(rgb)) {
            r = parseInt(RegExp.$1,10);
            g = parseInt(RegExp.$2,10);
            b = parseInt(RegExp.$3,10);
         }

         if (r + g + b >= threshold && rgb != 'transparent') {
            aNode.style.setProperty(property, 'rgb(' + (r - reduction) + ', ' + (g - reduction) + ', ' + (b - reduction) + ')', 'important');
            return nsIDOMNodeFilter.FILTER_ACCEPT;
         }

         return nsIDOMNodeFilter.FILTER_SKIP;
      };

      var i = 0, property,
      prop = new Array('background-color','border-top-color', 'border-left-color','border-bottom-color','border-right-color' );

      for (i; property = prop[i]; i++) {

         var walker = doc.createTreeWalker(doc, 1, filter, true);


         if (doc.documentElement.nodeName == 'HTML') {

            if (doc.defaultView.getComputedStyle(doc.documentElement, null).getPropertyValue('background-color') == 'transparent') {
               doc.documentElement.style.backgroundColor = doc.bgColor + ' !important';
            }

            while (walker.nextNode());

         }
   

      }

      return false;
   }
 
}
UserAgent: Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.6.30 Version/10.63
Anonymosity
silver member
silver member
 
Posts: 406
Joined: Sat 21 Jun, 2008 2:56 am

Return to Opera

Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]