File tree Expand file tree Collapse file tree 2 files changed +31
-14
lines changed Expand file tree Collapse file tree 2 files changed +31
-14
lines changed Original file line number Diff line number Diff line change
1
+ function getArticle ( url , api_key ) {
1
2
2
- const backup = 'https://article-extractor2.p.rapidapi.com/article/parse?url=https%3A%2F%2Frapidapi.com%2Fblog%2Frapidapi-marketplace-is-now-rapidapi-hub%2F ' ;
3
+ const base_url = 'https://article-extractor2.p.rapidapi.com/article/parse?url=' ;
3
4
4
- function getArticle ( url ) {
5
5
const options = {
6
6
method : 'GET' ,
7
7
headers : {
@@ -10,13 +10,17 @@ function getArticle(url) {
10
10
}
11
11
} ;
12
12
13
- fetch ( url , options )
14
- . then ( response => response . json ( ) )
15
- . then ( response => console . log ( response ) )
16
- . catch ( err => console . error ( err ) ) ;
13
+ fetch ( base_url + url , options )
14
+ . then ( response => {
15
+ if ( response . status !== 200 ) {
16
+ throw new Error ( `Request failed with status ${ response . status } ` ) ;
17
+ }
18
+ return response . json ( ) ;
19
+ } )
20
+ . then ( response => {
21
+ console . log ( response ) ;
22
+ } )
23
+ . catch ( err => {
24
+ console . error ( err ) ;
25
+ } ) ;
17
26
}
18
-
19
- console . log ( 'quick-weblog.js success' ) ;
20
-
21
-
22
- { /* <script type="module" src="<?php echo plugin_dir_url( __FILE__ ); ?>quick-weblog.js"></script> */ }
Original file line number Diff line number Diff line change 12
12
Text Domain: quick-weblog
13
13
*/
14
14
15
- $ api_key = get_option ('quick_weblog_api_key ' , '' );
16
-
17
15
function quick_weblog_form () {
16
+
17
+ $ api_key = get_option ('quick_weblog_api_key ' , '' );
18
+
18
19
?>
19
20
<style>
20
21
#quick-weblog {
@@ -47,13 +48,25 @@ function quick_weblog_form() {
47
48
}
48
49
</style>
49
50
51
+ <script src="<?php echo plugin_dir_url ( __FILE__ ); ?> quick-weblog.js"></script>
52
+
53
+ <script>
54
+ window.addEventListener("DOMContentLoaded", (event) => {
55
+ document.getElementById("quick-test").addEventListener("click", (click_event) => {
56
+ getArticle(document.getElementById("quick-test-input").value, "<?php echo esc_js ( wp_kses ( $ api_key , array () ) ); ?> " );
57
+ });
58
+ });
59
+ </script>
60
+
50
61
<p id="quick-weblog-description">Quickly create a simple Post that highlights an existing news article. Posts include a captioned image and quote with URL citation of original article. All fields are required.</p>
51
62
63
+ <button id="quick-test">Quick Test</button>
64
+
52
65
<div class="card">
53
66
<form id="quick-weblog" method="post" action="<?php echo esc_url ( admin_url ('admin-post.php ' ) ); ?> ">
54
67
<div>
55
68
<label for="url"><?php _e ( 'Post URL ' , 'quick-weblog ' ); ?> </label>
56
- <input type="text" name="url" id="url" required>
69
+ <input id="quick-test-input" type="text" name="url" id="url" required>
57
70
</div>
58
71
59
72
<div>
You can’t perform that action at this time.
0 commit comments