Takhzen Catalog Link Elongator

Elongates all Takhzen Catalog Links to their direct links

  1. // ==UserScript==
  2.  
  3. // @name Takhzen Catalog Link Elongator
  4.  
  5. // @namespace DevelopmentSimplyPut(developmentsimplyput.blogspot.com)
  6.  
  7. // @description Elongates all Takhzen Catalog Links to their direct links
  8.  
  9. // @include *
  10.  
  11. // @exclude http://takhzen.com*
  12.  
  13. // @version 0.0.1.20141015205435
  14. // ==/UserScript==
  15.  
  16. String.prototype.ReplaceAll = function(stringToFind,stringToReplace){
  17. var temp = this;
  18. var index = temp.indexOf(stringToFind);
  19.  
  20. while(index != -1){
  21.  
  22. temp = temp.replace(stringToFind,stringToReplace);
  23. index = temp.indexOf(stringToFind);
  24. }
  25. return temp;
  26. }
  27.  
  28. Array.prototype.unique = function () {
  29. var r = new Array();
  30. o:for(var i = 0, n = this.length; i < n; i++)
  31. {
  32. for(var x = 0, y = r.length; x < y; x++)
  33. {
  34. if(r[x]==this[i])
  35. {
  36. continue o;
  37. }
  38. }
  39. r[r.length] = this[i];
  40. }
  41. return r;
  42. }
  43.  
  44. function insertAfter(referenceNode,newNode)
  45. {
  46. referenceNode.parentNode.insertBefore(newNode,referenceNode.nextSibling);
  47. }
  48.  
  49. function Run(Urls)
  50. {
  51. if(Urls.length>0)
  52. {
  53. for(i=0;i<Urls.length;i++)
  54. GetDirectLink(Urls[i]);
  55. }
  56. }
  57.  
  58. function ExpandUrls(HostersUrl,Node)
  59. {
  60. GM_xmlhttpRequest
  61. (
  62. {
  63. method: "GET",
  64. url: HostersUrl,
  65. headers:{'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey', 'Content-type':'application/x-www-form-urlencoded'},
  66. onload:function(result2)
  67. {
  68. result=result2.finalUrl;
  69. var Anchor=document.createElement('a');
  70. Anchor.setAttribute('href', result);
  71. Anchor.innerHTML='<font color="green">'+result+'</font>';
  72. var Breaker=document.createElement('br');
  73. insertAfter(Node, Breaker);
  74. insertAfter(Breaker, Anchor);
  75. }
  76. }
  77. )
  78. }
  79.  
  80. function GetDirectLink(str)
  81. {
  82. GM_xmlhttpRequest(
  83. {
  84. method: "GET",
  85. url: str,
  86. headers:{'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey', 'Content-type':'application/x-www-form-urlencoded'},
  87. onload:function(result)
  88. {
  89. var HostersUrls1=new Array();
  90. var HostersUrls2=new Array();
  91. var HostersUrls=new Array();
  92. var HostersPattern1=/http:\/\/www\.takhzen\.com\/(?:\w*)\/(?:\w*)/g;
  93. var HostersPattern2=/http:\/\/takhzen\.com\/(?:\w*)\/(?:\w*)/g;
  94. HostersUrls1=result.responseText.match(HostersPattern1);
  95. HostersUrls2=result.responseText.match(HostersPattern2);
  96. if(HostersUrls1 != null && HostersUrls2 != null)
  97. HostersUrls=HostersUrls1.concat(HostersUrls2);
  98. else if(HostersUrls1 != null && HostersUrls2 == null)
  99. HostersUrls=HostersUrls1;
  100. else if(HostersUrls2 != null && HostersUrls1 == null)
  101. HostersUrls=HostersUrls2;
  102. if(HostersUrls != null && HostersUrls.length>0)
  103. {
  104. HostersUrls=HostersUrls.unique();
  105.  
  106. var Nodes=new Array();
  107. Nodes=document.getElementsByTagName("a");
  108. for(var i=0;i<Nodes.length;i++)
  109. {
  110. if(Nodes[i].getAttribute('href')==str)
  111. {
  112. for(var h=0;h<HostersUrls.length;h++)
  113. {
  114. Nodes[i].innerHTML='<img src="http://img405.imageshack.us/img405/9007/logoat.jpg" />';
  115. ExpandUrls(HostersUrls[h],Nodes[i]);
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. );
  123. }
  124.  
  125. var DirectUrls=new Array();
  126. var Urls1=new Array();
  127. var Urls2=new Array();
  128. var Urls=new Array();
  129. var UrlsPattern1=/http:\/\/www\.takhzen\.com\/(?:\w*)/g;
  130. var UrlsPattern2=/http:\/\/takhzen\.com\/(?:\w*)/g;
  131. Urls1=(document.getElementsByTagName("body"))[0].innerHTML.match(UrlsPattern1);
  132. Urls2=(document.getElementsByTagName("body"))[0].innerHTML.match(UrlsPattern2);
  133.  
  134. if(Urls1 != null && Urls2 != null)
  135. Urls=Urls1.concat(Urls2);
  136. else if(HostersUrls1 != null && Urls2 == null)
  137. Urls=Urls1;
  138. else if(Urls2 != null && Urls1 == null)
  139. Urls=Urls2;
  140.  
  141. if(Urls != null && Urls.length>0)
  142. {
  143. Urls=Urls.unique();
  144. Run(Urls);
  145. }