javascript - How do I get my redirecting script to add a random suffix to select sites? -


I have a user script that redirects from one list to a random site. (Reference :)

How do I add a random suffix to choose the script, such as the wallbase. CC?

This is my script so far:

  // == Userscript == // @name multipage, multisite slides Type of show // @ match http: //*.breaktaker.com/* // match Http: //*.imageshack.us/* // match http://static.tumblr.com/* // Http://thefriendship.com/images/* // Click on twitter on Twitter http: // failjudge .com / * // match http://wallbase.cc/* // ==/userscript == var UrlsToLoad = ['http://www.breaktaker.com/albums/pictures/animals/BigCat.jpg', 'Http://img375.imageshack.us/img375/8105/bigcats34ye4.jpg', 'http: // Withfriendship.com/images/g/33769/1.jpg ',' http: //static.tumblr Com / yd0wcto / LXQlx109d / bigcats.jpg ',' http://failjudge.com/ ',' http: // Wallbase.cc/wallpaper/ + [lists That number suffix -1-10000000000] "]; Set Timeout (GotRandrmal, 4000); Function GotoRandomURL () {var numUrls = urlsToLoad.length; Var urlIdx = urlsToLoad.indexOf (location.href); If (urlIdx> = 0) {urlsToLoad.splice (urlIdx, 1); NumUrls--; } UrlIdx = Math.floor (Math.random () * numUrls); Location.href = urlsToLoad [urlIdx]; }   

Adding a random suffix, this means that the script should change Checks the site on - it also selects a new URL, therefore, for those sites, we have to check partial matches.

But instead of interpreting each piece, there is a big group O code here;) It should be a little documentary itself. :

  // == userscript == // @name multipage, type of multicite slideshow // // match http: //*.breaktaker Com / * // @ match http: //*.imageshack.us/* // match http://static.tumblr.com/* // http://withfriendship.com/images/* // on Twitter // @ Match http://failjudge.com/* // match http://wallbase.cc/* // ==/userscript == var urlsToLoad = [{url: 'http://www.breaktaker.com/ album / Picture / Beast / Big Cat Jpg ', shoftix: false}, {url:' http://img375.imageshack.us/img375/8105/bigcats34ye4.jpg ', use sophix: incorrect}, {url:' http: //withfriendship.com/ Images / g / 33769 / 1.jpg 'Use Sufix: false}, {url:' http://static.tumblr.com/yd0wcto/LXQlx109d/bigcats.jpg ', use suffix: false}, {Url : Use 'http://failjudge.com/', Sufix: false}, // --- Include everything before the suffix URL, suffix {Url: 'http://wallbase.cc/wallpaper/ ', Use suffix: true}]; / * --- Since many of these sites load large images, so can be a good deal before chrome is normal or its "document end" injection images can be eliminated. Therefore, insure the script after loading: * / window.addEventListener ("load", function () {setTimeout (GotoRandram, 4000);}, false); If (document.readyState == "full") {setTimeout (Gottor andomURL, 4000); } Function GotoRandomURL () {var numUrls = urlsToLoad.length; Var urlIdx = -1; (Var j = numUrls - 1; J & gt; = 0; -J) {if (urlsToLoad [J] .useSuffix) {// --- That URL starts with the specified value var prefChk = new RegExp ('^' URL Tollload [J]. Aral, 'I'); If (prefChk.test (location.href)) {urlIdx = J; break; }} And {if (urlsToLoad [J] .url == location.href) {urlIdx = J; break; }}} If (urlIdx> = 0) {urlsToLoad.splice (urlIdx, 1); NumUrls--; } UrlIdx = Math.floor (Math.random () * numUrls); Var targURL = urlsToLoad [urlIdx] .url; If (urlsToLoad [urlIdx] .useSuffix) {// --- Note: wallbase.cc currently has less than 2 million wallpapers TargURL + = Math.ceil (Math.rendum (* 2000000); } Console.log ('\ n \ n *** \ n', targURL, '\ n *** \ n \ n'); Location.href = targURL; }    

Comments