Skip to content

Instantly share code, notes, and snippets.

@ariakm25
Last active August 1, 2024 17:30
Show Gist options
  • Save ariakm25/57caaeb5443a08374d110e5c86becd17 to your computer and use it in GitHub Desktop.
Save ariakm25/57caaeb5443a08374d110e5c86becd17 to your computer and use it in GitHub Desktop.
Jikan.me client for wordpress (meta-box)
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("disabled", 'disabled');
})
.catch(e => {
alert('Error: Please Input Correct MAL ID!');
$('#meta_mal_api_input').val('').removeAttr("disabled", 'disabled');
console.log(e)
});
})
@Adytm404
Copy link

can u fix this with v4 api?

@AlbEagle
Copy link

AlbEagle commented Mar 1, 2023

hello, me too i need this for v4 help pls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment