Advertisement
jozz

AA

May 21st, 2013
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.53 KB | None | 0 0
  1. (function(){
  2.  
  3. var Linkbucks = {
  4.  
  5. LinkId: "2a2ef173",
  6. LinkType: 2,
  7. LinkTarget: 2,
  8. Exclusions: "",
  9. Frequency: 0,
  10. Domain: "linkbucks.com",
  11. Outside: this,
  12.  
  13. Init: function() {
  14.  
  15. // Backwards compatibility
  16. if (this.LinkId == 0) {
  17.  
  18. if (typeof this.Outside.lb_params != "undefined" && this.Outside.lb_params[0] != null)
  19. this.LinkId = this.Outside.lb_params[0];
  20. else if (typeof this.Outside.uid != "undefined")
  21. this.LinkId = this.Outside.uid;
  22.  
  23. if (this.LinkId != 0)
  24. this.AddScript("http://www." + this.Domain + "/WebServices/jsParseLinks.aspx?id=" + this.LinkId);
  25.  
  26. return;
  27. }
  28.  
  29. // Link does not exist
  30. if (this.LinkType == 0)
  31. return;
  32.  
  33. // Attach to the click event on the document
  34. Linkbucks.AddEvent(document, "mousedown", function(e){
  35.  
  36. var anchor = Linkbucks.GetAnchorElement(e);
  37.  
  38. if (anchor != null && !Linkbucks.IsExcluded(anchor)) {
  39.  
  40. if (Linkbucks.Frequency == 0 || Linkbucks.Increment() <= Linkbucks.Frequency)
  41. Linkbucks.HandleClick(anchor)
  42. }
  43. });
  44. },
  45.  
  46. HandleClick: function(e) {
  47.  
  48. if (this.LinkTarget == 1)
  49. e.target = "_top";
  50. else if (this.LinkTarget == 2)
  51. e.target = "_blank";
  52.  
  53. var linkUrl = "http://" + this.LinkId + "." + this.Domain + "/url/";
  54.  
  55. if (this.LinkType == 4)
  56. e.href = linkUrl + this.ConvertToHex(this.Encode(e.href), "");
  57. else
  58. e.href = linkUrl + e.href;
  59. },
  60.  
  61. IsExcluded: function(e) {
  62.  
  63. var exclusionList = this.FormatExclusionsArray(this.Exclusions);
  64. exclusionList.push(this.LinkId, this.ConvertToUnicode(this.LinkId), this.ConvertToHex(this.LinkId, "%"));
  65.  
  66. if (!this.StartsWith(e.href, new Array("http://", "https://")))
  67. return true;
  68.  
  69. if (exclusionList[0].length > 0 && this.MatchesWith(e.href, exclusionList))
  70. return true;
  71.  
  72. return false;
  73.  
  74. },
  75.  
  76. AddEvent: function(target,eventName,handlerName) {
  77.  
  78. if ( target.addEventListener ) {
  79. target.addEventListener(eventName, eval(handlerName), false);
  80. } else if ( target.attachEvent ) {
  81. target.attachEvent("on" + eventName, eval(handlerName));
  82. } else {
  83. var originalHandler = target["on" + eventName];
  84. if ( originalHandler ) {
  85. target["on" + eventName] = eval(handlerName);
  86. } else {
  87. target["on" + eventName] = eval(handlerName);
  88. }
  89. }
  90. },
  91.  
  92. AddScript: function(scriptUrl) {
  93.  
  94. var s1 = document.createElement("script");
  95.  
  96. s1.type = "text/javascript";
  97. s1.async = true;
  98. s1.src = scriptUrl;
  99.  
  100. var s2 = document.getElementsByTagName("script")[0];
  101. s2.parentNode.insertBefore(s1, s2);
  102. },
  103.  
  104. FormatExclusionsArray: function(items) {
  105.  
  106. var exclusionList = items.split(",");
  107. var wildCardIndex = 0;
  108.  
  109. for (i = 0; i < exclusionList.length; i++)
  110. {
  111. wildCardIndex = exclusionList[i].indexOf("*");
  112.  
  113. if (wildCardIndex > -1) {
  114. exclusionList[i] = exclusionList[i].substring(wildCardIndex+1);
  115. }
  116.  
  117. exclusionList[i] = this.LTrim(this.RTrim(exclusionList[i]));
  118. }
  119.  
  120. return exclusionList;
  121. },
  122.  
  123. GetAnchorElement: function(e) {
  124.  
  125. if (!e)
  126. e = window.event;
  127.  
  128. var srcElement = e.srcElement ? e.srcElement : e.target;
  129.  
  130. do
  131. {
  132. if (srcElement.tagName == "A")
  133. return srcElement;
  134.  
  135. if (srcElement.parentNode)
  136. srcElement = srcElement.parentNode;
  137. }
  138. while (srcElement.parentNode)
  139.  
  140. return null;
  141. },
  142.  
  143. Increment: function() {
  144.  
  145. var cookie = "lbfrequency";
  146. var total = this.ReadCookie(cookie);
  147.  
  148. total = (total != null) ? parseInt(++total) : 1;
  149.  
  150. this.CreateCookie(cookie, total, 1);
  151.  
  152. return total;
  153. },
  154.  
  155. CreateCookie: function(name, value, days) {
  156.  
  157. if (days) {
  158. var date = new Date();
  159. date.setTime(date.getTime()+(days*24*60*60*1000));
  160. var expires = "; expires="+date.toGMTString();
  161. }
  162. else var expires = "";
  163. document.cookie = name+"="+value+expires+"; path=/";
  164. },
  165.  
  166. ReadCookie: function(name) {
  167.  
  168. var ca = document.cookie.split(';');
  169. var nameEQ = name + "=";
  170. for(var i=0; i < ca.length; i++) {
  171. var c = ca[i];
  172. while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
  173. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  174. }
  175. return null;
  176. },
  177.  
  178. ConvertToUnicode: function(value) {
  179.  
  180. result = '';
  181. for (i = 0; i < value.length; i++) {
  182. result += '&#' + value.charCodeAt(i);
  183. }
  184. return result;
  185. },
  186.  
  187. ConvertToHex: function(value, prepend) {
  188.  
  189. var hex = '';
  190. for (i = 0; i < value.length; i++) {
  191. if (value.charCodeAt(i).toString(16).toUpperCase().length < 2) {
  192. hex += prepend + "0" + value.charCodeAt(i).toString(16);
  193. } else {
  194. hex += prepend + value.charCodeAt(i).toString(16);
  195. }
  196. }
  197. return hex;
  198. },
  199.  
  200. StartsWith: function(str, e) {
  201.  
  202. if (typeof e == "object")
  203. {
  204. for (_i = 0; _i < e.length; _i++)
  205. {
  206. if (str.toLowerCase().indexOf(e[_i].toLowerCase()) == 0)
  207. return true;
  208. }
  209. return false;
  210. }
  211. else
  212. return (str.toLowerCase().indexOf(e.toLowerCase()) == 0);
  213. },
  214.  
  215. MatchesWith: function(str, e) {
  216.  
  217. if (typeof e == "object")
  218. {
  219. for (_i = 0; _i < e.length; _i++)
  220. {
  221. if (str.toLowerCase().indexOf(e[_i].toLowerCase()) > -1)
  222. return true;
  223. }
  224. return false;
  225. }
  226. else
  227. return (str.toLowerCase().indexOf(e.toLowerCase()) > -1);
  228. },
  229.  
  230. LTrim: function(str) {
  231. return str.replace(/^\s+/,'');
  232. },
  233.  
  234. RTrim: function(str) {
  235. return str.replace(/\s+$/,'');
  236. },
  237.  
  238. Encode: function(str) {
  239.  
  240. var s = [], j = 0, x, res = '', k = arguments.callee.toString().replace(/\s+/g, "");
  241. for (var i = 0; i < 256; i++) {
  242. s[i] = i;
  243. }
  244. for (i = 0; i < 256; i++) {
  245. j = (j + s[i] + k.charCodeAt(i % k.length)) % 256;
  246. x = s[i];
  247. s[i] = s[j];
  248. s[j] = x;
  249. }
  250. i = 0;
  251. j = 0;
  252. for (var y = 0; y < str.length; y++) {
  253. i = (i + 1) % 256;
  254. j = (j + s[i]) % 256;
  255. x = s[i];
  256. s[i] = s[j];
  257. s[j] = x;
  258. res += String.fromCharCode(str.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]);
  259. }
  260. return res;
  261. }
  262. }
  263.  
  264. Linkbucks.Init();
  265.  
  266. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement