PageSourceSearch

https://xgm.guru/public/mjs/79df25d1/ui/cookie.js

js xgm.guru collected 2026-09-24 10:34:15 UTC 1,725 bytes, 71 lines download raw bytes

1const Cookie = {
2    /** @type Array.<function> */
3    _onChangeCallbacks: [],
4
5    /**
6     * @param name string
7     * @param value string
8     * @param days number
9     */
10    setItem: (name, value, days) => {
11        let expires = ''
12        if (days) {
13            const date = new Date()
14            date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000)
15            expires = `; expires=${date.toUTCString()}`
16        }
17        document.cookie = `${name}=${value}${expires}; path=/; domain=.`+document.location.hostname
18    },
19
20    /**
21     * @param name
22     * @returns {string|null}
23     */
24    getItem: name => {
25        const nameEQ = `${name}=`
26        const ca = document.cookie.split(';')
27        for (let i = 0; i < ca.length; i++) {
28            let c = ca[i]
29            while (c.charAt(0) === ' ') {
30                c = c.substring(1, c.length)
31            }
32            if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length)
33        }
34        return null
35    },
36
37    /**
38     * @param name string
39     */
40    removeItem: name => {
41        Cookie.setItem(name, '', -1)
42    },
43
44    onChange: (callback) => {
45        Cookie._onChangeCallbacks.push(callback)
46    },
47
48    onChangeRemove: (callback) => {
49        const index = Cookie._onChangeCallbacks.indexOf(callback)
50        if (index !== -1) {
51            Cookie._onChangeCallbacks.splice(index, 1)
52        }
53    },
54
55    _emitOnChange: () => {
56        for(let fn of Cookie._onChangeCallbacks) {
57            fn();
58        }
59    }
60}
61
62let lastCookie = document.cookie;
63window.setInterval(() => {
64    if (lastCookie != document.cookie) {
65        lastCookie = document.cookie;
66        Cookie._emitOnChange()
67    }
68}, 1000);
69
70
71export {Cookie}

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.