1
- function add_bookmark_button ( ) {
2
- var bookmarkButton = createElement ( "button" , { class : "bookmark-button" } ) ;
1
+ function createBookmarkButton ( ) {
2
+ const bookmarkButton = createElement ( "button" , { class : "bookmark-button" } ) ;
3
3
bookmarkButton . innerHTML =
4
4
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M12 .587l3.668 7.568 8.332 1.151-6.064 5.828 1.48 8.279-7.416-3.967-7.417 3.967 1.481-8.279-6.064-5.828 8.332-1.151z"/></svg>' ;
5
5
6
- document . querySelector ( ".name" ) . append ( bookmarkButton ) ;
7
-
8
6
bookmarkButton . addEventListener ( "click" , ( ) => {
9
7
if ( bookmarkButton . classList . contains ( "yellow-bookmark-button" ) ) {
10
8
bookmarkButton . classList . remove ( "yellow-bookmark-button" ) ;
@@ -27,18 +25,30 @@ function add_bookmark_button() {
27
25
payload : window . location . pathname . split ( "/" ) [ 1 ] . substring ( 1 ) ,
28
26
} ,
29
27
( response ) => {
30
- console . log ( response . is_bookmarked ) ;
31
28
if ( response . is_bookmarked ) {
32
29
bookmarkButton . classList . add ( "yellow-bookmark-button" ) ;
33
30
} else {
34
31
bookmarkButton . classList . remove ( "yellow-bookmark-button" ) ;
35
32
}
36
33
}
37
34
) ;
35
+
36
+ return bookmarkButton ;
38
37
}
39
38
40
- console . log ( document . querySelector ( ".bookmark-button" ) ) ;
41
39
if ( document . querySelector ( ".bookmark-button" ) == null ) {
42
- add_bookmark_button ( ) ;
43
- console . log ( "SUCCES add bookmark button" ) ;
40
+ var blogProfile = document . querySelector ( "div > div.name" ) ;
41
+ console . log ( blogProfile ) ;
42
+ if ( blogProfile != null && blogProfile != undefined ) {
43
+ var bookmarkButton = createBookmarkButton ( ) ;
44
+ blogProfile . append ( bookmarkButton ) ;
45
+ console . log ( "SUCCES add bookmark button in blog profile" ) ;
46
+ }
47
+
48
+ var username = document . querySelector ( "div.information > span.username" ) ;
49
+ if ( username != null && username != undefined ) {
50
+ var bookmarkButton = createBookmarkButton ( ) ;
51
+ username . after ( bookmarkButton ) ;
52
+ console . log ( "SUCCES add bookmark button in top of post" ) ;
53
+ }
44
54
}
0 commit comments