• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AJGranowski / reddit-expanded-community-filter-userscript / 10765121853

09 Sep 2024 01:52AM UTC coverage: 90.951%. Remained the same
10765121853

push

github

web-flow
Bump rollup-plugin-userscript from 0.3.2 to 0.3.4 (#348)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

78 of 96 branches covered (81.25%)

Branch coverage included in aggregate %.

314 of 335 relevant lines covered (93.73%)

5.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/web/Fetch.ts
1
import { AsyncXMLHttpRequest } from "../userscript/AsyncXMLHttpRequest";
2✔
2
import { MutedSubredditsResponse } from "./@types/MutedSubredditsResponse";
3

4
/**
5
 * Specialized web request class.
6
 */
7
class Fetch {
8
    private readonly asyncXMLHttpRequest: AsyncXMLHttpRequest;
9
    private readonly domParser: DOMParser;
10

11
    constructor() {
12
        this.asyncXMLHttpRequest = this.asyncXMLHttpRequestSupplier();
8✔
13
        this.domParser = this.domParserSupplier();
8✔
14
    }
15

16
    /**
17
     * Request an HTML document.
18
     */
19
    fetchDocument(url: string): Promise<Document> {
20
        const request: Tampermonkey.Request = {
3✔
21
            method: "GET",
22
            url: url
23
        };
24

25
        return this.asyncXMLHttpRequest.asyncXMLHttpRequest(request, (response) => response.status >= 200 && response.status < 300)
3✔
26
            .then((response) => {
27
                return this.domParser.parseFromString(response.responseText, "text/html");
2✔
28
            });
29
    }
30

31
    /**
32
     * Request the list of muted subreddits for this account.
33
     * The access token can be retrieved by plugging various sources into the AccessToken class.
34
     */
35
    fetchMutedSubreddits(accessToken: string): Promise<string[]> {
36
        const request: Tampermonkey.Request = {
5✔
37
            data: JSON.stringify({
38
                "id": "c09ff0d041c1" // Muted subreddits ID.
39
            }),
40
            headers: {
41
                "Content-Type": "application/json",
42
                "Authorization": `Bearer ${accessToken}`
43
            },
44
            method: "POST",
45
            url: "https://gql.reddit.com/"
46
        };
47

48
        return this.asyncXMLHttpRequest.asyncXMLHttpRequest(request, (response) => response.status >= 200 && response.status < 300)
5✔
49
            .then((response) => {
50
                const responseJSON = JSON.parse(response.responseText) as MutedSubredditsResponse;
4✔
51
                if (responseJSON.data.identity == null) {
4✔
52
                    throw new Error("User is logged out.");
1✔
53
                }
54

55
                return responseJSON.data.identity.mutedSubreddits.edges
3✔
56
                    .map((x) => x.node.name);
6✔
57
            });
58
    }
59

60
    /* istanbul ignore next */
61
    protected asyncXMLHttpRequestSupplier(): AsyncXMLHttpRequest {
62
        return new AsyncXMLHttpRequest();
63
    }
64

65
    /* istanbul ignore next */
66
    protected domParserSupplier(): DOMParser {
67
        return new DOMParser();
68
    }
69
}
70

71
export { Fetch };
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc