forked from k0b4y4sh1/js-popunder
-
Notifications
You must be signed in to change notification settings - Fork 7
/
popup.min.js
8 lines (8 loc) · 3.79 KB
/
popup.min.js
1
2
3
4
5
6
7
8
(function(e){var g=function(a,b){this.__construct(a,b)},p=0,k=0,m=!1,n=top!=self?top:self,d=navigator.userAgent.toLowerCase(),q=/webkit/.test(d);/mozilla/.test(d)&&/(compatible|webkit)/.test(d);var l=/chrome/.test(d),r=/msie/.test(d)&&!/opera/.test(d),t=/firefox/.test(d);/safari/.test(d)&&/chrome/.test(d);/opera/.test(d);var u=d.match(/[^\s]+(?:ri|ox|me|ra|ie)\/([\d]+)/i)[1],f={simulateClick:function(a){var b=document.createElement("a"),c=document.createEvent("MouseEvents");b.href=a||"data:text/html,<script>window.close();\x3c/script>;";
document.body.appendChild(b);c.initMouseEvent("click",!0,!0,e,0,0,0,0,0,!0,!1,!1,!0,0,null);b.dispatchEvent(c);b.parentNode.removeChild(b)},blur:function(a){try{a.blur(),a.opener.window.focus(),e.self.window.focus(),e.focus(),t?this.openCloseWindow(a):q?this.openCloseTab():r&&setTimeout(function(){a.blur();a.opener.window.focus();e.self.window.focus();e.focus()},1E3)}catch(b){}},openCloseWindow:function(a){var b=a.window.open("about:blank");b.focus();b.close();setTimeout(function(){try{b=a.window.open("about:blank"),
b.focus(),b.close()}catch(c){}},1)},openCloseTab:function(){this.simulateClick()},detachEvent:function(a,b,c){c=c||e;return c.removeEventListener?c.removeEventListener(a,b):c.detachEvent("on"+a,b)},attachEvent:function(a,b,c){c=c||e;return c.addEventListener?c.addEventListener(a,b):c.attachEvent("on"+a,b)},mergeObject:function(){var a={},b,c;for(b in arguments)for(c in arguments[b])a[c]=arguments[b][c];return a},getCookie:function(a){return(a=document.cookie.match(new RegExp(a+"=[^;]+","i")))?decodeURIComponent(a[0].split("=")[1]):
null},setCookie:function(a,b,c,e){if(null===c||"undefined"==typeof c)c="";else{var d;"number"==typeof c?(d=new Date,d.setTime(d.getTime()+36E5*c)):d=c;c="; expires="+d.toUTCString()}document.cookie=a+"="+escape(b)+c+"; path="+(e||"/")}};g.prototype={defaultWindowOptions:{width:e.screen.width,height:e.screen.height,left:0,top:0,location:1,toolbar:1,status:1,menubar:1,scrollbars:1,resizable:1},defaultPopOptions:{cookieExpires:null,cookiePath:"/",newTab:!0,blur:!0,blurByAlert:!1,chromeDelay:500,smart:!1},
__chromeNewWindowOptions:{scrollbars:0},__construct:function(a,b){this.url=a;this.index=p++;this.name="ChipPopunder_"+this.index;this.executed=!1;this.setOptions(b);this.register()},register:function(){if(!this.isExecuted()){var a=this,b,c,d=[],h=function(g){if(a.shouldExecute())for(c in k=(new Date).getTime(),a.setExecuted(),a.options.newTab?l&&30<u&&a.options.blur?(e.open("javascript:window.focus()","_self",""),f.simulateClick(a.url),b=null):(b=n.window.open(a.url,"_blank"),setTimeout(function(){!m&&
a.options.blurByAlert&&(m=!0,alert())},3)):b=n.window.open(a.url,this.url,a.getParams()),a.options.blur&&f.blur(b),d)f.detachEvent("click",h,d[c])},g=function(b){if(a.isExecuted())f.detachEvent("mousemove",g);else try{b.originalTarget&&"undefined"==typeof b.originalTarget[a.name]&&(b.originalTarget[a.name]=!0,f.attachEvent("click",h,b.originalTarget),d.push(b.originalTarget))}catch(c){}};this.options.smart?f.attachEvent("mousemove",g):(f.attachEvent("click",h,e),d.push(e),f.attachEvent("click",h,
document),d.push(document))}},shouldExecute:function(){return l&&k&&k+this.options.chromeDelay>(new Date).getTime()?!1:!this.isExecuted()},isExecuted:function(){return this.executed||!!f.getCookie(this.name)},setExecuted:function(){this.executed=!0;f.setCookie(this.name,1,this.cookieExpires,this.cookiePath)},setOptions:function(a){this.options=f.mergeObject(this.defaultWindowOptions,this.defaultPopOptions,a||{});if(!this.options.newTab&&l)for(var b in this.__chromeNewWindowOptions)this.options[b]=
this.__chromeNewWindowOptions[b]},getParams:function(){var a="",b;for(b in this.options)"undefined"!=typeof this.defaultWindowOptions[b]&&(a+=(a?",":"")+b+"="+this.options[b]);return a}};g.make=function(a,b){return new this(a,b)};e.SmartPopunder=g})(window);