Mercurial > google_bookmarks_incsearch
changeset 0:c47ec96326ad
initial import
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 15 Aug 2008 01:57:59 +0900 |
parents | |
children | b090002b1814 |
files | Makefile chrome.manifest chrome/content/base.css chrome/content/database.js chrome/content/glayer.css chrome/content/glayer.js chrome/content/glayer_ex.js chrome/content/googlebookmarks.js chrome/content/help.gif chrome/content/incsearch.js chrome/content/init.js chrome/content/loader.gif chrome/content/loader.js chrome/content/overlay.xul chrome/content/setting.gif chrome/content/sync.gif chrome/content/user-extension-sample.js chrome/content/user-sample.css chrome/content/view.html chrome/skin/icon-large.png chrome/skin/icon-medium.png chrome/skin/icon-small.png chrome/skin/toolbar-button.css install.rdf |
diffstat | 23 files changed, 2460 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,14 @@ +app=googlebookmarks_incsearch +vers=_2_0_0 + +all: + cd chrome; zip -r $(app).jar content skin + zip -r $(app)$(vers).xpi chrome/$(app).jar chrome.manifest install.rdf + +clean: + rm -f $(app)$(vers).xpi + rm -f chrome/$(app).jar + +mostlyclean: clean + find . -name "*~" -exec rm {} ';' + find . -name "#*#" -exec rm {} ';'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome.manifest Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,6 @@ +content googlebookmarks_incsearch jar:chrome/googlebookmarks_incsearch.jar!/content/ +skin googlebookmarks_incsearch classic/1.0 jar:chrome/googlebookmarks_incsearch.jar!/skin/ + +overlay chrome://browser/content/browser.xul chrome://googlebookmarks_incsearch/content/overlay.xul +style chrome://browser/content/browser.xul chrome://googlebookmarks_incsearch/skin/toolbar-button.css +style chrome://global/content/customizeToolbar.xul chrome://googlebookmarks_incsearch/skin/toolbar-button.css
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/base.css Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,153 @@ +body, div, +dl, dt, dd, ul, ol, li, +h1, h2, h3, h4, h5, h6, +pre, p, blockquote, form, th, td { + font-style: normal; + font-weight: normal; + margin: 0; + padding: 0; +} + +body { + font-family: Verdana, Arial, sans-serif; + line-height:1.3; + background-color: #FFFFFF; + margin: 5px; +} + +span#title { + margin: 0px 5px 0px 0px; +} + +table { + width: 96%; + margin: 5px 10px 5px 10px; + border-collapse: collapse; +} + +th { + padding: 2px 4px 2px 4px; + border: solid 1px #737373; + text-align: left; + font-weight: normal; + background-color: #CFCFCF; + font-size: 80%; +} + +td { + padding: 2px 4px 2px 4px; + border: solid 1px #737373; + background-color: #FFFFFF; + font-size: 80%; +} + +tr > th:first-child { + padding: 1px; +} + +tr > td:first-child { + padding: 1px; +} + +tr.focus > td { + background-color: #EFEFEF; +} + +tr.focus > td:first-child { + background-color: #737373; +} + +td p { + padding: 4px 2px 2px 6px; +} + +strong { + font-weight: normal; +} +strong.high1 { + background-color: #FFFF99 +} +strong.high2 { + background-color: #FFDFFF; +} +strong.high3 { + background-color: #CCFF99; +} +strong.high4 { + background-color: #FFCC99; +} + +img { + vertical-align: middle; + border: none; +} + +.buttons { + text-align: center; + +} +#footer { + clear: both; + padding: 5px 5px 5px 10px; + background-color: #FFFFFF; + font-size: 80%; + color: #000000; +} + +#option { + padding: 0px 2px 0px 2px; + font-size: 80%; +} +#option a { + padding: 0px 2px 0px 2px; +} + +#status { + padding: 4px 2px 0px 20px; + font-size: 80%; +} + +#viewArea { + clear: both; +} + +#viewHeader { + padding-top: 5px; + width: 97%; +} +#viewFooter { + width: 97%; +} + +#pageLinkTop { + padding: 4px 2px 0px 10px; + text-align: right; + font-size: 80%; +} +#pageLinkBottom { + padding: 0px 2px 0px 10px; + text-align: right; + font-size: 80%; +} + +.pageLink a:visited { + color: #0000EE; +} + + +div#loadingBox { + text-align: center; +} +div#loadingBox p { + margin: 2px; + padding: 2px; +} + + +div#settingBox table tr th { + width: 50%; +} +div#helpBox table tr th { + width: 50%; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/database.js Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,207 @@ +// Database +function Database(name, dir) { + name += '.sqlite'; + + var file = Database.getService('@mozilla.org/file/directory_service;1', 'nsIProperties') + .get('ProfD', Components.interfaces.nsIFile); + + if (dir) { + file.append(dir); + if (!file.exists()) { + file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755); + } + } + + file.append(name); + + this.connection = Database.getService('@mozilla.org/storage/service;1', 'mozIStorageService').openDatabase(file); +} + +Database.getService = function(cls, interface) { + return Components.classes[cls].getService(Components.interfaces[interface]); +} + +Database.bindParams = function(wrapper, params) { + + if (params == null) return; + + // Hash + if (typeof(params) == 'object' && params.length == null) { + var paramNames = this.getParamNames(wrapper); + for each(var name in paramNames) { + var param = params[name]; + if (typeof(param)=='undefined') continue; + + if (param instanceof Date){ + wrapper.params[name] = param.getTime(); + continue; + } + + wrapper.params[name] = param; + } + return; + } + + // Array + if (typeof(params) == 'string' || params.length == null) { + params = [].concat(params); + } + + var statement = wrapper.statement; + for (var i = 0, len = statement.parameterCount; i < len; i++) { + statement.bindUTF8StringParameter(i, params[i]); + } +} + +Database.getParamNames = function(wrapper) { + var paramNames = []; + var statement = wrapper.statement; + for (var i=0, len=statement.parameterCount ; i<len ; i++) { + paramNames.push(statement.getParameterName(i).substr(1)); + } + return paramNames; +} + +Database.getColumnNames = function(wrapper) { + var columnNames=[]; + statement = wrapper.statement; + for ( var i = 0, len = statement.columnCount; i < len; i++) { + columnNames.push(statement.getColumnName(i)); + } + return columnNames; +} + +Database.getRow = function(row, columnNames){ + var result = {}; + for each(var name in columnNames) { + result[name] = row[name]; + } + return result; +} + +Database.DatabaseException = function(db, exception){ + this.code = db.connection.lastError; + this.message = 'errorCode:' + this.code + '; ' + db.connection.lastErrorString; + this.original = exception; +} + + +Database.prototype = { + createStatement: function(sql) { + + try { + var statement = this.connection.createStatement(sql); + var wrapper = Components.classes["@mozilla.org/storage/statement-wrapper;1"] + .createInstance(Components.interfaces.mozIStorageStatementWrapper); + + wrapper.initialize(statement); + return wrapper; + } catch(e) { + this.throwException(e); + } + }, + + execute: function(sql, params, handler) { + if (typeof(handler) == 'function') { + var temp = {}; + temp.process = handler; + handler = temp; + } + + var statement = sql.initialize ? sql : this.createStatement(sql); + try{ + Database.bindParams(statement, params); + + if (!handler) { + statement.execute(); + return; + } + + var columnNames; + while (statement.step()) { + if (!columnNames) + columnNames = Database.getColumnNames(statement); + + handler.process(statement.row, columnNames); + } + + return statement; + + } catch(e if e==StopIteration) { + } catch(e) { + this.throwException(e); + } finally { + if (statement) + statement.reset(); + } + }, + + throwException: function(exception){ + if (this.connection.lastError != 0) { + throw new Database.DatabaseException(this, exception); + } else { + throw exception; + } + }, + + transaction: function(handler) { + var connection = this.connection; + var error = false; + connection.beginTransaction(); + try { + handler(); + connection.commitTransaction(); + } catch(e) { + error = true; + this.throwException(e); + } finally { + if(error) + connection.rollbackTransaction(); + } + } +} + +// ResultArrayHandler +function ResultArrayHandler(database, sql) { + this.database = database; + this.statement = this.database.createStatement(sql); +} + +ResultArrayHandler.prototype = { + execute: function(params) { + this.result = []; + this.database.execute(this.statement, params, this); + return this.result; + }, + + createRowResult: function(row, columnNames) { + var result = {}; + for (var i = 0, len = columnNames.length; i < len; i++) { + result[columnNames[i]] = row[columnNames[i]]; + } + return result; + }, + + process: function(row, columnNames) { + this.result.push(Database.getRow(row, columnNames)); + } +} + +// UpdateHandler +function UpdateHandler(database, sql) { + this.database = database; + this.statement = this.database.createStatement(sql); +} + +UpdateHandler.prototype = { + execute: function(params) { + if (params && params.constructor == Array) { + for (var i = 0, len = params.length; i < len; i++) { + this.database.execute(this.statement, params[i], null); + } + } else { + this.database.execute(this.statement, params, null); + } + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/glayer.css Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,76 @@ +#glayer { + position: fixed!important; + position: absolute; + top:0; + left:0; + width:100%; + height:100%; + z-index:100; + background-color:#1F1F1F; + -moz-opacity: 0.8; + opacity:.80; +} + +/* Box Base */ +div.glayer_box { + position: fixed!important; + position: absolute; + z-index: 101; + width: 400px; + padding: 2px; + border: 5px solid #B8B8B8; + background-color: #FFFFFF; +} + +div.glayer_box_big { + position: fixed!important; + position: absolute; + z-index: 101; + width: 500px; + padding: 2px; + border: 5px solid #B8B8B8; + background-color: #FFFFFF; +} + +/* Message */ +p#glayer_message_text { + margin: 2px; + padding: 2px; + text-align: center; +} + +/* Alert */ +p#glayer_alert_text { + margin: 2px; + padding: 2px; + text-align: center; +} +p#glayer_alert_button { + margin: 10px 0 0 0; + padding: 0; + text-align: center; +} +input#glayer_alert_ok { + font-size: 80%; +} + +/* Confirm */ +p#glayer_confirm_text { + margin: 2px; + padding: 2px; + text-align: center; +} +p#glayer_confirm_button { + margin: 10px 0 0 0; + padding: 0; + text-align: center; +} +input#glayer_confirm_ok { + margin: 2px; + font-size: 80%; +} +input#glayer_confirm_cancel { + margin: 2px; + font-size: 80%; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/glayer.js Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,365 @@ +/* +-------------------------------------------------------- +glayer.js - (gray out + layer) = glayer +Version 2.2 (Update 2007/05/21) + +- onozaty (http://www.enjoyxstudy.com) + +Released under the Creative Commons License(Attribution 2.1 Japan): + http://creativecommons.org/licenses/by/2.1/jp/ + +For details, see the web site: + http://www.enjoyxstudy.com/javascript/glayer/ + +-------------------------------------------------------- +*/ + +var Glayer = { + defaultId : 'glayer', + show: function(grayElement) { + + grayElement = this.createElement(grayElement || this.defaultId); + this.resetSize(grayElement); + grayElement.style.display = ''; + + return grayElement; + }, + hide: function(grayElement) { + + grayElement = this.getElement(grayElement || this.defaultId); + grayElement.style.display = 'none'; + + return grayElement; + }, + fadeIn: function(grayElement, fadeOptions) { + + grayElement = this.createElement(grayElement || this.defaultId); + this.resetSize(grayElement); + + fadeOptions = this.copyProperties({to: this.getOpacity(grayElement)}, fadeOptions || {}); + new Glayer.FadeIn(grayElement, fadeOptions).start(); + + return grayElement; + }, + fadeOut: function(grayElement, fadeOptions) { + + grayElement = this.getElement(grayElement || this.defaultId); + + fadeOptions = this.copyProperties({from: this.getOpacity(grayElement)}, fadeOptions || {}); + new Glayer.FadeOut(grayElement, fadeOptions).start(); + + return grayElement; + }, + + showParallel: function(otherElements, grayElement) { + + grayElement = this.createElement(grayElement || this.defaultId); + this.resetSize(grayElement); + grayElement.style.display = ''; + + for (var i = 0; i < otherElements.length; i++) { + otherElements[i] = this.getElement(otherElements[i]); + otherElements[i].style.display = ''; + } + + return grayElement; + }, + hideParallel: function(otherElements, grayElement) { + + grayElement = this.getElement(grayElement || this.defaultId); + grayElement.style.display = 'none'; + + for (var i = 0; i < otherElements.length; i++) { + otherElements[i] = this.getElement(otherElements[i]); + otherElements[i].style.display = 'none'; + } + + return grayElement; + }, + fadeInParallel: function(otherElements, grayElement, fadeOptions) { + + grayElement = this.createElement(grayElement || this.defaultId); + this.resetSize(grayElement); + + fadeOptions = this.copyProperties({to: this.getOpacity(grayElement)}, fadeOptions || {}); + var grayFade = new Glayer.FadeIn(grayElement, fadeOptions); + + var otherFades = []; + for (var i = 0; i < otherElements.length; i++) { + otherElements[i] = this.getElement(otherElements[i]); + otherFades.push(new Glayer.FadeIn(otherElements[i], {duration: fadeOptions.duration, to: this.getOpacity(otherElements[i])})); + } + + grayFade.start(function(){ + grayFade.update(); + for (var i = 0; i < otherFades.length; i++) { + otherFades[i].update(); + } + }); + + return grayElement; + }, + fadeOutParallel: function(otherElements, grayElement, fadeOptions) { + + grayElement = this.getElement(grayElement || this.defaultId); + + fadeOptions = this.copyProperties({from: this.getOpacity(grayElement)}, fadeOptions || {}); + var grayFade = new Glayer.FadeOut(grayElement, fadeOptions); + + var otherFades = []; + for (var i = 0; i < otherElements.length; i++) { + otherElements[i] = this.getElement(otherElements[i]); + otherFades.push(new Glayer.FadeOut(otherElements[i], {duration: fadeOptions.duration, from: this.getOpacity(otherElements[i])})); + } + + grayFade.start(function(){ + grayFade.update(); + for (var i = 0; i < otherFades.length; i++) { + otherFades[i].update(); + } + }); + + return grayElement; + }, + + resetSize: function(element) { + var position = this._getStyle(element, 'position'); + + if (position != 'fixed') { + var page = this.getPageSize(); + + element.style.width = page.width + 'px'; + element.style.height = page.height + 'px'; + } + }, + + // Util + getElement: function(element) { + + if (typeof element == 'string') { + element = document.getElementById(element); + } + return element; + }, + createElement: function(element) { + + var id = element; + element = this.getElement(element); + + if (!element) { + element = document.createElement('div'); + element.id = id; + element.style.display = 'none'; + document.body.appendChild(element); + } + return element; + }, + copyProperties: function(dest, src) { + for (var property in src) { + dest[property] = src[property]; + } + return dest; + }, + isIE : (/MSIE/.test(navigator.userAgent) && !window.opera), + isWebKit : (navigator.userAgent.indexOf('AppleWebKit') != -1), + + // Window / Page Size + getWindowSize: function() { + var width; + var height; + + if (document.compatMode == 'CSS1Compat' && !window.opera) { + // Strict Mode && Non Opera + width = document.documentElement.clientWidth; + height = document.documentElement.clientHeight; + } else if (navigator.userAgent.indexOf('AppleWebKit') != -1){ + // Safari + width = window.innerWidth; + height = window.innerHeight; + } else { + // other + width = document.body.clientWidth; + height = document.body.clientHeight; + } + + return {width: width, height: height}; + }, + getPageSize: function() { + + var windowSize = this.getWindowSize(); + + var width = windowSize.width; + var height = windowSize.height; + + if (document.compatMode == 'CSS1Compat') { + if (document.documentElement.scrollWidth > width) { + width = document.documentElement.scrollWidth; + } + if (document.documentElement.scrollHeight > height) { + height = document.documentElement.scrollHeight; + } + } else { + if (document.body.scrollWidth > width) { + width = document.body.scrollWidth; + } + if (document.body.scrollHeight > height) { + height = document.body.scrollHeight; + } + } + + return {width: width, height: height}; + }, + + // Styles + getOpacity: function(element) { + var value = this._getStyle(element, 'opacity'); + if (value) return parseFloat(value); + + if (value = (element.style.filter || '').match(/alpha\(opacity=(.*)\)/)) { + if (value[1]) return parseFloat(value[1]) / 100; + } + + return 1.0; + }, + _getStyle: function(element, style) { + var value = element.style[style]; + if (value) return value; + + if (document.defaultView && document.defaultView.getComputedStyle) { + var oldDisplay = element.style.display; + if (Glayer.isWebKit) element.style.display = 'block'; + var css = document.defaultView.getComputedStyle(element, null); + if (css) value = css.getPropertyValue(style); + if (Glayer.isWebKit) element.style.display = oldDisplay; + return value; + } else if (element.currentStyle) { + return element.currentStyle[style]; + } + + return null; + }, + + // debug + getDebugInfo: function() { + + var debugInfo = new Array(); + + debugInfo.push("document.compatMode:" + document.compatMode); + debugInfo.push("window.innerWidth:" + window.innerWidth); + debugInfo.push("window.innerHeight:" + window.innerHeight); + debugInfo.push("window.scrollMaxX:" + window.scrollMaxX); + debugInfo.push("window.scrollMaxY:" + window.scrollMaxY); + debugInfo.push("document.body.scrollWidth:" + document.body.scrollWidth); + debugInfo.push("document.body.scrollHeight:" + document.body.scrollHeight); + debugInfo.push("document.body.offsetWidth:" + document.body.offsetWidth); + debugInfo.push("document.body.offsetHeight:" + document.body.offsetHeight); + debugInfo.push("document.body.clientWidth:" + document.body.clientWidth); + debugInfo.push("document.body.clientHeight:" + document.body.clientHeight); + debugInfo.push("document.documentElement:" + document.documentElement); + if (document.documentElement) { + debugInfo.push("document.documentElement.scrollWidth:" + document.documentElement.scrollWidth); + debugInfo.push("document.documentElement.scrollHeight:" + document.documentElement.scrollHeight); + debugInfo.push("document.documentElement.offsetWidth:" + document.documentElement.offsetWidth); + debugInfo.push("document.documentElement.offsetHeight:" + document.documentElement.offsetHeight); + debugInfo.push("document.documentElement.clientWidth:" + document.documentElement.clientWidth); + debugInfo.push("document.documentElement.clientHeight:" + document.documentElement.clientHeight); + } + + return debugInfo; + } +}; + + +// Fade In/Out +Glayer.Fade = function(element, options) { + this.setup(element, options); +}; + +Glayer.Fade.prototype = { + intervalTime: 10, + duration: 800, + + setup: function(element, options) { + this.element = element; + this.style = this.element.style; + + options = options || {}; + + if (options.duration != undefined) this.duration = options.duration; + if (options.from != undefined) this.from = options.from; + if (options.to != undefined) this.to = options.to; + if (options.callback != undefined) this.callback = options.callback; + + this.startTime = new Date().getTime(); + this.endTime = this.startTime + this.duration; + + this.range = this.to - this.from; + + if (Glayer.isIE && (!this.element.currentStyle.hasLayout)) { + this.style['zoom'] = 1; + } + this.first = true; + }, + start: function(updater) { + var self = this; + updater = updater || function(){ self.update(); }; + this.intervalId = setInterval(updater, this.intervalTime); + }, + end: function() { + if (this.intervalId != null) { + clearInterval(this.intervalId); + this.intervalId = null; + } + this.execCallback(); + }, + execCallback: function() { + if (!this.callback) return; + + if (typeof this.callback == 'function') { + this.callback(); + } else { + for (var i = 0; i < this.callback.length; i++) { + this.callback[i](); + } + } + }, + update: function() { + var nowTime = new Date().getTime(); + + if (this.first) { + this.style.display = ''; + this.first = false; + } + + if (nowTime >= this.endTime) { + this.setOpacity(this.to); + this.end(); + } else { + this.setOpacity(this.from + (this.range * (nowTime - this.startTime) / this.duration)); + } + }, + setOpacity: function(opacity) { + this.style.opacity = opacity; + if (Glayer.isIE) this.style.filter = 'alpha(opacity=' + (opacity * 100) + ')'; + } +}; + +Glayer.FadeIn = function() { + Glayer.Fade.apply(this, arguments); +}; +Glayer.copyProperties(Glayer.FadeIn.prototype, Glayer.Fade.prototype); +Glayer.FadeIn.prototype.from = 0.0; +Glayer.FadeIn.prototype.to = 1.0; + +Glayer.FadeOut = function() { + Glayer.Fade.apply(this, arguments); +}; +Glayer.copyProperties(Glayer.FadeOut.prototype, Glayer.Fade.prototype); +Glayer.FadeOut.prototype.from = 1.0; +Glayer.FadeOut.prototype.to = 0.0; +Glayer.FadeOut.prototype.end = function() { + this.style.display = 'none'; + this.setOpacity(this.from); + Glayer.Fade.prototype.end.apply(this, arguments); +}; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/glayer_ex.js Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,246 @@ +/* +-------------------------------------------------------- +glayer_ex.js (glayer.js extensions) +Version 1.0 (Update 2007/05/28) + +- onozaty (http://www.enjoyxstudy.com) + +Released under the Creative Commons License(Attribution 2.1 Japan): + http://creativecommons.org/licenses/by/2.1/jp/ + +For details, see the web site: + http://www.enjoyxstudy.com/javascript/glayer/extension/ + http://www.enjoyxstudy.com/javascript/glayer/ + +-------------------------------------------------------- +*/ +Glayer.copyProperties(Glayer, { + //// Base //// + boxClassName: 'glayer_box', + createBox: function(boxElement) { + boxElement = this.createElement(boxElement); + boxElement.className = this.boxClassName; + return boxElement; + }, + showBox: function(boxElement, boxOptions, grayElement) { + this.setBoxPosition(boxElement, boxOptions); + return this.showParallel([boxElement], grayElement); + }, + hideBox: function(boxElement, grayElement) { + return this.hideParallel([boxElement], grayElement); + }, + fadeInBox: function(boxElement, boxOptions, grayElement, fadeOption) { + this.setBoxPosition(boxElement, boxOptions); + return this.fadeInParallel([boxElement], grayElement, fadeOption); + }, + fadeOutBox: function(boxElement, grayElement, fadeOption) { + return this.fadeOutParallel([boxElement], grayElement, fadeOption); + }, + + setBoxPosition: function(boxElement, boxOptions) { + var style = boxElement.style; + + boxOptions = boxOptions || {}; + var topRatio = boxOptions.topRatio != null ? boxOptions.topRatio : 0.5; + var leftRatio = boxOptions.leftRatio != null ? boxOptions.leftRatio : 0.5; + style.width = boxOptions.width || ''; + style.height = boxOptions.height || ''; + + var windowTop = 0; + var windowLeft = 0; + var position = this._getStyle(boxElement, 'position'); + if (position != 'fixed') { + windowTop = document.documentElement.scrollTop || document.body.scrollTop; + windowLeft = document.documentElement.scrollLeft || document.body.scrollLeft; + } + + style.display = ''; + var offsetHeight = boxElement.offsetHeight; + var offsetWidth = boxElement.offsetWidth; + style.display = 'none'; + + var windowSize = this.getWindowSize(); + + style.top = ((windowSize.height * topRatio) - (offsetHeight * topRatio) + windowTop) + 'px'; + style.left = ((windowSize.width * leftRatio) - (offsetWidth * leftRatio) + windowLeft) + 'px'; + }, + + //// Message //// + defaultMessage: { + boxId: 'glayer_message', + textId: 'glayer_message_text' + }, + createMessageBox: function(message, boxOptions) { + boxOptions = boxOptions || {}; + var boxElement = boxOptions.box || this.defaultMessage.boxId; + var boxId = boxElement.id || boxElement; + var textElement = boxOptions.text || this.defaultMessage.textId; + var textId = textElement.id || textElement; + + boxElement = this.getElement(boxElement); + if (!boxElement) { + boxElement = this.createBox(boxId); + textElement = document.createElement('p'); + textElement.id = textId; + boxElement.appendChild(textElement); + } else { + textElement = this.getElement(textElement); + } + + textElement.innerHTML = message; + return boxElement; + }, + + showMessage: function(message, boxOptions, grayElement) { + return this.showBox(this.createMessageBox(message, boxOptions), boxOptions, grayElement); + }, + hideMessage: function(boxElement, grayElement) { + return this.hideBox(boxElement || this.defaultMessage.boxId, grayElement); + }, + fadeInMessage: function(message, boxOptions, grayElement, fadeOption) { + return this.fadeInBox(this.createMessageBox(message, boxOptions), boxOptions, grayElement, fadeOption); + }, + fadeOutMessage: function(boxElement, grayElement, fadeOption) { + return this.fadeOutBox(boxElement || this.defaultMessage.boxId, grayElement, fadeOption); + }, + + //// Alert //// + defaultAlert: { + boxId: 'glayer_alert', + textId: 'glayer_alert_text', + buttonId: 'glayer_alert_button', + okId: 'glayer_alert_ok', + okLabel: 'OK' + }, + getDefaultAlertOkFunc: function() { + return function(){ Glayer.hideAlert(); }; + }, + + createAlertBox: function(message, boxOptions) { + + boxOptions = boxOptions || {}; + var boxElement = boxOptions.box || this.defaultAlert.boxId; + var boxId = boxElement.id || boxElement; + var textElement = boxOptions.text || this.defaultAlert.textId; + var textId = textElement.id || textElement; + var okElement = boxOptions.ok || this.defaultAlert.okId; + var okId = okElement.id || okElement; + + boxElement = this.getElement(boxElement); + if (!boxElement) { + boxElement = this.createBox(boxId); + + textElement = document.createElement('p'); + textElement.id = textId; + boxElement.appendChild(textElement); + + var buttonElement = document.createElement('p'); + buttonElement.id = this.defaultAlert.buttonId; + boxElement.appendChild(buttonElement); + + okElement = document.createElement('input'); + okElement.type = 'button'; + okElement.id = okId; + buttonElement.appendChild(okElement); + } else { + textElement = this.getElement(textElement); + okElement = this.getElement(okElement); + } + + textElement.innerHTML = message; + + okElement.value = boxOptions.okLabel || this.defaultAlert.okLabel; + okElement.onclick = boxOptions.callback || this.getDefaultAlertOkFunc(); + + return boxElement; + }, + + showAlert: function(message, boxOptions, grayElement) { + return this.showBox(this.createAlertBox(message, boxOptions), boxOptions, grayElement); + }, + hideAlert: function(boxElement, grayElement) { + return this.hideBox(boxElement || this.defaultAlert.boxId, grayElement); + }, + fadeInAlert: function(message, boxOptions, grayElement, fadeOption) { + return this.fadeInBox(this.createAlertBox(message, boxOptions), boxOptions, grayElement, fadeOption); + }, + fadeOutAlert: function(boxElement, grayElement, fadeOption) { + return this.fadeOutBox(boxElement || this.defaultAlert.boxId, grayElement, fadeOption); + }, + + //// Confirm //// + defaultConfirm: { + boxId: 'glayer_confirm', + textId: 'glayer_confirm_text', + buttonId: 'glayer_confirm_button', + okId: 'glayer_confirm_ok', + okLabel: 'OK', + cancelId: 'glayer_confirm_cancel', + cancelLabel: 'Cancel' + }, + getConfirmResultFunc: function(callback, result) { + return function(){ callback(result); }; + }, + + createConfirmBox: function(message, resultCallback, boxOptions) { + + boxOptions = boxOptions || {}; + var boxElement = boxOptions.box || this.defaultConfirm.boxId; + var boxId = boxElement.id || boxElement; + var textElement = boxOptions.text || this.defaultConfirm.textId; + var textId = textElement.id || textElement; + var okElement = boxOptions.ok || this.defaultConfirm.okId; + var okId = okElement.id || okElement; + var cancelElement = boxOptions.cancel || this.defaultConfirm.cancelId; + var cancelId = cancelElement.id || cancelElement; + + boxElement = this.getElement(boxElement); + if (!boxElement) { + boxElement = this.createBox(boxId); + + textElement = document.createElement('p'); + textElement.id = textId; + boxElement.appendChild(textElement); + + var buttonElement = document.createElement('p'); + buttonElement.id = this.defaultConfirm.buttonId; + boxElement.appendChild(buttonElement); + + okElement = document.createElement('input'); + okElement.type = 'button'; + okElement.id = okId; + buttonElement.appendChild(okElement); + cancelElement = document.createElement('input'); + cancelElement.type = 'button'; + cancelElement.id = cancelId; + buttonElement.appendChild(cancelElement); + } else { + textElement = this.getElement(textElement); + okElement = this.getElement(okElement); + cancelElement = this.getElement(cancelElement); + } + + textElement.innerHTML = message; + + okElement.value = boxOptions.okLabel || this.defaultConfirm.okLabel; + okElement.onclick = this.getConfirmResultFunc(resultCallback, true); + + cancelElement.value = boxOptions.cancelLabel || this.defaultConfirm.cancelLabel; + cancelElement.onclick = this.getConfirmResultFunc(resultCallback, false); + + return boxElement; + }, + + showConfirm: function(message, resultCallback, boxOptions, grayElement) { + return this.showBox(this.createConfirmBox(message, resultCallback, boxOptions), boxOptions, grayElement); + }, + hideConfirm: function(boxElement, grayElement) { + return this.hideBox(boxElement || this.defaultConfirm.boxId, grayElement); + }, + fadeInConfirm: function(message, resultCallback, boxOptions, grayElement, fadeOption) { + return this.fadeInBox(this.createConfirmBox(message, resultCallback, boxOptions), boxOptions, grayElement, fadeOption); + }, + fadeOutConfirm: function(boxElement, grayElement, fadeOption) { + return this.fadeOutBox(boxElement || this.defaultConfirm.boxId, grayElement, fadeOption); + } +});
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/googlebookmarks.js Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,131 @@ +var GoogleBookmarksParser = { + parse: function(xml, idStart) { + var items = xml.getElementsByTagName('item'); + + var list = []; + for (var i = 0, len = items.length; i < len; i++) { + var bookmark = {}; + var item = items[i]; + + bookmark.id = idStart + i; + bookmark.url = this.getFirstText(item, 'link'); + bookmark.title = this.getFirstText(item, 'title'); + bookmark.info = this.getInfo(item); + bookmark.tags = this.getTags(item); + bookmark.time = this.getFirstText(item, 'pubDate'); + + list.push(bookmark); + } + + return list; + }, + getInfo: function(item) { + + var annotation = item.getElementsByTagNameNS('http://www.google.com/history/', 'bkmk_annotation'); + return (annotation.length != 0) ? annotation[0].firstChild.nodeValue : ''; + }, + getTags: function(item) { + + var tags = item.getElementsByTagNameNS('http://www.google.com/history/', 'bkmk_label'); + + var tagsList = []; + for (var i = 0, len = tags.length; i < len; i++) { + tagsList.push(tags[i].firstChild.nodeValue); + } + + if (tagsList.length == 0) { + return ''; + } + return '[' + tagsList.join('] [') + ']'; + }, + getFirstText: function(element, tagName) { + var firstChild = element.getElementsByTagName(tagName)[0].firstChild; + return (firstChild) ? firstChild.nodeValue : ''; + } +} + + +var GoogleBookmarksLoader = function(statusElement, loadingElement, database, callback) { + this.init(statusElement, loadingElement, database, callback); +}; + +for (var prop in LoaderBase.prototype) { + GoogleBookmarksLoader.prototype[prop] = LoaderBase.prototype[prop]; +} + +GoogleBookmarksLoader.prototype.url = 'https://www.google.com/bookmarks/lookup?output=rss&sort=date'; +GoogleBookmarksLoader.COLLECT_SIZE = 1000; + +GoogleBookmarksLoader.prototype._load = function() { + this.bookmarks = []; + this.__load(); +} +GoogleBookmarksLoader.prototype.__load = function() { + + var self = this; + var request = new XMLHttpRequest(); + + request.onreadystatechange = function() { + if (request.readyState == 4) { + try { + request.status + } catch(e) { + // error + self.error('error :connect error :' + self.url); + } + + if (request.status == 200) { + // success + + var xml = request.responseXML; + + var tempBookmarks = GoogleBookmarksParser.parse(xml, self.bookmarks.length); + self.bookmarks = self.bookmarks.concat(tempBookmarks); + + if (tempBookmarks.length < GoogleBookmarksLoader.COLLECT_SIZE) { + + var userId = 'dummy'; + prefBranch.setCharPref('userId', userId); + incsearch.userId = userId; + + self.total = self.bookmarks.length; + + var generator = self.update(self.bookmarks); + + var executer = new Executer( + generator, + 100, + function(count) { + self.dispLoading(count); + }, + function() { + self.dispEnd(self.bookmarks.length); + self.callback(); + } + ); + + executer.run(); + + } else { + self.__load(); + } + } else { + // error + var errMsg = 'error :' + request.status + ' :' + request.statusText + ' :' + self.url; + self.error(errMsg); + } + } + }; + + request.open("GET", this.url + '&start=' + this.bookmarks.length + '&num=' + GoogleBookmarksLoader.COLLECT_SIZE, true); + request.send(null); +}; + + +IncSearch.prototype.createEditUrl = function(bookmark) { + return 'http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=' + encodeURIComponent(bookmark.url); +}; + + +var EXTENSION_NAME = 'googlebookmarks_incsearch'; +var BookmarkLoader = GoogleBookmarksLoader;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/incsearch.js Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,631 @@ +var IncSearch = function() { + this.initialize.apply(this, arguments); +}; + +/*-- Utils --------------------------------------------*/ +IncSearch._copyProperties = function(dest, src) { + for (var property in src) { + dest[property] = src[property]; + } + return dest; +}; + +IncSearch._copyProperties = function(dest, src) { + for (var property in src) { + dest[property] = src[property]; + } + return dest; +}; + +IncSearch._getElement = function(element) { + return (typeof element == 'string') ? document.getElementById(element) : element; +}; + +IncSearch._addEvent = function(element, type, func) { + element.addEventListener(type, func, false); +}; + +IncSearch._stopEvent = function(event) { + event.preventDefault(); + event.stopPropagation(); +}; + +/*-----------------------------------------------------*/ +IncSearch.prototype = { + initialize: function(input, viewArea) { + this.input = IncSearch._getElement(input); + this.viewArea = IncSearch._getElement(viewArea); + + this.checkLoopTimer = null; + this.setOptions(arguments[2] || {}); + + this.reset(); + + // check loop start + this.checkLoop(); + }, + + reset: function() { + this.oldInput = null; + this.results = null; + this.resultCount = null; + + this.nowPage = 0; + this.nowRow = 0; + + this.resetTotalCount(); + }, + + // options + interval: 500, + delay: 0, + dispMax: 10, + initDispNon: false, + ignoreCase: true, + highlight: true, + highClassName: 'high', + highClassNum: 4, + delim: ' ', + escape: true, + pagePrevName: 'prev', + pageNextName: 'next', + useHotkey: true, + urlTarget: '_blank', + editTarget: '_blank', + + startElementText: '<table><tr><th></th><th width="60%">Description</th><th width="20%">Tags</th><th width="20%">Time</th><th></th>', + + setOptions: function(options) { + + IncSearch._copyProperties(this, options); + + if (this.useHotkey) { + IncSearch._addEvent(document, 'keydown', this._bindEvent(this.hotkey)); + } + }, + + checkLoop: function() { + var input = this.getInput(); + if (this.isChange(input)) { + this.oldInput = input; + if (this.delay == 0) { + this.startSearch(input); + } else { + if (this.startSearchTimer) clearTimeout(this.startSearchTimer); + this.startSearchTimer = setTimeout(this._bind(this.startSearch, input), this.delay); + } + } + if (this.checkLoopTimer) clearTimeout(this.checkLoopTimer); + this.checkLoopTimer = setTimeout(this._bind(this.checkLoop), this.interval); + }, + + isChange: function(input) { + return (!this.oldInput || (input.join(this.delim) != this.oldInput.join(this.delim))); + }, + + startSearch: function(input) { + // init + this.clearViewArea(); + if (!this.initDispNon || input.length != 0) { + if (this.searchBefore) this.searchBefore(); + this.count(input); + this.search(input, 1); + this.createViewArea(input); + this.nowPage = 1; + this.changeRow(1); + this.createPageLink(1, this.pageLinkTop); + this.createPageLink(1, this.pageLinkBottom); + if (this.searchAfter) this.searchAfter(); + } + }, + changePage: function(pageNo) { + + var start = (pageNo - 1) * this.dispMax + 1; + + if (start > this.resultCount) return false; + + if (this.changePageBefore) this.changePageBefore(pageNo); + this.search(this.oldInput, start); + this.createViewArea(this.oldInput); + this.nowPage = pageNo; + this.nowRow = 0; + this.changeRow(1); + this.createPageLink(pageNo, this.pageLinkTop); + this.createPageLink(pageNo, this.pageLinkBottom); + if (this.changePageAfter) this.changePageAfter(pageNo); + return true; + }, + changeRow: function(rowNo) { + + if (this.results.length == 0) { + return; + } + + if (rowNo < 1) { + if (this.nowPage > 1) { + this.changePage(this.nowPage - 1); + this.changeRow(this.results.length); + } + return; + } + + if (rowNo > this.results.length) { + if (this.nowPage < this.getPageCount()) { + this.changePage(this.nowPage + 1); + } + return; + } + + var table = this.viewArea.getElementsByTagName('table')[0]; + + if (this.nowRow != 0 && table.rows[this.nowRow]) { + table.rows[this.nowRow].className = ''; + } + var row = table.rows[rowNo]; + row.className = 'focus'; + + var margin = 0; + var topPos = (this.viewArea.offsetTop + row.offsetTop) - (this.viewArea.offsetTop + table.rows[1].offsetTop); + var bottomPos = (this.viewArea.offsetTop + row.offsetTop + row.offsetHeight) + 5; + + if (topPos < document.documentElement.scrollTop) { + window.scrollTo(0, topPos); + } else if (bottomPos > document.documentElement.clientHeight + document.documentElement.scrollTop) { + window.scrollTo(0, bottomPos - document.documentElement.clientHeight); + } + + this.nowRow = rowNo; + }, + openUrl: function(rowNo) { + + if (this.results.length == 0) { + return; + } + + window.open(this.results[rowNo - 1].url, this.urlTarget); + }, + openEditWindow: function(rowNo) { + + if (this.results.length == 0) { + return; + } + + window.open(this.createEditUrl(this.results[rowNo - 1]), this.editTarget); + }, + + countSql: 'SELECT COUNT(*) count FROM bookmark', + resetTotalCount: function() { + + var handler = new ResultArrayHandler(this.database, this.countSql); + handler.execute(); + this.totalCount = handler.result[0].count; + }, + + count: function(patternList) { + var where = this.createWhere(patternList); + var sql = this.countSql + where.where; + + try{ + var handler = new ResultArrayHandler(this.database, sql); + handler.execute(where.params); + this.resultCount = handler.result[0].count; + } catch(e) { + alert(e.message || e); + throw e; + } + }, + + searchSql: 'SELECT url, title, info, tags, time FROM bookmark', + search: function(patternList, start) { + + var where = this.createWhere(patternList); + var sql = [ + this.searchSql, where.where, + ' ORDER BY id', + ' LIMIT ', this.dispMax, + ' OFFSET ', (start - 1)].join(''); + + try { + var handler = new ResultArrayHandler(this.database, sql); + handler.execute(where.params); + this.results = handler.result; + } catch(e) { + alert(e.message || e); + throw e; + } + }, + createWhere: function(patternList) { + + var where = []; + var params = {}; + + if (patternList.length != 0) { + for (var i = 0, len = patternList.length; i < len; i++) { + var temp = this.createCondOne(patternList[i], params, 'param' + i); + if (temp != '') { + if (where.length != 0) where.push(' AND'); + where.push(temp); + } + } + } + + var whereString = where.join(''); + if (whereString.length > 0) whereString = ' WHERE' + whereString; + + return { + where: whereString, + params: params}; + }, + createCondOne: function(pattern, params, paramName) { + + var where = []; + if (pattern.indexOf('|') > -1) { + var patterns = this.getSplitPatterns(pattern, '|'); + if (patterns.length != 0) { + for (var i = 0, len = patterns.length; i < len; i++) { + var temp = this.createCondOne(patterns[i], params, paramName + '_' + i); + if (temp != '') { + if (where.length != 0) where.push(' OR'); + where.push(temp); + } + } + if (where.length != 0) { + where.unshift(' ('); + where.push(')'); + } + } + } else if (pattern.indexOf('!') == 0) { + if (pattern.length != 1) { + where.push(this._createCondOne(pattern.substr(1), params, paramName, true)); + } + } else { + where.push(this._createCondOne(pattern, params, paramName)); + } + return where.join(''); + }, + _createCondOne: function(pattern, params, paramName, not) { + params[paramName] = ['%', pattern.toUpperCase().replace(/\\/g, '\\\\').replace(/\%/g, '\\%').replace(/\_/g, '\\_'), '%'].join(''); + return [" search_text ", (not ? "NOT " : ""), "LIKE :", paramName, " ESCAPE '\\'"].join(''); + }, + + getSplitPatterns: function(pattern, separator) { + var temp = pattern.split(separator); + var patterns = []; + for (var i = 0, len = temp.length; i < len; i++) { + if (temp[i] != '') patterns.push(temp[i]); + } + return patterns; + }, + + createPageLink: function(pageNo, pageLinkElm) { + + pageLinkElm = IncSearch._getElement(pageLinkElm); + + var pageCount = this.getPageCount(); + + var prev_page = false; + var next_page = false; + + if (pageCount > 1) { + + if (pageNo == 1) { + next_page = true; + } else if (pageNo == pageCount) { + prev_page = true; + } else { + next_page = true; + prev_page = true; + } + } + + pageLinkElm.innerHTML = ''; + + if (prev_page) { + this.createPageAnchor(pageLinkElm, this.pagePrevName, pageNo - 1); + } + if (next_page) { + if (prev_page) { + pageLinkElm.appendChild(document.createTextNode(' | ')); + } + + this.createPageAnchor(pageLinkElm, this.pageNextName, pageNo + 1); + } + }, + + createPageAnchor: function(parent, text, page) { + + var a = parent.appendChild(document.createElement('a')); + a.setAttribute('href', 'javascript:void(0)'); + a.appendChild(document.createTextNode(text)); + + IncSearch._addEvent(a, 'click', this._bind(this.changePage, page)); + }, + + getPageCount: function() { + var pageCount = 0; + + if (this.resultCount && this.resultCount != 0) { + if (this.dispMax == 0) { + pageCount = 1; + } else { + pageCount = Math.floor((this.resultCount + this.dispMax - 1) / this.dispMax); + } + } + return pageCount; + }, + + createInfo: function() { + var displayInfo = ''; + + if (this.resultCount != 0) { + var start = (this.nowPage - 1) * this.dispMax + 1; + var end = start + this.dispMax - 1; + + if (this.dispMax == 0 || end > this.resultCount) { + end = this.resultCount; + } + displayInfo = ['(display :', start, '-', end, ')'].join(''); + } + this.status.innerHTML = [this.resultCount.toString(), ' hits ', + displayInfo, ' / total : ', this.totalCount].join(''); + }, + searchAfter: function() { + this.createInfo(); + window.scrollTo(0, 0); + }, + searchBefore: function() { + this.status.innerHTML = 'Search...'; + }, + changePageAfter: function(pageNo) { + this.createInfo(); + window.scrollTo(0, 0); + }, + + hotkey: function(event) { + if (event.ctrlKey) { + switch(event.keyCode) { + case 13: // Enter + case 77: // m (Enter Max OS X) + this.openUrl(this.nowRow); + IncSearch._stopEvent(event); + break; + case 37: // Left + if (this.nowPage > 1) { + this.changePage(this.nowPage - 1); + } + IncSearch._stopEvent(event); + break; + case 38: // Up + this.changeRow(this.nowRow - 1); + IncSearch._stopEvent(event); + break; + case 39: // Right + if (this.nowPage < this.getPageCount()) { + this.changePage(this.nowPage + 1); + } + IncSearch._stopEvent(event); + break; + case 40: // Down + this.changeRow(this.nowRow + 1); + IncSearch._stopEvent(event); + break; + case 69: // e + this.openEditWindow(this.nowRow); + IncSearch._stopEvent(event); + break; + default: + break; + } + } + }, + + createViewArea: function(patternList) { + var elementText = []; + + patternList = this.getHighlightPatterns(patternList); + + for (var i = 0, len = this.results.length; i < len; i++) { + elementText.push(this.createLineElement(this.results[i], patternList)); + } + + if (elementText.length > 0) { + if (this.startElementText) elementText.unshift(this.startElementText); + if (this.endElementText) elementText.push(this.endElementText); + this.viewArea.innerHTML = elementText.join(''); + } + + if (this.afterHookCreateView) { + this.afterHookCreateView(patternList); + } + }, + + getHighlightPatterns: function(patternList) { + var highlightPatterns = []; + + for (var i = 0, len = patternList.length; i < len; i++) { + var pattern = patternList[i]; + if (pattern.indexOf('|') > -1) { + var patterns = this.getSplitPatterns(pattern, '|'); + highlightPatterns = highlightPatterns.concat(this.getHighlightPatterns(patterns)); + } else if (pattern.indexOf('!') != 0) { + highlightPatterns.push(pattern); + } + } + return highlightPatterns; + }, + + clearViewArea: function() { + this.viewArea.innerHTML = ''; + this.results = null; + this.resultCount = null; + this.nowPage = 0; + this.nowRow = 0; + }, + + createLineElement: function(bookmark, patternList) { + + var text = ['<tr><td></td><td>']; + + // url, title + text.push(this.createTitleElement(bookmark, patternList)); + + // info + if (bookmark.info) { + text.push(this.createElement(bookmark.info, patternList, 'p')); + } + text.push('</td>'); + + // tags + text.push(this.createElement(this.tagsString(bookmark.tags), patternList, 'td')); + + // time + text.push(this.createElement(bookmark.time, patternList, 'td', false)); + + // edit + text.push(this.createEditElement(bookmark, patternList)); + text.push('</tr>'); + + return text.join(''); + }, + + createElement: function(value, patternList, tagName, highlight) { + + return ['<', tagName, '>', + this.createText(value, patternList, highlight), + '</', tagName, '>'].join(''); + }, + + createText: function(value, patternList, highlight) { + + var textList = []; + + if (highlight == null) highlight = this.highlight; + + if (highlight) { + + var first = this.getFirstMatch(value, patternList); + + while (first.listIndex != -1) { + textList.push(this._escapeHTML(value.substr(0, first.matchIndex))); + textList.push('<strong class="'); + textList.push(this.highClassName); + textList.push((first.listIndex % this.highClassNum) + 1); + textList.push('">'); + textList.push(this._escapeHTML(value.substr(first.matchIndex, patternList[first.listIndex].length))); + textList.push('</strong>'); + + value = value.substr(first.matchIndex + patternList[first.listIndex].length); + first = this.getFirstMatch(value, patternList); + } + } + + textList.push(this._escapeHTML(value)); + + return textList.join(''); + }, + + tagsString: function(tags, sep) { + + if (typeof(tags) == 'string') return tags; + + sep = sep || ' '; + if (this.tagBracket && tags.length != 0) { + return ['[', tags.join(']' + sep + '['), ']'].join(''); + } else { + return tags.join(sep); + } + }, + + createTitleElement: function(bookmark, patternList) { + var text = ['<a href="', bookmark.url, '"']; + if (this.urlTarget) { + text.push(' target="', this.urlTarget, '" '); + } + text.push('>'); + text.push(this.createText(bookmark.title, patternList)); + text.push('</a>'); + + if (this.addTitleText) { + text.push(this.addTitleText(bookmark, patternList)); + } + + text.push('<br />'); + return text.join(''); + }, + + createEditElement: function(bookmark, patternList) { + + var text = ['<td><a href="', this.createEditUrl(bookmark), '"']; + if (this.editTarget) { + text.push(' target="', this.editTarget, '" '); + } + + text.push('>edit</a></td>'); + + return text.join(''); + }, + + matchIndex: function(value, pattern) { + + if (this.ignoreCase) { + return value.toLowerCase().indexOf(pattern.toLowerCase()); + } else { + return value.indexOf(pattern); + } + }, + + getFirstMatch: function(value, patternList) { + + var first = {}; + first.listIndex = -1; + first.matchIndex = value.length; + + for (var i = 0, len = patternList.length; i < len; i++) { + var index = this.matchIndex(value, patternList[i]); + if (index != -1 && index < first.matchIndex) { + first.listIndex = i; + first.matchIndex = index; + } + } + + return first; + }, + + getInput: function() { + + var value = this.input.value; + + if (!value) { + return []; + } else if (this.delim) { + var list = value.split(this.delim); + var inputs = []; + for (var i = 0, len = list.length; i < len; i++) { + if (list[i]) inputs.push(list[i]); + } + return inputs; + } else { + return [value]; + } + }, + + // Utils + _bind: function(func) { + var self = this; + var args = Array.prototype.slice.call(arguments, 1); + return function(){ func.apply(self, args); }; + }, + _bindEvent: function(func) { + var self = this; + var args = Array.prototype.slice.call(arguments, 1); + return function(event){ event = event || window.event; func.apply(self, [event].concat(args)); }; + }, + _escapeHTML: function(value) { + if (this.escape) { + return value.replace(/\&/g, '&').replace( /</g, '<').replace(/>/g, '>') + .replace(/\"/g, '"').replace(/\'/g, ''').replace(/\n|\r\n/g, '<br />'); + } else { + return value; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/init.js Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,287 @@ +var DEFAULT_NUMBER_OF_RESULTS = 10; +var DEFAULT_SIZE_OF_INPUT_AREA = 80; +var USER_EXT_JS = "user-extension.js" +var USER_EXT_JS_SAMPLE = "user-extension-sample.js" +var USER_CSS = "user.css" +var USER_CSS_SAMPLE = "user-sample.css" + +if (!createTableSql) { + var createTableSql = "CREATE TABLE bookmark(id INTEGER, url TEXT, title TEXT, info TEXT, tags TEXT, time TEXT, search_text TEXT, PRIMARY KEY(id))"; +} + +var database = new Database('bookmark', EXTENSION_NAME); + +var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); +var prefBranch = prefSvc.getBranch('extensions.' + EXTENSION_NAME + '.'); +var incsearch = null; + +window.addEventListener('load', function(){ + var text = document.getElementById('text'); + var viewArea = document.getElementById('viewArea'); + var status = document.getElementById('status'); + var sync = document.getElementById('sync'); + var setting = document.getElementById('setting'); + var help = document.getElementById('help'); + var loadingBox = document.getElementById('loadingBox'); + var loadingImage = document.getElementById('loadingImage'); + var loadingMessage = document.getElementById('loadingMessage'); + var pageLinkTop = document.getElementById('pageLinkTop'); + var pageLinkBottom = document.getElementById('pageLinkBottom'); + + var userId = null; + try { + userId = prefBranch.getCharPref("userId"); + } catch(e){ + } + + var numberOfResults = DEFAULT_NUMBER_OF_RESULTS; + try { + numberOfResults = prefBranch.getIntPref("numberOfResults"); + } catch(e){ + } + + var sizeOfInputArea = DEFAULT_SIZE_OF_INPUT_AREA; + try { + sizeOfInputArea = prefBranch.getIntPref("sizeOfInputArea"); + } catch(e){ + } + + text.size = sizeOfInputArea; + + + try { + if (!userId || !database.connection.tableExists('bookmark')) { + if (database.connection.tableExists('bookmark')) { + database.execute("DROP TABLE bookmark"); + } + database.execute(createTableSql); + } + } catch(e) { + + status.innerHTML = e.message || e; + loading.style.display = 'none'; + throw e; + } + + // global + incsearch = new IncSearch( + text, + viewArea, + { + dispMax: numberOfResults, + status: status, + pageLinkTop: pageLinkTop, + pageLinkBottom: pageLinkBottom, + database: database, + userId: userId + } + ); + incsearch.input.focus(); + + var update = function() { + incsearch.input.focus(); + new BookmarkLoader(loadingBox, loadingMessage, database); + }; + + sync.addEventListener('click', update, false); + + // settings + var settingBox = document.getElementById('settingBox'); + var settingSave = document.getElementById('settingSave'); + var settingCancel = document.getElementById('settingCancel'); + var numberOfResultElement = document.getElementById('numberOfResults'); + var sizeOfInputAreaElement = document.getElementById('sizeOfInputArea'); + + var openSetting = function() { + Glayer.showBox(settingBox); + numberOfResultElement.value = incsearch.dispMax; + numberOfResultElement.focus(); + sizeOfInputAreaElement.value = text.size; + }; + + var closeSetting = function() { + Glayer.hideBox(settingBox); + incsearch.input.focus(); + }; + + setting.addEventListener('click', openSetting, false); + + numberOfResultElement.addEventListener( + 'keydown', + function(event) { + if (event.keyCode == 13) { + settingSave.click(); + } + }, + false); + + sizeOfInputAreaElement.addEventListener( + 'keydown', + function(event) { + if (event.keyCode == 13) { + settingSave.click(); + } + }, + false); + + settingSave.addEventListener( + 'click', + function() { + Glayer.hideBox(settingBox); + incsearch.dispMax = parseInt(numberOfResultElement.value) || incsearch.dispMax; + prefBranch.setIntPref('numberOfResults', incsearch.dispMax); + incsearch.input.size = parseInt(sizeOfInputAreaElement.value) || incsearch.input.size; + prefBranch.setIntPref('sizeOfInputArea', incsearch.input.size); + + incsearch.reset(); + incsearch.input.focus(); + }, + false); + + settingCancel.addEventListener('click', closeSetting, false); + + // help + var helpBox = document.getElementById('helpBox'); + var helpClose = document.getElementById('helpClose'); + + var openHelp = function() { + Glayer.showBox(helpBox); + helpClose.focus(); + }; + + var closeHelp = function() { + Glayer.hideBox(helpBox); + incsearch.input.focus(); + }; + + var hideMsgBox = function() { + helpBox.style.display = 'none'; + settingBox.style.display = 'none'; + loadingBox.style.display = 'none'; + + var confirmBox = document.getElementById('glayer_confirm'); + if (confirmBox) { + confirmBox.style.display = 'none'; + } + var alertBox = document.getElementById('glayer_alert'); + if (alertBox) { + alertBox.style.display = 'none'; + } + } + + help.addEventListener('click', openHelp, false); + helpClose.addEventListener('click', closeHelp, false); + + // shortcut + document.addEventListener( + 'keydown', + function(event) { + if (event.ctrlKey) { + switch(event.keyCode) { + case 85: // u (Sync) + hideMsgBox(); + update(); + IncSearch._stopEvent(event); + break; + case 83: // s (Setting) + if (settingBox.style.display == '') { + closeSetting(); + } else { + hideMsgBox(); + openSetting(); + } + IncSearch._stopEvent(event); + break; + case 191: // / (Help) + if (helpBox.style.display == '') { + closeHelp(); + } else { + hideMsgBox(); + openHelp(); + } + IncSearch._stopEvent(event); + break; + default: + break; + } + } + }, + false); + + + if (!userId) update(); + +}, false); + +window.addEventListener('unload', function(){ +if (database.connection.transactionInProgress) database.connection.rollbackTransaction(); +}, false); + + +(function() { + function getContents(aURL){ + var ioService = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + var scriptableStream = Components.classes["@mozilla.org/scriptableinputstream;1"] + .getService(Components.interfaces.nsIScriptableInputStream); + + var channel = ioService.newChannel(aURL, null, null); + var input = channel.open(); + scriptableStream.init(input); + var str = scriptableStream.read(input.available()); + scriptableStream.close(); + input.close(); + return str; + } + + var ios = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + var fileHandler = ios.getProtocolHandler("file") + .QueryInterface(Components.interfaces.nsIFileProtocolHandler); + + // user extension javascript + var userExtJs = Components.classes["@mozilla.org/file/directory_service;1"] + .getService(Components.interfaces.nsIProperties) + .get("ProfD", Components.interfaces.nsIFile); + + userExtJs.append(EXTENSION_NAME); + userExtJs.append(USER_EXT_JS); + + if (!userExtJs.exists()) { + var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"] + .createInstance(Components.interfaces.nsIFileOutputStream); + + foStream.init(userExtJs, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate + + var sample = getContents("chrome://" + EXTENSION_NAME + "/content/" + USER_EXT_JS_SAMPLE); + foStream.write(sample, sample.length); + foStream.close(); + } + + var userExtJsURL = fileHandler.getURLSpecFromFile(userExtJs); + + document.write('<script type="text/javascript" src="'+ userExtJsURL +'"><\/script>'); + + // user stylesheet + var userCss = Components.classes["@mozilla.org/file/directory_service;1"] + .getService(Components.interfaces.nsIProperties) + .get("ProfD", Components.interfaces.nsIFile); + + userCss.append(EXTENSION_NAME); + userCss.append(USER_CSS); + + if (!userCss.exists()) { + var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"] + .createInstance(Components.interfaces.nsIFileOutputStream); + + foStream.init(userCss, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate + + var sample = getContents("chrome://" + EXTENSION_NAME + "/content/" + USER_CSS_SAMPLE); + foStream.write(sample, sample.length); + foStream.close(); + } + + var userCssURL = fileHandler.getURLSpecFromFile(userCss); + + document.write('<link rel="stylesheet" href="' + userCssURL + '" type="text/css" />'); +})();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/loader.js Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,116 @@ +var LoaderBase = function(){}; +LoaderBase.prototype = { + init: function(loadingBox, loadingMessage, database, callback) { + this.loadingBox = loadingBox; + this.loadingMessage = loadingMessage; + this.database = database; + this.callback = callback || function() {}; + + try { + this.insertHandler = new UpdateHandler(this.database, this.insertSql); + } catch(e) { + this.error(e.message || e); + throw e; + } + this.load(); + }, + insertSql: "INSERT INTO bookmark VALUES(:id, :url, :title, :info, :tags, :time, UPPER(:title||' '||:info||' '||:tags))", + truncateSql: 'DELETE FROM bookmark', + + load: function() { + this.dispStart(); + + this.bookmarks = []; + this.total = null; + + this._load(); + }, + dispStart: function() { + Glayer.showBox(this.loadingBox); + this.loadingMessage.innerHTML = 'Bookmarks Loading...'; + }, + dispLoading: function(count) { + this.loadingMessage.innerHTML = 'Bookmarks Loading... ' + count + '/' + this.total; + }, + dispEnd: function(count) { + this.loadingBox.style.display = 'none'; + Glayer.showAlert('Finish!! loaded ' + count + ' bookmarks', {callback: function(){ incsearch.input.focus(); Glayer.hideAlert(); }}); + document.getElementById(Glayer.defaultAlert.okId).focus(); + + incsearch.reset(); + }, + error: function(errMsg) { + this.loadingBox.style.display = 'none'; + + var self = this; + Glayer.showConfirm( + errMsg, + function(result){ + Glayer.hideConfirm(); + if (result) { + self.dispStart(); + self._load(); + } else { + incsearch.input.focus(); + } + }, + {okLabel: 'Retry', cancelLabel: 'cancel'} + ); + document.getElementById(Glayer.defaultConfirm.cancelId).focus(); + + throw errMsg; + }, + + truncate: function() { + this.database.execute(this.truncateSql); + }, + insert: function(bookmark) { + this.insertHandler.execute(bookmark); + }, + + update: function(bookmarks) { + + var self = this; + + var conn = this.database.connection; + try { + conn.beginTransaction(); + this.truncate(); + + for (var i = 0, len = bookmarks.length; i < len; i++) { + if (i % 100 == 0) yield i; + this.insert(bookmarks[i]); + } + + conn.commitTransaction(); + } catch(e) { + conn.rollbackTransaction(); + + this.error(e.message || e); + throw e; + } + } +} + + +var Executer = function(generator, interval, func, callback) { + this.generator = generator; + this.func = func || function(){}; + this.interval = interval; + this.callback = callback; + + var self = this; + this.run = function() { + try{ + self.func(self.generator.next()); + setTimeout(function(){self.run()}, self.interval); + } catch (e) { + if (e instanceof StopIteration) { + self.callback(); + } else { + throw e; + } + } + } +}; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/overlay.xul Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<overlay id="googleBookmarksIncsearchOverlay" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <commandset id="mainCommandSet"> + <command id="googleBookmarksIncsearchCommand" oncommand="open_googleBookmarksIncsearch();"/> + </commandset> + <menupopup id="menu_ToolsPopup"> + <menuitem id="googleBookmarksIncsearchMenuitem" + label="Google Bookmarks IncSearch" + insertbefore="sanitizeSeparator" + key="key_open_googleBookmarksIncsearch" + command="googleBookmarksIncsearchCommand" /> + </menupopup> + <toolbarpalette id="BrowserToolbarPalette"> + <toolbarbutton id="googleBookmarksIncsearchButton" class="toolbarbutton-1" + label="Google Bookmarks IncSearch" tooltiptext="Google Bookmarks IncSearch" + command="googleBookmarksIncsearchCommand" /> + </toolbarpalette> + <keyset id="mainKeyset"> + <key id="key_open_googleBookmarksIncsearch" modifiers="alt" key="i" command="googleBookmarksIncsearchCommand" /> + </keyset> + <script type="application/x-javascript"> + <![CDATA[ + window.addEventListener('load', function() { + + var openKey = document.getElementById('key_open_googleBookmarksIncsearch'); + + var prefSvc = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); + var prefBranch = prefSvc.getBranch('extensions.googlebookmarks_incsearch.'); + + try { + var modifiers = prefBranch.getCharPref('shortcut.open.modifiers'); + openKey.setAttribute('modifiers', modifiers); + } catch(e) {} + + try { + var key = prefBranch.getCharPref('shortcut.open.key'); + openKey.setAttribute('key', key); + } catch(e) {} + + try { + if (prefBranch.getBoolPref('shortcut.open.disabled')) { + openKey.parentNode.removeChild(openKey); + } + } catch(e) {} + + }, false); + + var open_googleBookmarksIncsearch = function() { + var openUrl = 'chrome://googlebookmarks_incsearch/content/view.html'; + var target = null; + + var tabs = gBrowser.tabContainer.childNodes; + + for (var i = 0, len = tabs.length; i < len; i++) { + if (tabs[i].linkedBrowser.currentURI.spec == openUrl) { + target = tabs[i]; + break; + } + } + + if (!target) { + gBrowser.selectedTab = gBrowser.addTab(openUrl); + } else { + gBrowser.selectedTab = target; + target.linkedBrowser.contentDocument.getElementById('text').focus(); + } + } + + ]]> + </script> + +</overlay>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/user-sample.css Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,1 @@ +/* user stylesheet */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/content/view.html Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,120 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <meta http-equiv="Content-Script-Type" content="text/javascript" /> + <link rel="stylesheet" href="./base.css" type="text/css" /> + <link rel="stylesheet" href="./glayer.css" type="text/css" /> + <script type="text/javascript" src="./glayer.js"></script> + <script type="text/javascript" src="./glayer_ex.js"></script> + <script type="text/javascript" src="./database.js"></script> + <script type="text/javascript" src="./incsearch.js"></script> + <script type="application/javascript;version=1.7" src="./loader.js"></script> + <script type="text/javascript" src="./googlebookmarks.js"></script> + <script type="text/javascript" src="./init.js"></script> + <title>Google Bookmarks IncSearch - Firefox Extension</title> + </head> + <body> + <p> + <span id="title" class="title">Google Bookmarks IncSearch</span> + <input id="text" name="pattern" value="" size="80" type="text" /> + <span id="option"> + <a id ="sync" href="javascript:void(0)"><img src="./sync.gif" alt="Sync Bookmarks" />sync</a> + <a id ="setting" href="javascript:void(0)"><img src="./setting.gif" alt="Setting" />setting</a> + <a id ="help" href="javascript:void(0)"><img src="./help.gif" alt="Help" />help</a> + </span> + </p> + <div id="viewHeader"> + <span style="float:right;" id="pageLinkTop"></span> + <span id="status"></span> + </div> + <div id="viewArea"></div> + <div id="viewFooter"> + <div id="pageLinkBottom"></div> + </div> + <div id="footer"><p>© 2007-2008 <a href="http://www.enjoyxstudy.com/firefox/extension/googlebookmarks_incsearch/">Enjoy*Study</a> </p></div> + <div id="loadingBox" class="glayer_box" style="display: none;"> + <p> + <img src="./loader.gif" alt="loading" /> + <span id="loadingMessage"></span> + </p> + </div> + <div id="settingBox" class="glayer_box" style="display: none;"> + <p>Setting</p> + <table> + <tr> + <th>Number of results</th> + <td><input id="numberOfResults" name="numberOfResults" type="text" value="" size="5" /></td> + </tr> + <tr> + <th>Size of input area</th> + <td><input id="sizeOfInputArea" name="sizeOfInputArea" type="text" value="" size="5" /></td> + </tr> + </table> + <div class="buttons"> + <input id="settingSave" type="button" value="Save"/> + <input id="settingCancel" type="button" value="Cancel"/> + </div> + </div> + <div id="helpBox" class="glayer_box_big" style="display: none;"> + <p>Shortcut Keys</p> + <table> + <tr> + <th>[Ctrl]+[Right]</th> + <td>Next page</td> + </tr> + <tr> + <th>[Ctrl]+[Left]</th> + <td>Previous page</td> + </tr> + <tr> + <th>[Ctrl]+[Down]</th> + <td>Next bookmark</td> + </tr> + <tr> + <th>[Ctrl]+[Up]</th> + <td>Previous bookmark</td> + </tr> + <tr> + <th>[Ctrl]+[Enter] or [Ctrl]+[m]</th> + <td>Open bookmark</td> + </tr> + <tr> + <th>[Ctrl]+[e]</th> + <td>Edit bookmark</td> + </tr> + <tr> + <th>[Ctrl]+[u]</th> + <td>Load bookmarks from Google Bookmarks (sync bookmarks)</td> + </tr> + <tr> + <th>[Ctrl]+[s]</th> + <td>Open(Close) setting window</td> + </tr> + <tr> + <th>[Ctrl]+[/]</th> + <td>Show(Close) help (this page)</td> + </tr> + </table> + <br/> + <p>Input Text Pattern for Search</p> + <table> + <tr> + <th>a b</th> + <td>a AND b</td> + </tr> + <tr> + <th>a|b</th> + <td>a OR b</td> + </tr> + <tr> + <th>!a</th> + <td>NOT a</td> + </tr> + </table> + <div class="buttons"> + <input id="helpClose" type="button" value="Close"/> + </div> + </div> + </body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chrome/skin/toolbar-button.css Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,7 @@ +#googleBookmarksIncsearchButton { + list-style-image: url("chrome://googlebookmarks_incsearch/skin/icon-medium.png"); +} + +toolbar[iconsize="small"] #googleBookmarksIncsearchButton { + list-style-image: url("chrome://googlebookmarks_incsearch/skin/icon-small.png"); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/install.rdf Fri Aug 15 01:57:59 2008 +0900 @@ -0,0 +1,27 @@ +<?xml version="1.0"?> + +<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:em="http://www.mozilla.org/2004/em-rdf#"> + + <Description about="urn:mozilla:install-manifest"> + + <em:id>googlebookmarks_incsearch@enjoyxstudy.com</em:id> + <em:type>2</em:type> + <em:version>1.3.5</em:version> + + <em:targetApplication> + <Description> + <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> + <em:minVersion>2.0</em:minVersion> + <em:maxVersion>3.0.*</em:maxVersion> + </Description> + </em:targetApplication> + + <em:name>Google Bookmarks IncSearch</em:name> + <em:description>This extension is a incremental search UI for Google Bookmarks(http://www.google.com/bookmarks/), You can find bookmarks very quickly.</em:description> + <em:creator>onozaty</em:creator> + <em:homepageURL>http://www.enjoyxstudy.com/firefox/extension/googlebookmarks_incsearch/</em:homepageURL> + <em:iconURL>chrome://googlebookmarks_incsearch/skin/icon-large.png</em:iconURL> + </Description> + +</RDF>