// LICENSE : MIT "use strict"; require(['gitbook'], function (gitbook) { function addBeforeHeader(element) { jQuery('.book-header > h1').before(element) } function createButton({ user, repo, type, size, width, height, count }) { var extraParam = type === "watch" ? "&v=2" : ""; return ` `; } function insertGitHubLink({ user, repo, types, size, width, height, count }) { types.reverse().forEach(type => { var elementString = createButton({ user, repo, type, size, width, height, count }); addBeforeHeader(elementString); }); } function init(config) { var repoPath = config.repo; var [user, repo] = repoPath.split("/"); if (repoPath == null) { console.log("Should set github.repo"); return; } var types = config.types || ["star", "watch"]; var size = config.size || "large"; var width = config.width || (size === "large" ? "150" : "100"); var height = config.height || (size === "large" ? "30" : "20"); var count = typeof config.count === "undefined" ? "true" : "false"; insertGitHubLink({ user, repo, types, size, width, height, count }); } // injected by html hook function getPluginConfig() { return window["gitbook-plugin-github-buttons"]; } // make sure configuration gets injected gitbook.events.bind('start', function (e, config) { window["gitbook-plugin-github-buttons"] = config["github-buttons"]; }); gitbook.events.bind('page.change', function () { init(getPluginConfig()); }); });