We're in the process of updating the documentation for188BET靠谱吗Zotero 5.0.Some documentation may be outdated in the meantime.Thanks for your understanding.
188BET靠谱吗A Sample Zotero Plugin
188BET靠谱吗To help you get started creating Zotero plugins, we've created a simple Hello World plugin that demonstrates how to access Zotero from an external extension.See188BET靠谱吗Interacting with Zotero from Within Firefoxfor more information.
You can obtain theHello World code from github.
For more information on the basic elements and layout of a Firefox extension, see theXUL School Tutorialin the Mozilla Developer Center.
The most important code is in188BET靠谱吗chrome://helloworldzotero/content/hello.js188BET靠谱吗, which defines a method to insert a new item into the Zotero database and registers a callback function with the Zotero Notifier to receive a notification when an item is modified.The script is loaded by188BET靠谱吗chrome://helloworldzotero/content/include.js, which is included into the main overlay by188BET靠谱吗chrome/content/helloworldzotero/overlay.xul.188BET靠谱吗The latter also adds a menu item to the Zotero Actions menu.
188BET靠谱吗Once installed, the plugin will display an alert whenever an item is added, modified or deleted in Zotero.(You'll probably want your own plugin to do something slightly less annoying.)
188BET靠谱吗chrome/content/helloworldzotero/hello.js:
188BET靠谱吗Note: This file is loaded by chrome://helloworldzotero/content/include.js, which makes sure the Zotero.HelloWorldZotero object is only created once.
188BET靠谱吗Zotero.188BET靠谱吗HelloWorldZotero={DB:null,init:function(){188BET靠谱吗// Connect to (and create, if necessary) helloworld.sqlite in the Zotero directorythis.DB=new188BET靠谱吗Zotero.DBConnection('helloworld');if(!this.DB.tableExists('changes')){this.DB.query("CREATE TABLE changes (num INT)");this.DB.query("INSERT INTO changes VALUES (0)");}188BET靠谱吗// Register the callback in Zotero as an item observervarnotifierID=188BET靠谱吗Zotero.Notifier.registerObserver(this.notifierCallback,['item']);// Unregister callback when the window closes (important to avoid a memory leak)window.addEventListener('unload',function(e){188BET靠谱吗Zotero.Notifier.unregisterObserver(notifierID);},false);},insertHello:function(){vardata={title:188BET靠谱吗"Zotero",company:"Center for History and New Media",creators:[['Dan','Stillman','programmer'],['Simon','Kornblith','programmer']],version:'1.0.1',company:'Center for History and New Media',place:'Fairfax, VA',url:188BET靠谱吗'//www.brodersterzo.com'};188BET靠谱吗Zotero.Items.add('computerProgram',data);188BET靠谱吗// returns a Zotero.Item instance},// Callback implementing the notify() method to pass to the NotifiernotifierCallback:{notify:function(event,type,ids,extraData){if(event=='add'||event=='modify'||event=='delete'){// Increment a counter every time an item is changed188BET靠谱吗Zotero.188BET靠谱吗HelloWorldZotero.DB.query("UPDATE changes SET num = num + 1");if(event!='delete'){// Retrieve the added/modified items as Item objectsvaritems=188BET靠谱吗Zotero.Items.get(ids);}else{varitems=extraData;}// Loop through array of items and grab titlesvartitles=[];foreach(variteminitems){// For deleted items, get title from passed dataif(event=='delete'){titles.push(item.old.title?item.old.title:'[No title]');}else{titles.push(item.getField('title'));}}if(!titles.length){return;}// Get the localized string for the notification message and// append the titles of the changed itemsvarstringName='notification.item'+(titles.length==1?'':'s');switch(event){case'add':stringName+="Added";break;case'modify':stringName+="Modified";break;case'delete':stringName+="Deleted";break;}varstr=document.getElementById(188BET靠谱吗'hello-world-zotero-strings').getFormattedString(stringName,[titles.length])+":\n\n"+titles.join("\n");}alert(str);}}};// Initialize the pluginwindow.addEventListener('load',function(e){188BET靠谱吗Zotero.188BET靠谱吗HelloWorldZotero.init();},false);