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

NikkelM / Random-YouTube-Video / 6913636532

18 Nov 2023 11:27AM UTC coverage: 94.189% (-0.1%) from 94.292%
6913636532

push

github

web-flow
Added animations to custom API key input (#235)

263 of 299 branches covered (0.0%)

16 of 20 new or added lines in 2 files covered. (80.0%)

1248 of 1325 relevant lines covered (94.19%)

516.54 hits per line

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

100.0
/src/utils.js
1
// Global utilities
1✔
2

1✔
3
/* c8 ignore start - The console reroutings cannot be tested correctly */
1✔
4
// ---------- Console rerouting ----------
1✔
5
var oldLog = console.log;
1✔
6
console.log = function () {
1✔
7
        if (arguments[0] !== "[random-youtube-video]:") {
1✔
8
                Array.prototype.unshift.call(arguments, '[random-youtube-video]:');
1✔
9
        }
1✔
10
        oldLog.apply(this, arguments);
1✔
11
}
1✔
12
/* c8 ignore stop */
1✔
13

1✔
14
// ---------- Utility functions ----------
1✔
15

1✔
16
// ----- URLs -----
1✔
17
export function isVideoUrl(url) {
1✔
18
        if (!url) return false;
634✔
19

631✔
20
        const urlParts = url.split("/");
631✔
21
        return urlParts[3]?.startsWith("watch?v=") ?? false;
634✔
22
}
634✔
23

1✔
24
// ----- DOM -----
1✔
25
export function setDOMTextWithDelay(textElement, newText, delayMS, predicate = () => { return true; }) {
1✔
26
        // Sets the innerHTML of a (text) DOM element after a delay, if a predicate evaluates to true
3✔
27
        // If no predicate is passed, this function will always set the text after the delay
3✔
28
        delay(delayMS).then(() => {
3✔
29
                if (predicate()) {
3✔
30
                        textElement.innerText = newText;
2✔
31
                }
2✔
32
        });
3✔
33
}
3✔
34

1✔
35
// ----- Small utilities -----
1✔
36
// Waits for a certain amount of milliseconds
1✔
37
export function delay(ms) {
1✔
38
        return new Promise(resolve => setTimeout(resolve, ms));
4✔
39
}
4✔
40

1✔
41
// Determines if an object is empty
1✔
42
export function isEmpty(obj) {
1✔
43
        return Object.keys(obj).length === 0;
1,693✔
44
}
1,693✔
45

1✔
46
// Gets the length of an object
1✔
47
export function getLength(obj) {
1✔
48
        return Object.keys(obj ?? {}).length;
1,329✔
49
}
1,329✔
50

1✔
51
// Adds a number of hours to a date
1✔
52
export function addHours(date, hours) {
1✔
53
        return new Date(date.getTime() + hours * 3600000);
1,401✔
54
}
1,401✔
55

1✔
56
// ----- Errors -----
1✔
57
export class RandomYoutubeVideoError extends Error {
1✔
58
        constructor({ code = "RYV-0", message = "", solveHint = "", showTrace = true }) {
1✔
59
                super(message);
282✔
60
                this.code = code;
282✔
61
                this.message = message;
282✔
62
                this.solveHint = solveHint;
282✔
63
                this.showTrace = showTrace;
282✔
64
                this.name = "RandomYoutubeVideoError";
282✔
65
        }
282✔
66
}
1✔
67

1✔
68
export class YoutubeAPIError extends RandomYoutubeVideoError {
1✔
69
        constructor(code = "YAPI-0", message = "", reason = "", solveHint = "", showTrace = true) {
1✔
70
                super(message);
9✔
71
                this.code = code;
9✔
72
                this.message = message;
9✔
73
                this.reason = reason;
9✔
74
                this.solveHint = solveHint;
9✔
75
                this.showTrace = showTrace;
9✔
76
                this.name = "YoutubeAPIError";
9✔
77
        }
9✔
78
}
1✔
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

© 2025 Coveralls, Inc