// ==UserScript==
// @name Opera sniffing detector
// @author Øystein R. Ryen 
// @namespace http://userjs.org/ 
// @version 1.0
// @description  Displays a warning whenever a script on the page is
//			attempting to detect Opera.
// @ujs:category general: enhancements
// @ujs:published 2005-08-26 08:59
// @ujs:modified 2005-09-19 09:19
// @ujs:documentation http://userjs.org/scripts/general/enhancements/detect-opera-sniffing 
// @ujs:download http://userjs.org/scripts/download/general/enhancements/detect-opera-sniffing.js
// ==/UserScript==


/* 
 * This script is granted to the Public Domain.
 */

window.opera.addEventListener('BeforeScript',function(ev) {

  //Prompt to ask whether you want to allow sniffing or not
  //0 = never, 1 = always, 2 = prevent sniffing without promting (not recommended)
  var confirmSniff = 0;

  //where should sniffing be reported
  //0 = status toolbar, 1 = JavaScript console, 2 = both
  var reportTo = 0;
  
  var uaExpr = /(indexOf\s*\(\s*["'])[Oo]pera/g;
  var objExpr = /window.opera\.{0}/g;
  var ua = ev.element.text.match(uaExpr) ? " ua detection" : ""; 
  var obj = ev.element.text.match(objExpr) ? " object detection" : "";
  
  if (ua || obj) {
    if (reportTo != 1) {
      window.defaultStatus = "Opera sniffed(" + ua + obj + " )";  //print message in status window
    }
    if (reportTo) {
      this.postError("Opera sniffed(" + ua + obj + " )");     //print message in javascript console
    }
    
    if ( (confirmSniff == 2) || ( (confirmSniff == 1) && !window.confirm('Allow script to detect Opera?') ) ) {
      ev.element.text=ev.element.text.replace(objExpr,'false');
      ev.element.text=ev.element.text.replace(uaExpr,'$1bugoff');
      if (reportTo) { this.postError("Sniffing prevented"); }
    }
  }
},false);
