Skip to content

Instantly share code, notes, and snippets.

@taxilian
Created December 6, 2016 01:39
Show Gist options
  • Save taxilian/685301d6b3696e2b2c2520bb1c676738 to your computer and use it in GitHub Desktop.
Save taxilian/685301d6b3696e2b2c2520bb1c676738 to your computer and use it in GitHub Desktop.
possibly out of date example for using fb2.0
<html>
<head>
<title>FireBreath 2.0 Chrome Extension</title>
</head>
<body>
<script>
var mimetype = "application/x-echotestplugin"
var plugin = null;
function initPlugin() {
//Create a var that basically saves a random number to guarantee an unique identifier for a function. _plugin_ can be any other name.
var callbackFn = "_plugin_" + Math.floor(Math.random() * 100000000);
window[callbackFn] = function (data) {
//Retrieve the wyrmhole factory for later creation
var helper = data.wyrmhole;
setHelper(helper);
}
/*Post a message to the extension, telling it to instantiate a a wyrmhole.
FBDevTeam should be the name of your company inside the plugin configuration. For the echoTestPlugin its FBDevTeam.
callbackFn is the function that will be called once the result of the postMessage is returned.
*/
window.postMessage({firebreath: 'FBDevTeam', callback: callbackFn}, "*");
}
function setHelper(helper) {
//Using the wyrmholeFactory we create a wyrmhole.
helper.create(mimetype).then(
function (wyrmhole) {
//With the created wyrmhole we instantiate a new FireWyrmJS object that will allow us to create the plugin.
var FWJS = window.FireWyrmJS;
//Create pluginFactory that will allow the plugin creation.
window.pluginFactory = new FWJS(wyrmhole);
pluginFactory.create(mimetype, {/*some params*/}).then(
function (pluginObj) {
//Save the plugin to a gloal var for later access
plugin = pluginObj;
},
function (error) {
console.log("An Unexpected Error has ocurred: ", error);
}
)
},
function (error) {
console.log("An Unexpected Error has ocurred: ", error);
}
)
}
function getPluginVersion() {
if(plugin) {
plugin.version.then(
function (data) {
console.log("Plugin Version Is: ", data);
},
function (error) {
console.log("An Unexpected Error has ocurred: ", error);
}
)
}
else {
alert("plugin has not been initialized");
}
}
function getTestString() {
if(plugin) {
plugin.testString.then(
function (data) {
console.log("testString current value is: ", data);
},
function (error) {
console.log("An Unexpected Error has ocurred: ", error);
}
)
}
else {
alert("plugin has not been initialized");
}
}
function getTestString2() {
if(plugin) {
plugin.getProperty("testString").then(
function (data) {
console.log("testString current value is: ", data);
},
function (error) {
console.log("An Unexpected Error has ocurred: ", error);
}
)
}
else {
alert("plugin has not been initialized");
}
}
function setTestString(testString) {
if(plugin) {
plugin.setProperty("testString", testString);
}
else {
alert("plugin has not been initialized");
}
}
function setTestString2(testString) {
if(plugin) {
plugin.testString = testString;
}
else {
alert("plugin has not been initialized");
}
}
</script>
<a href="#" onclick="initPlugin()">Initialize plugin</a><br />
<a href="#" onclick="setTestString('I Like set method 1')">Set testString method 1</a><br />
<a href="#" onclick="setTestString2('I Like set method 2')">Set teststring method 2</a><br />
<a href="#" onclick="getTestString()">Get testString method 1</a><br />
<a href="#" onclick="getTestString2()">Get testString method 1</a><br />
<a href="#" onclick="getPluginVersion()">Get Plugin Version</a><br />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment