pushrbx icon

Untitled

pushrbx | PRO | 03/01/23 11:50:27 AM UTC | 1 ⭐ | 1070 👁️ | Never ⏰ | []
JavaScript |

2.13 KB

|

None

|

1 👍

/

0 👎

let $ = jQuery;
 
$('#meta_mal_api_button').click(function () {
  let id = $('#meta_mal_api_input').val();
  $('#meta_mal_api_input').val('Processing').attr("disabled", 'disabled');
  fetch('https://api.jikan.moe/v3/anime/' + id)
    .then(res => res.json())
    .then(res => {
      $('#title').val(res.title);
      $('#ak_synonyms').val(res.title_synonyms.join(", "));
      $('#ak_english').val(res.title_english);
      $('#ak_japanese').val(res.title_japanese);
      $('#ak_episodes').val(res.episodes);
      $('#ak_duration').val(res.duration);
      $('#ak_aired').val(res.aired.string);
      $('#ak_source').val(res.source);
      $('#ak_score').val(res.score);
      $('#ak_rating').val(res.rating);
      $('#new-tag-type').val(res.type);
      $('#new-tag-season').val(res.premiered);
      $('#new-tag-status').val(res.status.replace("Currently Airing", "Ongoing"));
      $('#ak_trailer').val(res.trailer_url.replace("?enablejsapi=1&wmode=opaque&autoplay=1", ""));
      $('#ak_producers').val(res.producers.map(item => {
        return item.name
      }).join(", "));
      $('#ak_licensors').val(res.licensors.map(item => {
        return item.name
      }).join(", "));
      $('#new-tag-genres').val(res.genres.map(item => {
        return item.name
      }).join(","));
    });
});
 
$('#new-tag-studios').val(res.studios.map(item => {
        return item.name
      }).join(","));
      var synopsis = "";
      var output = res.synopsis.replace(/\n/g, "<br />");
      synopsis += "" + output + "";
      if (typeof tinyMCE != "undefined") {
        var editor_id = wpActiveEditor;
        if ($('#wp-' + editor_id + '-wrap').hasClass('tmce-active') && tinyMCE.get(editor_id)) {
          tinyMCE.get(editor_id).setContent(synopsis);
        } else {
          $("#content").val(synopsis);
        }
      }
    })
    .then(() => {
      $('#meta_mal_api_input').val('Success').removeAttr("enable", 'enable');
    })
    .catch(e => {
      alert('Error: Please Input Correct MAL ID!');
      $('#meta_mal_api_input').val('').removeAttr("disabled", 'disabled');
      console.log(e)
    });
});
 

Comments