kevquirk/512kb.club

Random site button?

kevquirk opened this issue · 5 comments

Just had an idea, what about adding a button to the top of the page so that people can visit a random site from the club?

Haven't looked into how to do it, but I'm pretty sure it would be simple.

Thoughts?

Something like what "Weird Wide Webring" does?

It would be a cool feature, and would increase activity on people's sites.

I'll also start looking at away. I believe it would require some Javascript

Exactly like WW Web Ring. 😊

That project is open source, so I'm sure we can probably repurpose the randomisation code - I'm sure Jack won't mind.

I've no objections to introducing a little JS as long as it respects the visitors.

Well, it depends on how you want the array to be. This can also be solved with PHP. Both methods below has been tested and do work.

JavaScript

$('body').on('click', 'a#random', function() {
	var items = [
		'test',
		'hej',
		'haha'
	];

	var item = items[Math.floor(Math.random() * items.length)];
	console.log(item);
});

PHP

$items = [
	'test',
	'hej',
	'haha'
];

$item = array_rand($items);
echo $items[$item];

Why not use Netlify functions? That wouldn't require any JS in the frontend, just a link.

This has been merged in #513