File size: 1,026 Bytes
611cad7
f103e46
611cad7
 
a912e64
611cad7
 
a912e64
611cad7
 
a912e64
611cad7
 
a912e64
611cad7
a912e64
611cad7
 
a912e64
 
611cad7
f103e46
611cad7
 
a912e64
611cad7
 
a912e64
611cad7
 
a912e64
611cad7
1f90b4e
 
611cad7
a912e64
611cad7
 
a912e64
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
 * Navigates to the next page by incrementing the current page number in the URL query string.
 * @returns {void}
 */
function navigate_forward() {
    const url = new URL(window.location);
    const searchParams = url.searchParams;

    let q = searchParams.get('q');
    let page = parseInt(searchParams.get('page'));

    if (isNaN(page)) {
        page = 1;
    } else {
        page++;
    }

    window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
}

/**
 * Navigates to the previous page by decrementing the current page number in the URL query string.
 * @returns {void}
 */
function navigate_backward() {
    const url = new URL(window.location);
    const searchParams = url.searchParams;

    let q = searchParams.get('q');
    let page = parseInt(searchParams.get('page'));

    if (isNaN(page)) {
        page = 0;
    } else if (page > 0) {
        page--;
    }

    window.location.href = `${url.origin}${url.pathname}?q=${encodeURIComponent(q)}&page=${page}`;
}