Last active
October 10, 2015 01:08
-
-
Save 958/3608004 to your computer and use it in GitHub Desktop.
[keysnail]FoxAge2ch Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Info | |
var PLUGIN_INFO = | |
<KeySnailPlugin> | |
<name>FoxAge2ch Controller</name> | |
<description>Manipulate FoxAge2ch</description> | |
<description lang="ja">FoxAge2ch を操作</description> | |
<author>958</author> | |
<updateURL>https://gist.github.com/958/3608004/raw/foxage2ch.ks.js</updateURL> | |
<version>0.0.2</version> | |
<license>MIT</license> | |
<minVersion>1.8.0</minVersion> | |
<include>main</include> | |
<detail lang="ja"><![CDATA[ | |
=== これは何 ? === | |
FoxAge2ch を操作します | |
=== 設定 === | |
プロンプトのキーバインドを変更する場合は以下のように plugins.options['foxage2ch.keymap'] を設定してください | |
>|javascript| | |
plugins.options['foxage2ch.keymap'] = { | |
"C-z" : "prompt-toggle-edit-mode", | |
"SPC" : "prompt-next-page", | |
"b" : "prompt-previous-page", | |
"j" : "prompt-next-completion", | |
"k" : "prompt-previous-completion", | |
"g" : "prompt-beginning-of-candidates", | |
"G" : "prompt-end-of-candidates", | |
"D" : "prompt-cancel", | |
// FoxAge2ch Controller specific actions | |
'O' : 'open', | |
'F' : 'find', | |
'D' : 'delete', | |
}; | |
||< | |
=== 謝辞 === | |
以下のスクリプトを流用にしました | |
- Vimperator FoxAge2ch plugin | |
- https://github.com/vimpr/vimperator-plugins/blob/c94cc980c82e20b52ec2af4679130c51b5166228/foxage2ch.js | |
]]></detail> | |
</KeySnailPlugin>; | |
// Options | |
var pOptions = plugins.setupOptions('foxage2ch', { | |
'keymap': { | |
preset: { | |
'O': 'open', | |
'F': 'find', | |
'D': 'delete', | |
}, | |
description: M({ | |
ja: 'スレッド一覧の操作用キーマップ', | |
en: 'Local keymap for manipulation' | |
}) | |
}, | |
'color': { | |
preset: { | |
isNew: 'font-weight:bold;', | |
isOver: 'color:darkorange;', | |
isDead: 'color:red;', | |
isError: 'color:red; font-weight:bold;', | |
}, | |
description: M({ | |
ja: 'スレッド一覧のスタイル色', | |
en: 'Style of thread list', | |
}) | |
}, | |
}, PLUGIN_INFO); | |
// Main | |
var fa = (function () { | |
Components.utils.import('resource://foxage2ch/utils.jsm'); | |
var svc = FoxAge2chUtils.service; | |
var Thread = function (thread) { | |
this._thread = thread; | |
}; | |
Thread.prototype = { | |
open: function () | |
FoxAge2chUtils.service.openItem(this._thread, true, false), | |
delete: function () | |
FoxAge2chUtils.service.removeItem(this._thread), | |
find: function () | |
window.openDialog( | |
'chrome://foxage2ch/content/findThread.xul', | |
'FoxAge2ch:FindThread', | |
'chrome,centerscreen,modal,all', | |
this._thread.id | |
), | |
showInfo: function () | |
window.openDialog( | |
'chrome://foxage2ch/content/showInfo.xul', | |
'FoxAge2ch:ShowInfo', | |
'chrome,centerscreen,modal', | |
this._thread.id | |
), | |
get title() { | |
return this._thread.title; | |
}, | |
get isOver() { | |
return (this._thread.lastRes >= (this._thread.maxRes || 1000)); | |
}, | |
get isNew() { | |
return !!(this._thread.status & FoxAge2chUtils.STATUS_UPDATED); | |
}, | |
get isDead() { | |
return !!(this._thread.status & FoxAge2chUtils.STATUS_DATOUT); | |
}, | |
get isError() { | |
return !!(this._thread.status & FoxAge2chUtils.STATUS_ERROR); | |
}, | |
get readed() { | |
return this._thread.readRes; | |
}, | |
get unread() { | |
return this._thread.lastRes - this._thread.readRes; | |
} | |
}; | |
var self = { | |
get threads() { | |
var result = []; | |
for (let [, board] in Iterator(svc.getChildItems('root', {}))) { | |
if (board.type == FoxAge2chUtils.TYPE_BOARD) | |
Array.prototype.push.apply(result, svc.getChildItems(board.id, {})); | |
} | |
return result.map(function (thread) new Thread(thread)); | |
}, | |
openUpdates: function () | |
svc.openUpdates('root'), | |
checkUpdates: function () | |
svc.checkUpdates('root'), | |
addThread: function (aURL) { | |
var url = FoxAge2chUtils.unwrapURL(aURL); | |
return svc.addFavorite(aURL); | |
}, | |
}; | |
return self; | |
})(); | |
plugins.fosage2ch = fa; | |
// Add exts | |
plugins.withProvides(function (provide) { | |
provide('foxage2ch-show-threads', | |
function () { | |
var collection = fa.threads.map(function (thread) [thread, thread.title, thread.unread, thread.readed]); | |
prompt.selector({ | |
message: 'threads', | |
collection: collection, | |
flags: [HIDDEN|IGNORE, 0, IGNORE, IGNORE], | |
header: ['Title', 'Unread', 'Readed'], | |
width: [80, 20, 20], | |
style: [0, style.prompt.description, style.prompt.description], | |
keymap: pOptions['keymap'], | |
stylist: function(aRow, aColIndex) | |
(aRow[0].isNew ? (pOptions['color'].isNew || '') : '') + | |
(aRow[0].isOver ? (pOptions['color'].isOver || '') : '') + | |
(aRow[0].isDead ? (pOptions['color'].isDead || '') : '') + | |
(aRow[0].isError ? (pOptions['color'].isError || '') : ''), | |
actions: [ | |
[ | |
function (aIndex) collection[aIndex][0].open(), | |
'Open thread', 'open,c' | |
], | |
[ | |
function (aIndex) collection[aIndex][0].find(), | |
'Find thread', 'find' | |
], | |
[ | |
function (aIndex) collection[aIndex][0].delete(), | |
'Delete thread', 'delete' | |
], | |
[ | |
function (aIndex) collection[aIndex][0].showInfo(), | |
'Show information', 'show-info' | |
], | |
[ | |
function (aIndex) fa.checkUpdates(), | |
'Check updates', 'check-updates' | |
], | |
[ | |
function (aIndex) fa.openUpdates(), | |
'Open updates', 'open-updates' | |
], | |
] | |
}); | |
}, | |
'FoxAge2ch - Show threads'); | |
provide('foxage2ch-check-updates', | |
function () fa.checkUpdates(), | |
'FoxAge2ch - Check updates'); | |
provide('foxage2ch-open-updates', | |
function () fa.openUpdates(), | |
'FoxAge2ch - Open updates'); | |
provide('foxage2ch-add-thread', | |
function () { | |
var url = content.location.href; | |
if (fa.addThread(url)) display.echoStatusBar('Added: ' + url, 1000); | |
}, | |
'FoxAge2ch - Add thread'); | |
}, PLUGIN_INFO); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment