Skip to content

Instantly share code, notes, and snippets.

(function() {
const links = [
{ url: "https://site-A.com", w: 60 },
{ url: "https://site-B.com", w: 25 },
{ url: "https://site-C.com", w: 15 }
];
let r = Math.random() * 100, c = 0, el = document.getElementById('rotator');
if (el) {
let selected = links.find(l => (c += l.w) >= r) || links[0];
el.href = selected.url;