@@ -2,31 +2,59 @@ const logo = "\x1b[91m[Parcoil Cloak]\x1b[0m";
2
2
3
3
const cloak = {
4
4
getFavicon ( ) {
5
- const icons = document . querySelectorAll ( 'link[rel="icon"]' ) ;
6
- return icons . length > 0 ? icons [ 0 ] . href : null ;
5
+ try {
6
+ const icons = document . querySelectorAll ( 'link[rel="icon"]' ) ;
7
+ return icons . length > 0 ? icons [ 0 ] . href : null ;
8
+ } catch ( err ) {
9
+ console . error ( logo , err ) ;
10
+ }
7
11
} ,
8
12
setFavicon ( url ) {
9
- const icons = document . querySelectorAll ( 'link[rel="icon"]' ) ;
10
- icons . forEach ( ( icon ) => ( icon . href = url ) ) ;
11
- localStorage . setItem ( "cloakFavicon" , url ) ;
13
+ try {
14
+ const icons = document . querySelectorAll ( 'link[rel="icon"]' ) ;
15
+ if ( icons . length === 0 ) {
16
+ throw new Error ( "Favicon not found. Try adding rel='icon'" ) ;
17
+ }
18
+ icons . forEach ( ( icon ) => ( icon . href = url ) ) ;
19
+ localStorage . setItem ( "cloakFavicon" , url ) ;
20
+ } catch ( err ) {
21
+ console . error ( logo , err ) ;
22
+ }
12
23
} ,
13
24
getTitle ( ) {
14
- return document . title ;
25
+ try {
26
+ return document . title ;
27
+ } catch ( err ) {
28
+ console . error ( logo , err ) ;
29
+ }
15
30
} ,
16
31
setTitle ( newTitle ) {
17
- document . title = newTitle ;
18
- localStorage . setItem ( "cloakTitle" , newTitle ) ;
32
+ try {
33
+ document . title = newTitle ;
34
+ localStorage . setItem ( "cloakTitle" , newTitle ) ;
35
+ } catch ( err ) {
36
+ console . error ( logo , err ) ;
37
+ }
19
38
} ,
20
39
setCloak ( newTitle , url ) {
21
- this . setTitle ( newTitle ) ;
22
- this . setFavicon ( url ) ;
40
+ try {
41
+ this . setTitle ( newTitle ) ;
42
+ this . setFavicon ( url ) ;
43
+ } catch ( err ) {
44
+ console . error ( logo , err ) ;
45
+ }
23
46
} ,
24
47
init ( ) {
25
48
console . warn (
26
49
logo ,
27
50
"cloak.init() has been deprecated. theres no need to call it anymore."
28
51
) ;
29
52
} ,
53
+ getCloak ( ) {
54
+ const title = localStorage . getItem ( "cloakTitle" ) ;
55
+ const icon = localStorage . getItem ( "cloakFavicon" ) ;
56
+ return [ title , icon ] ;
57
+ } ,
30
58
aboutBlank ( url ) {
31
59
if ( ! url ) url = "https://www.google.com/search?q=how+many+seconds+in+a+day" ;
32
60
const newWindow = window . open ( ) ;
0 commit comments