aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnaka2009-07-27 22:25:57 +0000
committersnaka2009-07-27 22:25:57 +0000
commit4e2d53d0898a5a4269c7d7f4b2e5b9d7bae3461c (patch)
tree89e6a17d28f48488e83e9f3fd259b27dc5312dad
parentbe414d64322af06f45c2d77469a2a0862786edea (diff)
downloadvimperator-plugins-4e2d53d0898a5a4269c7d7f4b2e5b9d7bae3461c.tar.bz2
Add favicon
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@34653 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r--hateDAopener.js34
1 files changed, 28 insertions, 6 deletions
diff --git a/hateDAopener.js b/hateDAopener.js
index 36305ab..0e80c3b 100644
--- a/hateDAopener.js
+++ b/hateDAopener.js
@@ -89,7 +89,7 @@ plugins.hateDAopener = (function(){
let log = liberator.log;
let dump = function(title, obj) liberator.dump(title + "\n" + util.objectToString(obj));
// \r\n separated string to array
- let rns = function(source) source.split("\r\n");
+ let rns = function(source) source.split(/\r?\n/);
// comma separated string to array
let csv = function(source) source.split(",");
let libly = liberator.plugins.libly;
@@ -99,6 +99,7 @@ plugins.hateDAopener = (function(){
extractTitleAndTags: extractTitleAndTags,
generateCandidates: generateCandidates,
getDiaryEntries: getDiaryEntries,
+ getFaviconURI: getFaviconURI,
};
// }}}
// COMMAND //////////////////////////////////////////////////////////////{{{
@@ -112,7 +113,7 @@ plugins.hateDAopener = (function(){
context.format = {
anchored: false,
title: ["Title and URL", "Tags"],
- keys: { text: "url", name: "name", tags: "tags"},
+ keys: { text: "url", baseUrl: "baseUrl", path: "path", name: "name", tags: "tags"},
process: [templateTitleAndUrl, templateTags]
};
context.filterFunc = null;
@@ -127,10 +128,7 @@ plugins.hateDAopener = (function(){
// }}}
// PRIVATE //////////////////////////////////////////////////////////////{{{
- let cache = {
- data: null,
- userId: null
- };
+ let cache = { };
/**
* @return accounts info
@@ -166,6 +164,7 @@ plugins.hateDAopener = (function(){
* @return [{"url": "(url)", "name": "hogehoge", "tags": "[hoge]"}, ... ]
*/
function generateCandidates() {
+ dump("generateCandidates");
let allEntries = [];
accounts().forEach(function([userId, diary]) {
let entries = getDiaryEntries(userId, diary);
@@ -176,6 +175,8 @@ plugins.hateDAopener = (function(){
[title, tags] = extractTitleAndTags(titleAndTag);
return {
"url" : url,
+ "baseUrl" : 'http://' + diary + '.hatena.ne.jp/' + userId,
+ "path" : path,
"name" : title,
"tags" : tags
};
@@ -191,6 +192,7 @@ plugins.hateDAopener = (function(){
* @return [String dateTime, String path, String titleAndTag]
*/
function getDiaryEntries(userId, diary) {
+ dump("getDalyEntries");
if (cache[diary + userId])
return cache[diary + userId];
@@ -244,7 +246,9 @@ plugins.hateDAopener = (function(){
function templateTitleAndUrl(item){
let simpleURL = item.text.replace(/^https?:\/\//, '');
+ let favicon = getFaviconURI(item.baseUrl + '/');
return <>
+ <img src={favicon} />
<span class="td-strut"/>{item.name}
<a href={item.text} highlight="simpleURL">
<span class="extra-info">{simpleURL}</span>
@@ -252,6 +256,24 @@ plugins.hateDAopener = (function(){
</>;
}
+ let faviconCache = {};
+ function getFaviconURI(pageURI) {
+ if (faviconCache[pageURI])
+ return faviconCache[pageURI];
+ try {
+ let uri = Cc["@mozilla.org/network/io-service;1"]
+ .getService(Ci.nsIIOService)
+ .newURI(pageURI, null, null);
+ let faviconURI = Cc["@mozilla.org/browser/favicon-service;1"]
+ .getService(Ci.nsIFaviconService)
+ .getFaviconImageForPage(uri);
+ return faviconCache[pageURI] = faviconURI.spec;
+ } catch(e) {
+ alert(pageURI);
+ return "";
+ }
+ }
+
// }}}
return self;