// // hatebuWatchDog.js - hatena bookmark watch dog - // // LICENSE: {{{ // // This software distributable under the terms of an MIT-style license. // // Copyright (c) 2009 snaka // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // // OSI page : http://opensource.org/licenses/mit-license.php // Japanese : http://sourceforge.jp/projects/opensource/wiki/licenses%2FMIT_license // // }}} // PLUGIN INFO: {{{ let PLUGIN_INFO = {NAME} Make notify hatebu-count when specified site's hatebu-count changed. 指定されたサイトのはてブ数を監視、変動があったらお知らせします。 2.0pre 2.2pre https://github.com/vimpr/vimperator-plugins/raw/master/hatebuWatchDog.js snaka MIT style license 1.3.0 || :let g:hatebuWatchDogTargets = "http://d.hatena.ne.jp/snaka72/" ||< If you want watch more than one site, you should specify like following. >|| :let g:hatebuWatchDogTargets = "['http://d.hatena.ne.jp/snaka72/', 'http://vimperator.g.hatena.ne.jp/snaka72/']" ||< g:hatebuWatchDogAlways: Boole. Make notify every time. (for debug) Default:false ]]> || :let g:hatebuWatchDogTargets = "http://d.hatena.ne.jp/snaka72/" ||< 監視対象のサイトがが複数の場合は以下のように設定します。 >|| :let g:hatebuWatchDogTargets = "['http://d.hatena.ne.jp/snaka72/', 'http://vimperator.g.hatena.ne.jp/snaka72/']" ||< g:hatebuWatchDogAlways: Boole. 毎回報告を挙げるかどうか。デフォルト:false (主にでバッグ用) == ToDo == - 新着ブックマークのユーザidとコメントの表示 - 監視フレームワークにのっける ]]> ; // }}} // Clear all watchers if started watcher exists. if (plugins.hatebuWatchDog && plugins.hatebuWatchDog.stopWatching) plugins.hatebuWatchDog.stopWatching(); let publics = plugins.hatebuWatchDog = (function() { // PRIVATE //////////////////////////////////////////////////////////////{{{ const libly = plugins.libly; let previousValue = 0; let tasks = []; function getCurrentValue(target, onSuccess, onFailure) { // build hatebu xml-rpc request let req = new libly.Request( 'http://b.hatena.ne.jp/xmlrpc', { 'Content-Type' : 'text/xml' },{ postBody : bookmark.getTotalCount {target} .toXMLString() } ); let currentValue; req.addEventListener("onSuccess", function(data) { liberator.log("XML-RPC request was succeeded."); let resXml = new XML(data.responseText.replace(/^<\?xml version[^>]+?>/, '')); currentValue = window.eval(resXml..int.toString()); onSuccess(currentValue); }); req.addEventListener("onFailure", function(data) { onFailure(); }); liberator.log("reauest..."); req.post(); liberator.log("done..."); } function notifyAlways() window.eval(liberator.globalVariables.hatebuWatchDogAlways) || false; function showHatebuNotification(targetSite, currentValue, delta) { let title = delta >= 0
var PLUGIN_INFO =
<VimperatorPlugin>
    <name>{NAME}</name>
    <description>hatena message notifier</description>
    <description lang="ja">はてなメッセージの変更通知</description>
    <author mail="teramako@gmail.com" homepage="http://vimperator.g.hatena.ne.jp/teramako/">teramako</author>
    <version>0.1</version>
    <license>MPL 1.1/GPL 2.0/LGPL 2.1</license>
    <minVersion>2.0pre</minVersion>
    <maxVersion>2.0pre</maxVersion>
    <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/notifier/subject_hatena_message.js</updateURL>
</VimperatorPlugin>;
//}}}
(function() {

var notifier = liberator.plugins.notifier;
if (!notifier) return;

var libly = notifier.libly;
var $U = libly.$U;
var logger = $U.getLogger('subject_hatena_message');

var URL = 'http://m.hatena.ne.jp';

notifier.subject.register(notifier.SubjectHttp, {
    interval: 60,
    options: {
        url: URL,
        headers: null,
        extra: {}
    },
    preInitialize: function() {
        var [username, password] = $U.getUserAndPassword('https://www.hatena.ne.jp', 'https://www.hatena.ne.jp');
        this.options.extra.username = username;
        this.options.extra.password = password;
        return (username && password) ? true : false;
    },
    parse: function(res)
        res.getHTMLDocument('//table[@class="list"]//tr'),
    diff: function(cache, parsed)
        parsed.filter(function(element)
            !cache.some(function(c) c.textContent == element.textContent)),
    buildMessages: function(diff)
        diff.map($U.bind(this, function(d) {
            var anchor = $U.getFirstNodeFromXPath('descendant::a[@class="message-title"]', d);
            var permalink = URL + (anchor.href ? anchor.href : '');
            var [title, message, date] = [elm.textContent.replace(/^\s+|\s+$/g,'').replace(/>\s+</g,'><') for ([i,elm] in Iterator(d.cells))];
            var html = title + ' (' + date + ')<br/>' + message;
            return new notifier.Message('Hatena::Message', html, permalink);
        }))
});

})();
// vim: set fdm=marker sw=4 ts=4 sts=0 et: