Sometimes I feel like I want to use some sort of URL which redirects to a random site on the Stack Exchange network for the purpose of discovering new, interesting and useful Stack Exchange network sites.
-
2It should be easy enough to create that... alternatively, just pick something from the Hot Network Questions.– S.L. BarthApr 2, 2014 at 9:32
-
Code highlight on Meta is pretty minor, no need to edit just to add it. Thanks for the efforts though!– Shadow Wizard Says No More WarApr 2, 2014 at 11:17
-
@ShadowWizard sorry I just love when everything works 100% correctly. though I will learn my lesson now, thank you for your effort too, sheriff -)– Bruno GelbApr 2, 2014 at 11:20
-
Actually I approved your latest edit, two others deemed it too minor.– Shadow Wizard Says No More WarApr 2, 2014 at 11:23
-
@ShadowWizard ye, I've already read the history of that edit. -)– Bruno GelbApr 2, 2014 at 11:25
3 Answers
Taking Sklivvz's advice I built a jsfiddle that will redirect you automagically to a random site.
Since the API call is "heavy" and limited, please don't run the below code too many times.
Let's cut to the slack!
The Random Stack Exchange™ Site Jumper Turbo is here:
var jumperDiv = $('#Jumper');
jumperDiv.html('Loading, please wait...');
$.getJSON("https://api.stackexchange.com/2.2/sites?page=1&pagesize=999&?jsonp=wrapperFunc", function(data) {
$('#RemainingQuota').html('Quota remaining: ' + data.quota_remaining + '<hr />');
var allSites = [];
for (var i = 0; i < data.items.length; i++) {
//don't take meta sites
if (data.items[i]["site_state"] != "linked_meta")
allSites.push(data.items[i]["site_url"]);
}
Jump(allSites);
});
function Jump(allSites) {
var randSiteUrl = allSites[parseInt(Math.random() * allSites.length)];
jumperDiv.html('<a href="' + randSiteUrl + '">Jump to</a> ' + randSiteUrl + '!');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="RemainingQuota"></div>
<div id="Jumper"></div>
-
wow! :) how to read the code of this jsfiddle? It auto-runs every time I click the link Apr 2, 2014 at 11:00
-
-
-
@Pat yeah, weird. Maybe like imgur, they remove inactive fiddles. Using stack snippet instead now. Nov 7, 2016 at 15:12
-
1
-
-
1@TheBitByte yeah, I don't filter the list... but I should. Thanks! Nov 7, 2016 at 15:35
-
What about grabbing all the sitenames until the quota is finished, filtering meta sites out, and having a "random site" button that grabs sites from that internal list and displays them? Nov 7, 2016 at 15:37
-
Or, a crazier solution, manually grab the names from the HTML of stackexchange.com/sites. Not sure how reliable that solution would be if the page changes or new sites are added to it, though. Nov 7, 2016 at 15:40
-
@TheBitByte can't do those, it's client side and can't read remote pages, only the API which provides JSONP. Nov 7, 2016 at 15:42
-
@TheBitByte that's what I was referring to, can't read the HTML of stackexchange.com/sites Nov 7, 2016 at 15:44
-
You mean stack snippets can't access remote pages? I guess maybe they're sandboxed or something. Nov 7, 2016 at 15:45
-
1@TheBitByte any client side JavaScript code is restricted to read contents only of the same domain as the server where it sits, yes. Stack Snippets, jsfiddle, all of them. :) Nov 7, 2016 at 15:46
You can get the list of sites here as JSON:
http://api.stackexchange.com/docs/sites#filter=default&run=true
(call without help page: http://api.stackexchange.com/2.2/sites)
From that, it should be a Javascript one liner...
$.get("http://api.stackexchange.com/2.2/sites?pagesize=1000", function(data) {
console.log(data.items[Math.floor(Math.random()*data.items.length)]["site_url"]);
});
Well there is no such URL as of now, but the closest you can get to it is the All Sites url. You can randomly select a StackExchange site.
* To make it really very random, you can click on a random space in that page by closing your eyes ;)
-
perhaps I will write some js code for getting random url from this page. Thx! Apr 2, 2014 at 9:37
-
-
btw sir what's that letters in your nickname? Auto completion (after at sign) doesn’t seems to work on you, weird o_0 Apr 2, 2014 at 9:40
-
@aspect_mkn8rd - Since this is my post, you need not refer me using the
@
symbol. SE has handled that. And regarding the special characters, well those are some unicode characters I picked up from the internet and on any other post which is not mine, but I've commented, you can very well use the@
symbol to address me. It works :)– RahulApr 2, 2014 at 9:42 -
1@aspect_mkn8rd now you can use
@
, when you will press it the weird name will auto appear as its first character is special. Apr 2, 2014 at 11:07