편집 요약 없음 |
편집 요약 없음 |
||
5번째 줄: | 5번째 줄: | ||
function randomArray(n, max) { | function randomArray(n, max) { | ||
var arr = []; | var arr = []; | ||
if (n > max) n = max | if (n > max) n = max; | ||
while (arr.length < n) { | while (arr.length < n) { | ||
var r = Math.floor(Math.random() * max); | var r = Math.floor(Math.random() * max); | ||
14번째 줄: | 14번째 줄: | ||
var limit = parseInt($(this).data('limit')); | var limit = parseInt($(this).data('limit')); | ||
var $items = $(this).find('.libre-tab-item'); | var $items = $(this).find('.libre-tab-item'); | ||
var activeIds = randomArray(limit, $items.length) | var activeIds = randomArray(limit, $items.length); | ||
console.log(activeIds); | |||
$items.each(function (index) { | $items.each(function (index) { | ||
if (activeIds.indexOf(index) !== -1) { | if (activeIds.indexOf(index) !== -1) { | ||
$(this).addClass('libre-random-item-active') | $(this).addClass('libre-random-item-active'); | ||
} | } | ||
}) | }); | ||
}) | }); | ||
}); | }); |
2021년 8월 23일 (월) 15:56 판
mw.loader.load('//librewiki.net/index.php?title=사용자:Utolee90/status.js&action=raw&ctype=text/javascript');
$(function () {
// generate n random integers from 0 to max - 1
function randomArray(n, max) {
var arr = [];
if (n > max) n = max;
while (arr.length < n) {
var r = Math.floor(Math.random() * max);
if (arr.indexOf(r) === -1) arr.push(r);
}
}
$('.libre-random').each(function () {
var limit = parseInt($(this).data('limit'));
var $items = $(this).find('.libre-tab-item');
var activeIds = randomArray(limit, $items.length);
console.log(activeIds);
$items.each(function (index) {
if (activeIds.indexOf(index) !== -1) {
$(this).addClass('libre-random-item-active');
}
});
});
});