Smith 6744214

2w ago

Hey nostr

Here's a simple script using HTML and JavaScript that does exactly what you’re asking for:

A button that sends users to a random page from a list.

It keeps track of visited pages using localStorage, so it won't repeat until all pages have been shown.


Example:

1. HTML + JavaScript (Single File)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Random Page Redirect</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 100px;
}
button {
padding: 12px 24px;
font-size: 18px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Take Me to a Random Page</h1>
<button onclick="goToRandomPage()">Go!</button>

<script>
const pages = [
"/page1.html",
"/page2.html",
"/page3.html",
// ...add up to 100 pages here
"/page100.html"
];

function goToRandomPage() {
let visited = JSON.parse(localStorage.getItem("visitedPages")) || [];

if (visited.length === pages.length) {
visited = []; // Reset if all pages have been visited
}

// Filter pages that haven't been visited yet
const remainingPages = pages.filter(p => !visited.includes(p));

// Pick a random one
const randomPage = remainingPages[Math.floor(Math.random() * remainingPages.length)];

// Save visit
visited.push(randomPage);
localStorage.setItem("visitedPages", JSON.stringify(visited));

// Redirect
window.location.href = randomPage;
}
</script>
</body>
</html>

How to Use:

1. Replace the pages array with your actual page URLs.


2. Upload this HTML page to your domain, and clicking the button will redirect to a non-repeating random page.



Let me know if you want it to work across different browsers/devices (syncing visits) or if the pages aren't all on the same domain.

@shutosha

Infiltrated through EnterTheNostr.com

See translation

0
0
0
0
0


Do you have thoughts?

Log in to leave a comment


No replies