Skip to content

Instantly share code, notes, and snippets.

@azu
Created December 30, 2010 05:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azu/759494 to your computer and use it in GitHub Desktop.
Save azu/759494 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) {
if (ps.type == 'photo') {
return this.Photo.post(ps);
} else {
return this.append(getDataDir(ps.type + '.html'), ps);
}
},
append : function(file, ps) {
var title = convertToPlainText(ps.item);// プレーンテキストに
putContents(file, joinText([
joinText([
'<blockquote cite="'+ps.itemUrl+'" title="'+title+'">',
'<p class="jser-sitelink">',
'<strong>' + title + '</strong><br />',
'<a href="' + ps.itemUrl + '" title="' + title + '">' + ps.itemUrl + '</a>',
'</p>',
'</blockquote>',
'<p>'+joinText([ps.body, ps.description], '\n', false).replace("\n", "<br />") + '</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