MediaWiki:D&DBeyondAPI.js

/* D&DBeyondAPI by Abedecain */ /* Baised on OverwatchAPI by Luqgreg */ $(function{   var $dndbapi = $("div#dndbapi-main");    if ($dndbapi.length) {        console.log("DnDB-Api: Initializing...");		var decMark = defaultValue($dndbapi.data("decmark"), '.');		var decSpaces = defaultValue($dndbapi.data("decspaces"), 2);		var errorMsg = defaultValue($dndbapi.data("error"), "Error: Unknown error occurred! ");		var targetTemplate = $dndbapi.data("template");        var charid = $dndbapi.data("charid");

console.log("DnDB-Api: Downloading player data..."); $.getJSON("https://www.dndbeyond.com/character/13329286" + charid + "/json", function(data) {			console.log("DnDB-Api: Parsing player data...");			var query = "/api.php?action=parse&text=&format=json";			console.log("DnDB-Api: Parsing user template...");			$.getJSON(query, function(data) { var code = data.parse.text['*']; $dndbapi.html(code); });		}).error(function{			console.log("DnDB-Api: Unknown Error");           $dndbapi.html(errorMsg);		}); } });

function defaultValue(variable, defaultVal) { if(variable !== undefined && variable !== null) return variable; return defaultVal; }

function roundFloat(float, decSpaces) { if(decSpaces === 0) return Math.floor(float); return (Math.floor(float * Math.pow(10, decSpaces)) / Math.pow(10, decSpaces)); }