Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 3.75 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. JavaScript: Invert color on all elements of a page
  2. javascript: (function ($) {
  3.     function load_script(src, callback) {
  4.         var s = document.createElement('script');
  5.         s.src = src;
  6.         s.onload = callback;
  7.         document.getElementsByTagName('head')[0].appendChild(s);
  8.     }
  9.  
  10.     function invertElement() {
  11.         var colorProperties = ['color', 'background-color'];
  12.         var color = null;
  13.         for (var prop in colorProperties) {
  14.             prop = colorProperties[prop];
  15.             if (!$(this).css(prop)) continue;
  16.             if ($(this).data(prop) != $(this).css(prop)) continue;
  17.  
  18.             if (($(this).css(prop) === 'rgba(0, 0, 0, 0)') || ($(this).css(prop) === 'transparent')) {
  19.                 if ($(this).is('body')) {
  20.                     $(this).css(prop, 'black !important');
  21.                     continue;
  22.                 } else {
  23.                     continue;
  24.                 }
  25.             }
  26.             color = new RGBColor($(this).css(prop));
  27.             if (color.ok) {
  28.                 $(this).css(prop, 'rgb(' + (255 - color.r) + ',' + (255 - color.g) + ',' + (255 - color.b) + ') !important');
  29.             }
  30.             color = null;
  31.         }
  32.     }
  33.  
  34.     function setColorData() {
  35.         var colorProperties = ['color', 'background-color'];
  36.         for (var prop in colorProperties) {
  37.             prop = colorProperties[prop];
  38.             $(this).data(prop, $(this).css(prop));
  39.         }
  40.     }
  41.  
  42.     function invertColors() {
  43.         $(document).live('DOMNodeInserted', function(e) {
  44.             var $toInvert = $(e.target).find('*').andSelf();
  45.             $toInvert.each(setColorData);
  46.             $toInvert.each(invertElement);
  47.         });
  48.         $('*').each(setColorData);
  49.         $('*').each(invertElement);
  50.         $('iframe').each(function () {
  51.             $(this).contents().find('*').each(setColorData);
  52.             $(this).contents().find('*').each(invertElement);
  53.         });
  54.     }
  55.     load_script('http://www.phpied.com/files/rgbcolor/rgbcolor.js', function () {
  56.         if (!window.jQuery) load_script('https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', invertColors);
  57.         else invertColors();
  58.     });
  59.  
  60. })(jQuery);
  61.        
  62. //set up color properties to iterate through
  63. var colorProperties = ['color', 'background-color'];
  64.  
  65. //iterate through every element
  66. $('*').each(function() {
  67.     var color = null;
  68.  
  69.     for (var prop in colorProperties) {
  70.         prop = colorProperties[prop];
  71.  
  72.         //if we can't find this property or it's null, continue
  73.         if (!$(this).css(prop)) continue;
  74.  
  75.         //create RGBColor object
  76.         color = new RGBColor($(this).css(prop));
  77.  
  78.         if (color.ok) {
  79.             //good to go, let's build up this RGB baby!
  80.             //subtract each color component from 255
  81.             $(this).css(prop, 'rgb(' + (255 - color.r) + ', ' + (255 - color.g) + ', ' + (255 - color.b) + ')');
  82.         }
  83.         color = null; //some cleanup
  84.     }
  85. });
  86.        
  87. javascript:function load_script(src,callback){var s=document.createElement('script');s.src=src;s.onload=callback;document.getElementsByTagName('head')[0].appendChild(s);}function invertColors(){var colorProperties=['color','background-color'];$('*').each(function(){var color=null;for(var prop in colorProperties){prop=colorProperties[prop];if(!$(this).css(prop))continue;color=new RGBColor($(this).css(prop));if(color.ok){$(this).css(prop,'rgb('+(255-color.r)+','+(255-color.g)+','+(255-color.b)+')');}color=null;}});}load_script('http://www.phpied.com/files/rgbcolor/rgbcolor.js',function(){if(!window.jQuery)load_script('https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js',invertColors);else invertColors();});
  88.        
  89. load_script('http://www.example.com/pixastic.invert.js', function () {$('img').each(function() {try{$(this).pixastic("invert");} catch(e) {}})})