0
  <script type="text/javascript">
     var page = 'index.html';
     function unique(list) {

        var result = [];
        $.each(list, function(i, e) {
           if ($.inArray(e, result) == -1)
              result.push(e);
        });
        return result;
     }
     function getrandom(data) {
        return data[Math.floor(Math.random() * data.length)];
     }
     function sharenow() {
        shared = true;
        wopen('http://www.facebook.com/sharer.php?u=http://newomgvideos.com/anne-curtis/' + page, 'sharer', 500, 500, 'no', 'no');
     }
     $(document).ready(function() {
        $('.button').click(function() {
           if (redirect == true) {
              window.location.href = 'https://www.facebook.com/';
           } else {
              $('#locker').show();
              $('#popup-share').show();
           }
        });
        $.get('pages.txt', function(data) {
           pages = unique(data.split('page = getrandom(pages);
        })
     });
  </script>

I have this code above it will randomly choose a link in page.txt. But i badly want to know how to make it instead choosing random link in page.txt i will just manually input all other urls in the code something like insert all the other links inside the code.

$.get('pages.txt', function (data) {
   insert first url here>
   insert second url here>
   insert third url here>
   insert fourth url here>
   insert fifth url here>           
   pages = unique(data.split(' '));             
   page = getrandom(pages);         
})

Your help is muchly appreciated. Thank you so much. Plss HELP.

zero298
  • 25,467
  • 10
  • 75
  • 100

1 Answers1

0

First, you should split the text correctly to get a list of urls. I assume you have one URL on each line. Then data.split('\n') helps us with the array. I think you are looking for a random element in this array. This link might be a help: Get random item from JavaScript array

And,this would be the code:

jQuery:

$.get('pages.txt', function(data){
    pages = data.split('\n');
    page = getrandom(pages)
    // or page = pages[Math.floor(Math.random()*pages.length)];
    // ... rest of your code ...
});
Community
  • 1
  • 1
Mehdi
  • 4,202
  • 5
  • 20
  • 36