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

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 3.26 KB  |  hits: 19  |  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. http://127.0.0.1:37935/xpopup.js
  2.  
  3. var _orig_windowOpen = window.open;
  4. var _orig_windowSetTimeout = window.setTimeout;
  5. var _orig_windowSetInterval = window.setInterval;
  6.  
  7. var _orig_onUnload;
  8. var _orig_onLoad;
  9.  
  10. var _tmpWindowOpen;
  11.  
  12. function _emptyWindow( hOpener ){
  13.         this.focus = _safe_focus;
  14.         this.blur = _safe_blur;
  15.  
  16.         // set to main (parent) window
  17.         this.opener = hOpener;
  18.  
  19.         // create dummy document object
  20.         this.document = new Object();
  21.         this.document.open = _safe_documentOpen;
  22.         this.document.close = _safe_documentClose;
  23.         this.document.write = _safe_documentWrite;
  24.         this.document.writeln = _safe_documentWriteln;
  25. }
  26.  
  27. // dummy implementations
  28. function _safe_blur(){
  29. }
  30.  
  31. function _safe_focus(){
  32. }
  33.  
  34. function _safe_documentOpen( sUrl, sName, sFeatures, bReplace ){
  35. }
  36.  
  37. function _safe_documentClose(){
  38. }
  39.  
  40. function _safe_documentWrite( sText ){
  41. }
  42.  
  43. function _safe_documentWriteln( sText ){
  44. }
  45.  
  46. function _isOpenAllowed( sName ){
  47.         return ( sName != '' && sName == window.name) || sName == '_top' || sName == '_self';
  48. }
  49.  
  50. function _safe_open( sURL, sName, sFeatures ){
  51.         if ( _isOpenAllowed( sName ) )
  52.                 return _orig_windowOpen(sURL, sName, sFeatures);
  53.         else
  54.                 return ( new _emptyWindow( this.window ));
  55. }
  56.  
  57. function _block_windowOpen(){
  58.         // save window open handler
  59.         _tmpWindowOpen = window.open;
  60.         window.open = _safe_open;
  61. }
  62.  
  63. function _unblock_windowOpen(){
  64.         // restore window open handler
  65.         window.open = _tmpWindowOpen;
  66. }
  67.  
  68. function _safe_setInterval( sCode, iMilliSeconds ){
  69.         // first block window.open -> execute the code -> unblock window.open
  70.         return (_orig_windowSetInterval("_block_windowOpen(); " + sCode + "; _unblock_windowOpen();", iMilliSeconds ));
  71. }
  72.  
  73. var m_timeoutCodes = new Array();
  74. var m_timeoutCodesIndex = 0;
  75.  
  76. function executeTimoutCode(index){
  77.         m_timeoutCodes[index].runner();
  78. }
  79.  
  80. function _safe_setTimeout( sCode, iMilliSeconds ){
  81.         // first block window.open -> execute the code -> unblock window.open
  82.         if (typeof(sCode) == "function"){
  83.                 m_timeoutCodes[m_timeoutCodesIndex] = new Object();
  84.                 m_timeoutCodes[m_timeoutCodesIndex].runner = sCode;
  85.                 m_timeoutCodesIndex++;
  86.  
  87.                 return (_orig_windowSetTimeout("_block_windowOpen(); executeTimoutCode(" + (m_timeoutCodesIndex-1) + "); _unblock_windowOpen();", iMilliSeconds ));
  88.         } else {
  89.                 return (_orig_windowSetTimeout("_block_windowOpen(); " + sCode + "; _unblock_windowOpen();", iMilliSeconds ));
  90.         }
  91. }
  92.  
  93. function _safe_onLoad(){
  94.         // start blocking
  95.         _block_windowOpen();
  96.  
  97.         // run original handler
  98.         if (_orig_onLoad)
  99.         _orig_onLoad();
  100.  
  101.         // stop blocking
  102.         _unblock_windowOpen();
  103. }
  104.  
  105. function _safe_onUnload(){
  106.         // start blocking
  107.         _block_windowOpen();
  108.  
  109.         // run original handler
  110.         if (_orig_onUnload)
  111.         _orig_onUnload();
  112.  
  113.         // stop blocking
  114.         _unblock_windowOpen();
  115. }
  116.  
  117. var m_bRunOnlyOne = false;
  118.  
  119. function _popupControl(){
  120.         if ( !m_bRunOnlyOne ){
  121.                 m_bRunOnlyOne = true;
  122.  
  123.                 // page is processed, allow popup windows
  124.                 window.open = _orig_windowOpen;
  125.  
  126.                 // save onload and onunload event handlers
  127.                 _orig_onLoad = window.onload;
  128.                 _orig_onUnload = window.onunload;
  129.  
  130.                 // replace handlers
  131.                 window.onunload = _safe_onUnload;
  132.                 window.onload = _safe_onLoad;
  133.         }
  134. }
  135.  
  136. window.setTimeout = _safe_setTimeout;
  137. window.setInterval = _safe_setInterval;
  138. window.open = _safe_open;