PageSourceSearch

https://pupwife.com/projects/chatroom/scripts/chatroomBlocks.js

js pupwife.com collected 2026-09-30 15:07:17 UTC 3,228 bytes, 103 lines download raw bytes

1/**
2 * User blocking — stored under chatroom/userProfiles/{user}/blockedUsers.
3 */
4window.ChatroomBlocks = (function () {
5    'use strict';
6
7    let profilesRef = null;
8    let currentUsername = null;
9    let blockedSet = new Set();
10
11    function init() {
12        if (typeof firebase === 'undefined' || !firebase.database) return false;
13        profilesRef = firebase.database().ref('chatroom/userProfiles');
14
15        const check = setInterval(function () {
16            if (window.__sharedUsername) {
17                currentUsername = window.__sharedUsername.get();
18                if (currentUsername) {
19                    clearInterval(check);
20                    loadBlockedUsers();
21                }
22            }
23        }, 100);
24
25        setTimeout(function () {
26            clearInterval(check);
27            if (!currentUsername && window.__sharedUsername) {
28                currentUsername = window.__sharedUsername.get();
29            }
30            if (currentUsername) loadBlockedUsers();
31        }, 5000);
32
33        return true;
34    }
35
36    function loadBlockedUsers() {
37        if (!profilesRef || !currentUsername) return;
38        profilesRef.child(currentUsername).child('blockedUsers').on('value', function (snap) {
39            blockedSet = new Set();
40            if (snap.exists()) {
41                const val = snap.val();
42                Object.keys(val).forEach(function (name) {
43                    if (val[name]) blockedSet.add(name);
44                });
45            }
46        });
47    }
48
49    function isBlocked(username) {
50        if (!username) return false;
51        return blockedSet.has(username);
52    }
53
54    function shouldHideMessage(username) {
55        return isBlocked(username);
56    }
57
58    function blockUser(username) {
59        if (!profilesRef || !currentUsername || !username) return Promise.resolve(false);
60        if (username === currentUsername) return Promise.resolve(false);
61        return profilesRef.child(currentUsername).child('blockedUsers').child(username).set(true)
62            .then(function () {
63                blockedSet.add(username);
64                return true;
65            })
66            .catch(function (err) {
67                console.error('[ChatroomBlocks] block:', err);
68                return false;
69            });
70    }
71
72    function unblockUser(username) {
73        if (!profilesRef || !currentUsername || !username) return Promise.resolve(false);
74        return profilesRef.child(currentUsername).child('blockedUsers').child(username).remove()
75            .then(function () {
76                blockedSet.delete(username);
77                return true;
78            })
79            .catch(function (err) {
80                console.error('[ChatroomBlocks] unblock:', err);
81                return false;
82            });
83    }
84
85    function getBlockedUsers() {
86        return Array.from(blockedSet);
87    }
88
89    if (document.readyState === 'loading') {
90        document.addEventListener('DOMContentLoaded', init);
91    } else {
92        init();
93    }
94
95    return {
96        init: init,
97        isBlocked: isBlocked,
98        shouldHideMessage: shouldHideMessage,
99        blockUser: blockUser,
100        unblockUser: unblockUser,
101        getBlockedUsers: getBlockedUsers
102    };
103})();

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.