Advertisement
Guest User

lanund.js

a guest
Jun 14th, 2016
12,266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. // jsPopUnda - 2014
  2. // Lan @ TitsPlz.com
  3.  
  4. function jsUnda(sUrl, sConfig) {
  5.  
  6. var _parent = (top != self && typeof(top.document.location.toString()) === 'string') ? top : self;
  7. var unda = null;
  8.  
  9. sConfig = (sConfig || {});
  10.  
  11. var sName = (sConfig.name || Math.floor((Math.random() * 1000) + 1));
  12. var sWidth = (sConfig.width || window.outerWidth || window.innerWidth);
  13. var sHeight = (sConfig.height || (window.outerHeight-100) || window.innerHeight);
  14.  
  15. var sPosX = (typeof(sConfig.left) != 'undefined') ? sConfig.left.toString() : window.screenX;
  16. var sPosY = (typeof(sConfig.top) != 'undefined') ? sConfig.top.toString() : window.screenY;
  17.  
  18. /* capping */
  19. var sWait = (sConfig.wait || 3600); sWait = (sWait * 1000);
  20. var sCap = (sConfig.cap || 2);
  21.  
  22. /* cookie stuff */
  23. var popsToday = 0;
  24. var cookie = (sConfig.cookie || '__.unda');
  25.  
  26. var browser = function() {
  27. var n = navigator.userAgent.toLowerCase();
  28. var b = {
  29. webkit: /webkit/.test(n),
  30. mozilla: (/mozilla/.test(n)) && (!/(compatible|webkit)/.test(n)),
  31. chrome: /chrome/.test(n),
  32. msie: (/msie/.test(n)) && (!/opera/.test(n)),
  33. firefox: /firefox/.test(n),
  34. safari: (/safari/.test(n) && !(/chrome/.test(n))),
  35. opera: /opera/.test(n)
  36. };
  37. b.version = (b.safari) ? (n.match(/.+(?:ri)[\/: ]([\d.]+)/) || [])[1] : (n.match(/.+(?:ox|me|ra|ie)[\/: ]([\d.]+)/) || [])[1];
  38. return b;
  39. }();
  40.  
  41.  
  42. function isCapped() {
  43. try {
  44. popsToday = Math.floor(document.cookie.split(cookie + 'Cap=')[1].split(';')[0]);
  45. } catch (err) {}
  46. return (sCap <= popsToday || document.cookie.indexOf(cookie + '=') !== -1);
  47. }
  48.  
  49.  
  50. function doUnda(sUrl, sName, sWidth, sHeight, sPosX, sPosY) {
  51. if (isCapped()) return;
  52.  
  53. var sOptions = 'toolbar=no,scrollbars=yes,location=yes,statusbar=yes,menubar=no,resizable=1,width=' + sWidth.toString() + ',height=' + sHeight.toString() + ',screenX=' + sPosX + ',screenY=' + sPosY;
  54.  
  55. document.onclick = function() {
  56. if (isCapped()) return;
  57.  
  58. // ---
  59. // chrome27 fix
  60. window.open("javascript:window.focus();", "_self", "");
  61. // ---
  62.  
  63. unda = _parent.window.open(sUrl, sName, sOptions);
  64. if (unda) {
  65. // cookie
  66. var now = new Date();
  67. document.cookie = cookie + '=1;expires=' + new Date(now.setTime(now.getTime() + sWait)).toGMTString() + ';path=/';
  68. now = new Date();
  69. document.cookie = cookie + 'Cap=' + (popsToday + 1) + ';expires=' + new Date(now.setTime(now.getTime() + (84600 * 1000))).toGMTString() + ';path=/';
  70. pop2under();
  71. }
  72. };
  73. }
  74.  
  75.  
  76. function pop2under() {
  77. try {
  78. unda.blur();
  79. unda.opener.window.focus();
  80. window.self.window.blur();
  81. window.focus();
  82.  
  83. if (browser.firefox) openCloseWindow();
  84. if (browser.webkit) openCloseTab();
  85. } catch (e) {}
  86. }
  87.  
  88. function openCloseWindow() {
  89. var ghost = window.open('about:blank');
  90. ghost.focus();
  91. ghost.close();
  92. }
  93.  
  94. function openCloseTab() {
  95. var ghost = document.createElement("a");
  96. ghost.href = "about:blank";
  97. ghost.target = "PopHelper";
  98. document.getElementsByTagName("body")[0].appendChild(ghost);
  99. ghost.parentNode.removeChild(ghost);
  100.  
  101. var clk = document.createEvent("MouseEvents");
  102. clk.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
  103. ghost.dispatchEvent(clk);
  104.  
  105. // open a new tab for the link to target
  106. window.open(ghost.href, ghost.target).close();
  107. }
  108.  
  109.  
  110. // abort?
  111. if (isCapped()) {
  112. return;
  113. } else {
  114. doUnda(sUrl, sName, sWidth, sHeight, sPosX, sPosY);
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement