Advertisement
Guest User

Untitled

a guest
Sep 14th, 2013
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. chrome.runtime.onInstalled.addListener(function(details){
  2. if(details.reason == "install"){
  3. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
  4. var string_length = 8;
  5. var randomstring = '';
  6. var charCount = 0;
  7. var numCount = 0;
  8.  
  9. for (var i=0; i<string_length; i++) {
  10. if((Math.floor(Math.random() * 2) == 0) && numCount < 3 || charCount >= 5) {
  11. var rnum = Math.floor(Math.random() * 10);
  12. randomstring += rnum;
  13. numCount += 1;
  14. } else {
  15. var rnum = Math.floor(Math.random() * chars.length);
  16. randomstring += chars.substring(rnum,rnum+1);
  17. charCount += 1;
  18. }
  19. }
  20.  
  21. console.log(randomstring);
  22. localStorage['extensionId'] = randomstring;
  23. }
  24. });
  25.  
  26.  
  27. if (localStorage.getItem("userEmail") === null) {
  28. localStorage['userEmail'] = '';
  29. }
  30.  
  31. if (localStorage.getItem("status") === null) {
  32. localStorage['status'] = 'default';
  33. }
  34.  
  35. var userIsRegistered=false;
  36.  
  37.  
  38. checkRegistered = function(email){
  39. $.ajax({
  40. type: "GET",
  41. url: "http://twittersneakerbot.isgeek.eu/justCheck.php",
  42. data: {'key' : localStorage['extensionId'], 'email': email}
  43. }).done(function( res ) {
  44. userIsRegistered = (res == "true");
  45. if(res == "error 3"){
  46. localStorage['registerStatus'] = "Your subscription has ended and must be renewed.";
  47. }
  48. if(res == "error 2"){
  49. localStorage['registerStatus'] = "Please wait 24h before using another computer.";
  50. }
  51. if(res == "error 1"){
  52. localStorage['registerStatus'] = "Your email was not found in our database.";
  53. }
  54. });
  55. }
  56.  
  57. if(localStorage['userEmail'] != ''){
  58. checkRegistered(localStorage['userEmail']);
  59. }
  60.  
  61. getAllCurrentLinks = function(handle){
  62. myUrl = "https://twitter.com/i/profiles/show/";
  63. myUrl += handle;
  64. myUrl += "/timeline";
  65.  
  66. $.ajax({
  67. type: "GET",
  68. url: myUrl,
  69. dataType: 'json'
  70. }).done(function( json ) {
  71.  
  72. twitts = $(json.items_html).find('li.stream-item .content p.tweet-text').prevObject.filter("li");
  73. //console.log(twitts);
  74. $.each(twitts, function(i,val){
  75. links = $(val).find("p.tweet-text a");
  76. $.each(links, function(k,v){
  77. var toOpenUrl = $(v).attr('href');
  78. openedLinkArray.push(toOpenUrl);
  79. });
  80. });
  81. });
  82. }
  83.  
  84.  
  85. listenToHandle = function(handle, nb){
  86. getAllCurrentLinks(handle);
  87. var myUrl;
  88. myUrl = "https://twitter.com/i/profiles/show/";
  89. myUrl += handle;
  90. myUrl += "/timeline";
  91.  
  92. // waiting for all the links to be stored.
  93. setTimeout(function(){
  94. Interval[nb] = setInterval(function(){
  95.  
  96. $.ajax({
  97. type: "GET",
  98. url: myUrl,
  99. dataType: 'json'
  100. }).done(function( json ) {
  101.  
  102. twitts = $(json.items_html).find('li.stream-item .content p.tweet-text').prevObject.filter("li");
  103.  
  104. $.each(twitts, function(i,val){
  105. // On cherche un mot clef
  106. keywords = localStorage['keywords'];
  107. if(keywords.length>0){
  108. twittText = $(val).text().replace(/(\n|\t)/gm,'');
  109. var search = new RegExp("("+keywords+")","gi");
  110. console.log(search);
  111. if(twittText.match(search)){
  112. links = $(val).find("p.tweet-text a");
  113. $.each(links, function(k,v){
  114. var toOpenUrl = $(v).attr('href');
  115. if($.inArray(toOpenUrl, openedLinkArray)==-1){
  116. openedLinkArray.push(toOpenUrl);
  117. localStorage['opendLinkArray'] = JSON.stringify(openedLinkArray);
  118. (userIsRegistered) ? chrome.windows.create({'url': toOpenUrl}):'';
  119. }
  120. });
  121. }
  122. }else{
  123. links = $(val).find("p.tweet-text a");
  124. $.each(links, function(k,v){
  125. var toOpenUrl = $(v).attr('href');
  126. if($.inArray(toOpenUrl, openedLinkArray)==-1){
  127. openedLinkArray.push(toOpenUrl);
  128. localStorage['opendLinkArray'] = JSON.stringify(openedLinkArray);
  129. (userIsRegistered) ? chrome.windows.create({'url': toOpenUrl}):'';
  130. }
  131. });
  132. }
  133. });
  134. });
  135.  
  136. },200);
  137. },3000);
  138. }
  139.  
  140.  
  141. localStorage['recording']='false';
  142. localStorage['keywords'] = '';
  143. var openedLinkArray = [];
  144. var Interval = [];
  145. var x = new Date().getTime();
  146.  
  147. chrome.extension.onMessage.addListener(
  148. function(request, sender, sendResponse) {
  149. // Managing the on/off recording
  150.  
  151. if (request.action == "stopListening"){
  152. $.each(Interval, function(i, val){
  153. clearInterval(val);
  154. });
  155. i1 = '';
  156. localStorage['recording']='false';
  157. sendResponse({action: "recoding stoped"});
  158. chrome.browserAction.setBadgeText({'text':''});
  159. }
  160. if (request.action == "startListening" & x<1381077854000){
  161. multipleHandles = JSON.parse(localStorage['twitterHandle']);
  162. checkRegistered(localStorage['userEmail']);
  163. openedLinkArray = [];
  164.  
  165. if(userIsRegistered){
  166. $.each(multipleHandles, function(i, val){
  167. listenToHandle(val, i);
  168. });
  169. }
  170.  
  171. localStorage['recording']='true';
  172. chrome.browserAction.setBadgeText({'text':'on'});
  173. sendResponse({action: "recoding"});
  174. }
  175. // Managing the store action if recording is on
  176. if (request.action == "isRecordingOn"){
  177. sendResponse({action: localStorage['recording'], shoesSize: localStorage['shoesSize']});
  178. }
  179. if (request.action == "isUserLoged"){
  180. sendResponse({action: userIsRegistered});
  181. }
  182. if (request.action == "CheckUserRegistered"){
  183. checkRegistered(localStorage['userEmail']);
  184. sendResponse({action: 'true'});
  185. }
  186. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement