Skip to content

Instantly share code, notes, and snippets.

@azu
Created January 16, 2011 01:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azu/781466 to your computer and use it in GitHub Desktop.
Save azu/781466 to your computer and use it in GitHub Desktop.
Tomblooのデータフォルダに年月フォルダ内htmlで記録するパッチ
models.register({
name : 'Local HTML',
ICON : 'chrome://tombloo/skin/local.ico',
check : function(ps) {
return (/(regular|photo|quote|link)/).test(ps.type);
},
post : function(ps) {
function format0(str, len) {
return ('_' + Math.pow(10, len) + str).slice(-len);
}
if (ps.type == 'photo') {
return this.Photo.post(ps);
} else {
// Tombloo/2011/01/index.htmlのような場所に作成
var date = new Date();
var name = 'index.html';
var path = 'file:///' + getPref('dataDir').replace(/\{(.*?)\}/g,
function(all, name) {
return DirectoryService.get(name, IFile).path;
}).replace(/\\/g, '/');
var dir = createDir(date.getFullYear() + '\\' + format0((date.getMonth() + 1), 2), getLocalFile(path));
name && dir.append(name);
return this.append(dir, ps);
}
},
append : function(file, ps) {
var title = convertToPlainText(ps.item);// プレーンテキストに
// utm_*トラッキングコードを取り除く
var itemUrl = ps.itemUrl.replace(/([\?\&]utm_(source|medium|campaign|content)=.+)/ig,'');
putContents(file, joinText([
joinText([
'<blockquote cite="' + itemUrl + '" title="' + title + '">',
'<p class="jser-sitelink">',
'<strong>' + title + '</strong><br />',
'<a href="' + itemUrl + '" title="' + title + '">' + itemUrl + '</a>',
'</p>',
'</blockquote>',
'<p>' + joinText([ps.body, ps.description], '\n', false).replace("\n", "<br />\n", "g") + '</p>'
], "\n"),
getContents(file)
], '\n\n\n'));
/*
<blockquote cite="http://fixingthesejquery.com/#slide1" title="desc">
<p><strong>Fixing These jQuery | adam j. sontag</strong><br />
<a href="http://fixingthesejquery.com/#slide1" title="Fixing These jQuery | adam j. sontag">http://fixingthesejquery.com/#slide1</a></p>
</blockquote>
*/
return succeed();
},
Photo : {
post : function(ps) {
var file = getDataDir('photo');
createDir(file);
if (ps.file) {
file.append(ps.file.leafName);
} else {
var uri = createURI(ps.itemUrl);
var fileName = validateFileName(uri.fileName);
file.append(fileName);
}
clearCollision(file);
return succeed().addCallback(
function() {
if (ps.file) {
ps.file.copyTo(file.parent, file.leafName);
return file;
} else {
return download(ps.itemUrl, file);
}
}).addCallback(function(file) {
if (AppInfo.OS == 'Darwin') {
var script = getTempDir('setcomment.scpt');
putContents(script, [
'set aFile to POSIX file ("' + file.path + '" as Unicode text)',
'set cmtStr to ("' + ps.pageUrl + '" as Unicode text)',
'tell application "Finder" to set comment of (file aFile) to cmtStr'
].join('\n'), 'UTF-16');
var process = new Process(new LocalFile('/usr/bin/osascript'));
process.run(false, [script.path], 1);
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment