const SCHOLAR_CONFIG = { GUID: 'scholar@chnm', DB_FILE: 'scholar.sqlite', DB_VERSION: 10, // must match version at top of schema.sql DB_REBUILD: false, // erase DB and recreate from schema DEBUG_LOGGING: true, DEBUG_TO_CONSOLE: true // dump debug messages to console rather than (much slower) Debug Logger }; /* * Core functions */ var Scholar = new function(){ var _initialized = false this.testString = 'Sidebar is not registered'; this.LocalizedStrings; this.init = init; this.debug = debug; this.varDump = varDump; this.flattenArguments = flattenArguments; this.join = join; this.Hash = Hash; /* * Initialize the extension */ function init(){ this.LocalizedStrings = document.getElementById('scholar-strings'); if (!_initialized){ Scholar.DB.updateSchema(); _initialized = true; return true; } return false; } /* * Debug logging function * * Uses DebugLogger extension available from http://mozmonkey.com/debuglogger/ * if available, otherwise the console (in which case boolean browser.dom.window.dump.enabled * must be created and set to true in about:config) * * Defaults to log level 3 if level not provided */ function debug(message, level) { if (!SCHOLAR_CONFIG['DEBUG_LOGGING']){ return false; } if (!level){ level = 3; } if (!SCHOLAR_CONFIG['DEBUG_TO_CONSOLE']){ try { var logManager = Components.classes["@mozmonkey.com/debuglogger/manager;1"] .getService(Components.interfaces.nsIDebugLoggerManager); var logger = logManager.registerLogger("Firefox Scholar"); } catch (e){} } if (logger){ logger.log(level, message); } else { dump('scholar(' + level + '): ' + message + "\n\n"); } return true; } /** * PHP var_dump equivalent for JS * * Adapted from http://binnyva.blogspot.com/2005/10/dump-function-javascript-equivalent-of.html */ function varDump(arr,level) { var dumped_text = ""; if (!level){ level = 0; } // The padding given at the beginning of the line. var level_padding = ""; for (var j=0;j function(...){...} \n"; } else { dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; } } } } else { // Stings/Chars/Numbers etc. dumped_text = "===>"+arr+"<===("+typeof(arr)+")"; } return dumped_text; } /* * Flattens mixed arrays/values in a passed _arguments_ object and returns * an array of values -- allows for functions to accept both arrays of * values and/or an arbitrary number of individual values */ function flattenArguments(args){ var returns = new Array(); for (var i=0; i