aboutsummaryrefslogtreecommitdiffstats
path: root/access_hatena.js
diff options
context:
space:
mode:
Diffstat (limited to 'access_hatena.js')
-rw-r--r--access_hatena.js108
1 files changed, 64 insertions, 44 deletions
diff --git a/access_hatena.js b/access_hatena.js
index b268bba..93bbf31 100644
--- a/access_hatena.js
+++ b/access_hatena.js
@@ -5,7 +5,7 @@
* @description-ja はてなのサービスに簡単にアクセス
* @minVersion 2.1a1pre
* @author id:masa138, id:hitode909
- * @version 0.5.9
+ * @version 0.6.0
* ==/VimperatorPlugin==
*
* Usage:
@@ -19,18 +19,17 @@
*
*/
(function(){
- var alwaysCollect;
var useWedata;
-
var wedataCache;
var ignoreIds;
var ids;
+ var recentHosts;
+ var maxRecentHostsSize;
+ var historyCompletions;
+ var collectLogSpan;
var pageFor;
var title;
- var new_title_length;
- var old_title_length;
-
- var span;
+ var _old_title_length;
function Title() {
this.initialize.apply(this, arguments);
@@ -38,7 +37,7 @@
Title.prototype = {
initialize: function() {
this.title = [];
- this.count = 0;
+ this.n = 0;
},
key: function(host, id) {
return [host, id.replace('/', '')].join(':');
@@ -47,7 +46,7 @@
var key = this.key(host, id);
if (this.title[key] == null) {
this.title[key] = title;
- this.count++;
+ this.n++;
}
},
get: function(host, id, title) {
@@ -55,25 +54,27 @@
return this.title[this.key(host, id)];
},
length: function() {
- return this.count;
+ return this.n;
}
};
function init() {
- ids = [];
- pageFor = [];
- title = new Title();
- old_title_length = title.length();
+ ids = [];
+ recentHosts = [];
+ historyCompletions = [];
+ pageFor = [];
+ wedataCache = [];
+ title = new Title();
+ _old_title_length = -1;
- span = 7 * 4;
-
- alwaysCollect = liberator.globalVariables.accessHatenaAlwaysCollect;
- useWedata = liberator.globalVariables.accessHatenaUseWedata;
- ignoreIds = liberator.globalVariables.accessHatenaIgnoreIds;
- alwaysCollect = (alwaysCollect != null) ? alwaysCollect : true;
- useWedata = (useWedata != null) ? useWedata : true;
- ignoreIds = (ignoreIds != null) ? ignoreIds : ['login'];
- wedataCache = [];
+ maxRecentHostsSize = liberator.globalVariables.maxRecentHostsSize || 10;
+ collectLogSpan = liberator.globalVariables.collectLogSpan || 24 * 7 * 4 * 60 * 60 * 1000000;
+ alwaysCollect = liberator.globalVariables.accessHatenaAlwaysCollect;
+ useWedata = liberator.globalVariables.accessHatenaUseWedata;
+ ignoreIds = liberator.globalVariables.accessHatenaIgnoreIds;
+ alwaysCollect = (alwaysCollect != null) ? alwaysCollect : false;
+ useWedata = (useWedata != null) ? useWedata : true;
+ ignoreIds = (ignoreIds != null) ? ignoreIds : ['login'];
if (useWedata) {
loadWedata();
@@ -87,46 +88,62 @@
}
init();
- function collectLog() {
- var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsINavHistoryService);
- var options = historyService.getNewQueryOptions();
- var query = historyService.getNewQuery();
+ function prepareSearch() {
+ var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsINavHistoryService);
+ var options = historyService.getNewQueryOptions();
+ var query = historyService.getNewQuery();
query.beginTimeReference = query.TIME_RELATIVE_NOW;
- query.beginTime = -24 * span * 60 * 60 * 1000000;
- query.endTimeReference = query.TIME_RELATIVE_NOW;
- query.endTime = 0;
- query.domain = "hatena.ne.jp";
- var result = historyService.executeQuery(query, options);
- var root = result.root;
+ query.beginTime = -1 * collectLogSpan;
+ query.endTimeReference = query.TIME_RELATIVE_NOW;
+ query.endTime = 0;
+ query.domain = "hatena.ne.jp";
- new_title_length = title.length();
+ return historyService.executeQuery(query, options).root;
+ }
+
+ function collectLog() {
+ var root = prepareSearch();
+ ids = [];
+ recentHosts = [];
+ historyCompletions = [];
+ historyCompletions.h = [];
+ var _title_length = title.length();
root.containerOpen = true;
- ids = [];
for (var i = 0, length = root.childCount; i < length; i++) {
var page = root.getChild(i);
page.uri.match('^https?://([a-zA-Z0-9.]+)\\.hatena\\.ne\\.jp/([a-zA-Z][a-zA-Z0-9_-]{1,30}[a-zA-Z0-9]/?)?');
var host = RegExp.$1;
var id = RegExp.$2;
+ var _recent_hosts_length = recentHosts.length;
if (host != '') {
if (!pageFor[host]) {
pageFor[host] = page;
- }
- if (pageFor[host].uri.length > page.uri.length) {
+ } else if (pageFor[host].uri.length > page.uri.length) {
pageFor[host] = page;
}
+
+ if (_recent_hosts_length < maxRecentHostsSize && recentHosts.indexOf(host) == -1) {
+ recentHosts.push(host);
+ } else if (recentHosts.indexOf(host) == -1 && historyCompletions.h.indexOf(host) == -1) {
+ historyCompletions.push([host, pageFor[host].title]);
+ historyCompletions.h.push(host);
+ }
}
- if (id != '' && !id.match('^(?:' + ignoreIds.join('|') + ')$') && ids.indexOf(id) == -1) {
- ids.push(id);
- if (new_title_length > old_title_length && id.indexOf('/') != -1) {
- if (page.uri.match('^https?://' + host + '\\.hatena\\.ne\\.jp/' + id + '$') && title.get(host, id) != page.title) {
+ if (id != '' && !id.match('^(?:' + ignoreIds.join('|') + ')$')) {
+ if (ids.indexOf(id) == -1) {
+ ids.push(id);
+ }
+ if (_title_length > _old_title_length && id.indexOf('/') != -1) {
+ if (page.uri.match('^https?://' + host + '\\.hatena\\.ne\\.jp/' + id + '/?$') && title.get(host, id) != page.title) {
title.set(host, id, page.title);
}
}
}
}
- old_title_length = new_title_length;
root.containerOpen = false;
+
+ _old_title_length = _title_length;
}
collectLog();
@@ -157,12 +174,15 @@
var id = args[1] ? encodeURIComponent(args[1].toString()).replace('%2F', '/') : '';
var uri = 'http://' + host + '.hatena.ne.jp/' + id;
liberator.open(uri, liberator.CURRENT_TAB);
+ historyCompletions = [];
}, {
completer: function (context, args) {
if (args.length == 1) {
- if (alwaysCollect) collectLog();
context.title = ["Host", "Service"];
- context.completions = [[host, pageFor[host].title] for (host in pageFor) if (pageFor.hasOwnProperty(host))];
+ if (alwaysCollect || historyCompletions.length == 0) {
+ collectLog();
+ }
+ context.completions = [[recentHosts[i], pageFor[recentHosts[i]].title] for (i in recentHosts) if (recentHosts.hasOwnProperty(i))].concat(historyCompletions);
} else if (args.length == 2) {
var host = args[0].toString();
context.title = ["ID", "Page"];