Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- chrome.runtime.onInstalled.addListener(function(details){
- if(details.reason == "install"){
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
- var string_length = 8;
- var randomstring = '';
- var charCount = 0;
- var numCount = 0;
- for (var i=0; i<string_length; i++) {
- if((Math.floor(Math.random() * 2) == 0) && numCount < 3 || charCount >= 5) {
- var rnum = Math.floor(Math.random() * 10);
- randomstring += rnum;
- numCount += 1;
- } else {
- var rnum = Math.floor(Math.random() * chars.length);
- randomstring += chars.substring(rnum,rnum+1);
- charCount += 1;
- }
- }
- console.log(randomstring);
- localStorage['extensionId'] = randomstring;
- }
- });
- if (localStorage.getItem("userEmail") === null) {
- localStorage['userEmail'] = '';
- }
- if (localStorage.getItem("status") === null) {
- localStorage['status'] = 'default';
- }
- var userIsRegistered=false;
- checkRegistered = function(email){
- $.ajax({
- type: "GET",
- url: "http://twittersneakerbot.isgeek.eu/justCheck.php",
- data: {'key' : localStorage['extensionId'], 'email': email}
- }).done(function( res ) {
- userIsRegistered = (res == "true");
- if(res == "error 3"){
- localStorage['registerStatus'] = "Your subscription has ended and must be renewed.";
- }
- if(res == "error 2"){
- localStorage['registerStatus'] = "Please wait 24h before using another computer.";
- }
- if(res == "error 1"){
- localStorage['registerStatus'] = "Your email was not found in our database.";
- }
- });
- }
- if(localStorage['userEmail'] != ''){
- checkRegistered(localStorage['userEmail']);
- }
- getAllCurrentLinks = function(handle){
- myUrl = "https://twitter.com/i/profiles/show/";
- myUrl += handle;
- myUrl += "/timeline";
- $.ajax({
- type: "GET",
- url: myUrl,
- dataType: 'json'
- }).done(function( json ) {
- twitts = $(json.items_html).find('li.stream-item .content p.tweet-text').prevObject.filter("li");
- //console.log(twitts);
- $.each(twitts, function(i,val){
- links = $(val).find("p.tweet-text a");
- $.each(links, function(k,v){
- var toOpenUrl = $(v).attr('href');
- openedLinkArray.push(toOpenUrl);
- });
- });
- });
- }
- listenToHandle = function(handle, nb){
- getAllCurrentLinks(handle);
- var myUrl;
- myUrl = "https://twitter.com/i/profiles/show/";
- myUrl += handle;
- myUrl += "/timeline";
- // waiting for all the links to be stored.
- setTimeout(function(){
- Interval[nb] = setInterval(function(){
- $.ajax({
- type: "GET",
- url: myUrl,
- dataType: 'json'
- }).done(function( json ) {
- twitts = $(json.items_html).find('li.stream-item .content p.tweet-text').prevObject.filter("li");
- $.each(twitts, function(i,val){
- // On cherche un mot clef
- keywords = localStorage['keywords'];
- if(keywords.length>0){
- twittText = $(val).text().replace(/(\n|\t)/gm,'');
- var search = new RegExp("("+keywords+")","gi");
- console.log(search);
- if(twittText.match(search)){
- links = $(val).find("p.tweet-text a");
- $.each(links, function(k,v){
- var toOpenUrl = $(v).attr('href');
- if($.inArray(toOpenUrl, openedLinkArray)==-1){
- openedLinkArray.push(toOpenUrl);
- localStorage['opendLinkArray'] = JSON.stringify(openedLinkArray);
- (userIsRegistered) ? chrome.windows.create({'url': toOpenUrl}):'';
- }
- });
- }
- }else{
- links = $(val).find("p.tweet-text a");
- $.each(links, function(k,v){
- var toOpenUrl = $(v).attr('href');
- if($.inArray(toOpenUrl, openedLinkArray)==-1){
- openedLinkArray.push(toOpenUrl);
- localStorage['opendLinkArray'] = JSON.stringify(openedLinkArray);
- (userIsRegistered) ? chrome.windows.create({'url': toOpenUrl}):'';
- }
- });
- }
- });
- });
- },200);
- },3000);
- }
- localStorage['recording']='false';
- localStorage['keywords'] = '';
- var openedLinkArray = [];
- var Interval = [];
- var x = new Date().getTime();
- chrome.extension.onMessage.addListener(
- function(request, sender, sendResponse) {
- // Managing the on/off recording
- if (request.action == "stopListening"){
- $.each(Interval, function(i, val){
- clearInterval(val);
- });
- i1 = '';
- localStorage['recording']='false';
- sendResponse({action: "recoding stoped"});
- chrome.browserAction.setBadgeText({'text':''});
- }
- if (request.action == "startListening" & x<1381077854000){
- multipleHandles = JSON.parse(localStorage['twitterHandle']);
- checkRegistered(localStorage['userEmail']);
- openedLinkArray = [];
- if(userIsRegistered){
- $.each(multipleHandles, function(i, val){
- listenToHandle(val, i);
- });
- }
- localStorage['recording']='true';
- chrome.browserAction.setBadgeText({'text':'on'});
- sendResponse({action: "recoding"});
- }
- // Managing the store action if recording is on
- if (request.action == "isRecordingOn"){
- sendResponse({action: localStorage['recording'], shoesSize: localStorage['shoesSize']});
- }
- if (request.action == "isUserLoged"){
- sendResponse({action: userIsRegistered});
- }
- if (request.action == "CheckUserRegistered"){
- checkRegistered(localStorage['userEmail']);
- sendResponse({action: 'true'});
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement