@@ -4,34 +4,35 @@ const btn1 = document.querySelector(".btn");
4
4
const textcontainer = document . querySelector ( ".textcontainer" ) ;
5
5
const URL1 = "https://api.monkeylearn.com/v3/classifiers/cl_pi3C7JiL/classify/" ;
6
6
7
- btn1 . addEventListener ( "click" , async ( ) => {
8
-
9
- textcontainer . innerHTML = "" ;
10
- const value = inputBox . value ;
11
- const data = { "data" : [ value ] }
12
-
13
- try {
14
- const res = await fetch ( URL1 , {
15
- method : "POST" ,
16
- mode : "cors" ,
17
- headers : {
18
- "Authorization" : "Token 33c90d17d7c0daf299e0bdec6b5fa02db4443da4" ,
19
- "Content-Type" : "application/json" ,
20
- } ,
21
- body : JSON . stringify ( data )
22
- } ) ;
23
-
24
- const resJson = await res . json ( ) ;
25
- // console.log(resJson[0]);
26
- const finalResult = resJson [ 0 ] ;
27
- textcontainer . innerHTML = `<h3> ${ value } is :<span> ${ finalResult . classifications [ 0 ] . tag_name } </span> </h3>` ;
28
-
29
- inputBox . value = "" ;
30
-
31
- }
32
- catch ( err ) {
33
- console . log ( err ) ;
34
- }
7
+ btn1 . addEventListener ( "click" , async ( ) => {
8
+
9
+ textcontainer . innerHTML = "" ;
10
+ const value = inputBox . value ;
11
+ const data = {
12
+ "data" : [ value ]
13
+ }
14
+
15
+ try {
16
+ const res = await fetch ( URL1 , {
17
+ method : "POST" ,
18
+ mode : "cors" ,
19
+ headers : {
20
+ "Authorization" : "Token 33c90d17d7c0daf299e0bdec6b5fa02db4443da4" ,
21
+ "Content-Type" : "application/json" ,
22
+ } ,
23
+ body : JSON . stringify ( data )
24
+ } ) ;
25
+
26
+ const resJson = await res . json ( ) ;
27
+ // console.log(resJson[0]);
28
+ const finalResult = resJson [ 0 ] ;
29
+ textcontainer . innerHTML = `<h3> ${ value } is :<span> ${ finalResult . classifications [ 0 ] . tag_name } </span> </h3>` ;
30
+
31
+ inputBox . value = "" ;
32
+
33
+ } catch ( err ) {
34
+ console . log ( err ) ;
35
+ }
35
36
36
37
} )
37
38
@@ -42,34 +43,35 @@ const btn2 = document.querySelector(".btn");
42
43
const newscontainer = document . querySelector ( ".newscontainer" ) ;
43
44
const URL2 = "https://api.monkeylearn.com/v3/classifiers/cl_WDyr2Q4F/classify/" ;
44
45
45
- btn2 . addEventListener ( "click" , async ( ) => {
46
-
47
- newscontainer . innerHTML = "" ;
48
- const value = textBox . value ;
49
- const data = { "data" : [ value ] }
50
-
51
- try {
52
- const res = await fetch ( URL2 , {
53
- method : "POST" ,
54
- mode : "cors" ,
55
- headers : {
56
- "Authorization" : "Token 33c90d17d7c0daf299e0bdec6b5fa02db4443da4" ,
57
- "Content-Type" : "application/json" ,
58
- } ,
59
- body : JSON . stringify ( data )
60
- } ) ;
61
-
62
- const resJson = await res . json ( ) ;
63
- console . log ( resJson [ 0 ] ) ;
64
- const finalResult = resJson [ 0 ] ;
65
- newscontainer . innerHTML = `<h3> ${ value } belongs to :<span> ${ finalResult . classifications [ 0 ] . tag_name } </span>category </h3>` ;
66
-
67
- textBox . value = "" ;
68
-
69
- }
70
- catch ( err ) {
71
- console . log ( err ) ;
72
- }
46
+ btn2 . addEventListener ( "click" , async ( ) => {
47
+
48
+ newscontainer . innerHTML = "" ;
49
+ const value = textBox . value ;
50
+ const data = {
51
+ "data" : [ value ]
52
+ }
53
+
54
+ try {
55
+ const res = await fetch ( URL2 , {
56
+ method : "POST" ,
57
+ mode : "cors" ,
58
+ headers : {
59
+ "Authorization" : "Token 33c90d17d7c0daf299e0bdec6b5fa02db4443da4" ,
60
+ "Content-Type" : "application/json" ,
61
+ } ,
62
+ body : JSON . stringify ( data )
63
+ } ) ;
64
+
65
+ const resJson = await res . json ( ) ;
66
+ console . log ( resJson [ 0 ] ) ;
67
+ const finalResult = resJson [ 0 ] ;
68
+ newscontainer . innerHTML = `<h3> ${ value } belongs to :<span> ${ finalResult . classifications [ 0 ] . tag_name } </span>category </h3>` ;
69
+
70
+ textBox . value = "" ;
71
+
72
+ } catch ( err ) {
73
+ console . log ( err ) ;
74
+ }
73
75
74
76
} )
75
77
@@ -80,33 +82,34 @@ const btn3 = document.querySelector(".btn");
80
82
const langcontainer = document . querySelector ( ".langcontainer" ) ;
81
83
const URL3 = "https://api.monkeylearn.com/v3/classifiers/cl_Vay9jh28/classify/" ;
82
84
83
- btn3 . addEventListener ( "click" , async ( ) => {
84
-
85
- langcontainer . innerHTML = "" ;
86
- const value = inputBox1 . value ;
87
- const data = { "data" : [ value ] }
88
-
89
- try {
90
- const res = await fetch ( URL3 , {
91
- method : "POST" ,
92
- mode : "cors" ,
93
- headers : {
94
- "Authorization" : "Token 33c90d17d7c0daf299e0bdec6b5fa02db4443da4" ,
95
- "Content-Type" : "application/json" ,
96
- } ,
97
- body : JSON . stringify ( data )
98
- } ) ;
99
-
100
- const resJson = await res . json ( ) ;
101
- console . log ( resJson [ 0 ] ) ;
102
- const finalResult = resJson [ 0 ] ;
103
- langcontainer . innerHTML = `<h3> ${ value } belongs to :<span> ${ finalResult . classifications [ 0 ] . tag_name } </span>language </h3>` ;
104
-
105
- inputBox1 . value = "" ;
106
-
107
- }
108
- catch ( err ) {
109
- console . log ( err ) ;
110
- }
85
+ btn3 . addEventListener ( "click" , async ( ) => {
86
+
87
+ langcontainer . innerHTML = "" ;
88
+ const value = inputBox1 . value ;
89
+ const data = {
90
+ "data" : [ value ]
91
+ }
92
+
93
+ try {
94
+ const res = await fetch ( URL3 , {
95
+ method : "POST" ,
96
+ mode : "cors" ,
97
+ headers : {
98
+ "Authorization" : "Token 33c90d17d7c0daf299e0bdec6b5fa02db4443da4" ,
99
+ "Content-Type" : "application/json" ,
100
+ } ,
101
+ body : JSON . stringify ( data )
102
+ } ) ;
103
+
104
+ const resJson = await res . json ( ) ;
105
+ console . log ( resJson [ 0 ] ) ;
106
+ const finalResult = resJson [ 0 ] ;
107
+ langcontainer . innerHTML = `<h3> ${ value } belongs to :<span> ${ finalResult . classifications [ 0 ] . tag_name } </span>language </h3>` ;
108
+
109
+ inputBox1 . value = "" ;
110
+
111
+ } catch ( err ) {
112
+ console . log ( err ) ;
113
+ }
111
114
112
115
} )
0 commit comments