PageSourceSearch

https://thespamchallengelist.pages.dev/js/util.js

js thespamchallengelist.pages.dev collected 2026-10-03 05:57:58 UTC 1,155 bytes, 38 lines download raw bytes

1// https://stackoverflow.com/questions/3452546/how-do-i-get-the-youtube-video-id-from-a-url
2export function getYoutubeIdFromUrl(url) {
3    return url.match(
4        /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/,
5    )?.[1] ?? '';
6}
7
8export function embed(video) {
9    return `https://www.youtube.com/embed/${getYoutubeIdFromUrl(video)}`;
10}
11
12export function localize(num) {
13    return num.toLocaleString(undefined, { minimumFractionDigits: 3 });
14}
15
16export function getThumbnailFromId(id) {
17    return `https://img.youtube.com/vi/${id}/mqdefault.jpg`;
18}
19
20// https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
21export function shuffle(array) {
22    let currentIndex = array.length, randomIndex;
23
24    // While there remain elements to shuffle.
25    while (currentIndex != 0) {
26        // Pick a remaining element.
27        randomIndex = Math.floor(Math.random() * currentIndex);
28        currentIndex--;
29
30        // And swap it with the current element.
31        [array[currentIndex], array[randomIndex]] = [
32            array[randomIndex],
33            array[currentIndex],
34        ];
35    }
36
37    return array;
38}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.