// ==UserScript== // @name livedoor Reader with EntryFullText // @namespace http://www.m4i.jp/ // @include http://reader.livedoor.com/reader/* // @version 0.1.0 // ==/UserScript== (function(){ Function.prototype.bind = function() { var __method = this, args = unsafeWindow.Array.from(arguments), object = args.shift(); return function() { return __method.apply(object, args.concat(unsafeWindow.Array.from(arguments))); } } $X = function (exp, context) { if (!context) context = document; var resolver = function (prefix) { var o = document.createNSResolver(context)(prefix); return o ? o : (document.contentType == "text/html") ? "" : "http://www.w3.org/1999/xhtml"; } var exp = document.createExpression(exp, resolver); var result = exp.evaluate(context, XPathResult.ANY_TYPE, null); switch (result.resultType) { case XPathResult.STRING_TYPE : return result.stringValue; case XPathResult.NUMBER_TYPE : return result.numberValue; case XPathResult.BOOLEAN_TYPE: return result.booleanValue; case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: { result = exp.evaluate(context, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); var ret = []; for (var i = 0, len = result.snapshotLength; i < len ; i++) { ret.push(result.snapshotItem(i)); } return ret; } } return null; } var EntryFullText = function(rules) { this.load_cache(); this.rules = rules; this.compiled = false; }; EntryFullText.prototype = { fill_active_item: function() { var item = w.get_active_item(true); if (item) { item.subscribe_id = w.State.last_id; if (this.cache[item.subscribe_id] && this.rules[this.cache[item.subscribe_id]]) { this.extract(item, this.rules[this.cache[item.subscribe_id]]); return; } this.find_feed_url(item, (function(feedlink) { if (this.find_rule(feedlink, item)) return; this.find_redirect_url(feedlink, (function(feedlinks) { for (var i = 0; i < feedlinks.length; i++) { if (this.find_rule(feedlinks[i], item)) return; } }).bind(this)); }).bind(this)); } }, extract: function(item, rule) { GM_xmlhttpRequest({ method: 'get', url: item.link, onload: function(res) { try { if (!(rule.extract instanceof RegExp)) { rule.extract = new RegExp(rule.extract); } var matches = res.responseText.match(rule.extract); if (matches) { var data = {}; rule.extract_capture.forEach(function(capture, i) { data[capture] = matches[i + 1]; }); if (rule.extract_after_hook) { rule.extract_after_hook(data); } if (data.body) { var expr = 'id("item_' + item.item_id + '")//div[@class="body"]'; $X(expr)[0].innerHTML = data.body; } } } catch (e) {} } }); }, find_rule: function(feedlink, item) { if (!this.compiled) this.compile_handle(); for (var rule_id in this.rules) { if (!this.rules.hasOwnProperty(rule_id)) continue; if (this.rules[rule_id].handle.test(feedlink)) { this.cache[item.subscribe_id] = rule_id; this.save_cache(); this.extract(item, this.rules[rule_id]); return true; } } return false; }, find_feed_url: function(item, callback) { var api = new w.API('/api/feed/discover'); discover_feedlink(item.link); //discover_feedlink($X('id("right_body")//h1[1]//a')[0].href); function discover_feedlink(url) { api.post({ url: url }, function(discovereds) { discovereds.some(function(discovered) { if (discovered.subscribe_id == item.subscribe_id) { callback(discovered.feedlink); return true; } }); }); } }, find_redirect_url: function(feed_url, callback) { GM_xmlhttpRequest({ method: 'get', url: feed_url, onload: function(r) { var urls = []; try { var xml = new DOMParser().parseFromString(r.responseText, "application/xml"); var expr = '//*[local-name()="link" and @rel="self"]/@href'; urls = $X(expr, xml.documentElement).map(function(href) { return href.nodeValue; }); } catch (e) {} if (urls.length) callback(urls); } }); }, compile_handle: function() { for (var rule_id in this.rules) { if (!this.rules.hasOwnProperty(rule_id)) continue; try { this.rules[rule_id].handle = new RegExp(this.rules[rule_id].handle); } catch (e) { this.rules[rule_id].handle = /[^\s\S]/; } } this.compiled = true; }, load_cache: function() { eval('this.cache = ' + GM_getValue('cache', '{}') + ';'); }, save_cache: function() { var cache = []; for (var key in this.cache) { if (!this.cache.hasOwnProperty(key)) continue; cache.push('"' + key + '":"' + this.cache[key] + '"'); } GM_setValue('cache', '{' + cache.join(',') + '}'); }, delete_cache: function() { this.cache = {}; this.save_cache(); } }; var rules = {"plaza_rakuten":{"handle":"http://plaza\\.rakuten\\.co\\.jp/[\\w\\-]+/diary/","extract":"
([\\s\\S]*?)
","extract_capture":["body"]},"cnet_japan":{"handle":"http://(feeds\\.feedburner\\.jp/cnet|japan\\.cnet\\.com/news)","extract":"
[\\s\\S]*?(\\d{4}/\\d\\d/\\d\\d \\d\\d:\\d\\d)  [\\s\\S]*?
([\\s\\S]*)
[\\s\\S]*?
","extract_capture":["date","body"]},"extremetech":{"handle":"http://www\\.extremetech\\.com/article","extract":"([\\s\\S]*?)[\\s\\S]*?([\\s\\S]*?)","extract_capture":["title","body"]},"www_nikkeibp":{"handle":"http://www\\.nikkeibp\\.co\\.jp/","extract":"

([\\s\\S]*?)

[\\s\\S]*?([\\s\\S]*?)
","extract_capture":["title","body"]},"kyodo":{"handle":"http://flash24\\.kyodo\\.co\\.jp/","extract":"(
[\\s\\S]*?
)[\\s\\S]*?(
[\\s\\S]*?
)","extract_capture":["title","body"]},"news_com":{"handle":"http://news\\.com\\.com/","extract":"
[\\s\\S]*?
\\s*(

[\\s\\S]*?

)\\s*
","extract_capture":["body"]},"nikkei":{"handle":"http://www\\.nikkei\\.co\\.jp/news/","extract":"(?:)?([\\s\\S]*?)(?:)?([\\s\\S]*?)","extract_capture":["title","body"]},"eweek":{"handle":"http://www\\.eweek\\.com/article","extract":"([\\s\\S]*?)[\\s\\S]*?class=\"Article_Content\"[^>]*?>


([\\s\\S]*?)","extract_capture":["title","body"]},"theinquirer":{"handle":"http://www\\.theinquirer\\.net/\\?article","extract":"([\\s\\S]*?)[\\s\\S]*?

([\\s\\S]*?)
","extract_capture":["title","body"]},"blog_goo_ne_jp":{"handle":"http://blog[\\s\\S]goo[\\s\\S]ne[\\s\\S]jp/[\\s\\S]+","extract":"([\\s\\S]*?)","extract_capture":["body"]},"nytimes":{"handle":"http://www\\.nytimes\\.com/","extract":"
[^<]*?

[^<]*?]*?>([\\s\\S]*?)[^<]*?

[\\s\\S]*?(","extract_capture":["title","body"]},"business-i":{"handle":"http://www\\.business-i\\.jp/news/","extract":"([\\s\\S]*?)[\\s\\S]*?([\\s\\S]*?)","extract_capture":["title","body"]},"itmedia":{"handle":"http://www\\.itmedia\\.co\\.jp/news/articles","extract":"
[\\s\\S]*?

([\\s\\S]*?)

[\\s\\S]*?([\\s\\S]*?)","extract_capture":["title","body"]},"ameblo_jp":{"handle":"http://ameblo\\.jp/[\\s\\S]*?/entry-\\d+\\.html","extract":"
([\\s\\S]*?)","extract_capture":["body"]},"itpro_nikkeibp":{"handle":"http://itpro\\.nikkeibp\\.co\\.jp/","extract":"

([\\s\\S]*?)

[\\s\\S]*?([\\s\\S]*?)","extract_capture":["title","body"]},"usatoday":{"handle":"http://rssfeeds\\.usatoday\\.com/","extract":"([\\s\\S]*?)[\\s\\S]*?
([\\s\\S]*?)]*?>[\\s\\S]*?","extract_capture":["title","body"]},"nikkansports":{"handle":"http://[\\w\\-]+[\\s\\S]nikkansports[\\s\\S]com/\\w+/","extract":"
[\\s\\S]*?

([\\s\\S]*?)

\\s*((?:

|([\\s\\S]*)","extract_capture":["body"]},"kyoto-np":{"handle":"http://www\\.kyoto-np\\.co\\.jp/article\\.php","extract":"([\\s\\S]*?)[\\s\\S]*?([\\s\\S]*?)\\s*\\s*\\s*","extract_capture":["title","body"]},"daily_sports":{"handle":"http://www\\.daily\\.co\\.jp/[\\s\\S]*?\\.shtml","extract":"\\s*(<[\\s\\S]*?)","extract_capture":["body"]},"slashdot_jp":{"handle":"http://slashdot[\\s\\S]jp/[\\s\\S]*?article\\.pl\\?","extract":"(

[\\s\\S]*?
)[\\s\\S]*?(
[\\s\\S]*?
)?","extract_capture":["body","more"]},"kyoko_shimbun_news":{"handle":"http://www\\.f7\\.dion\\.ne\\.jp/~moorend/news/\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\.html$","extract":"([\\s\\S]*?)\u3053\u308c\u306f\u5618\u30cb\u30e5\u30fc\u30b9\u3067\u3059
[\\s\\S]*?
([\\s\\S]*?)","extract_capture":["title","body"]},"linuxjournal":{"handle":"http://www\\.linuxjournal\\.com/article","extract":"

([\\s\\S]*?)

([\\s\\S]*?)
","extract_capture":["title","body"]},"rbbtoday_com":{"handle":"http://www\\.rbbtoday\\.com/news","extract":"

([\\s\\S]*?)

[\\s\\S]*?
[\\s\\S]*?[\\s\\S]*?[\\s\\S]*?","extract_capture":["title","body"]},"japan_linux_com":{"handle":"http://japan\\.linux\\.com/(?:japanlinuxcom|desktop|enterprise|kernel|opensource|security|news)/[\\s\\S]*","extract":"([\\s\\S]*?)","extract_capture":["body"]},"mainichi-msn":{"handle":"http://www\\.mainichi-msn\\.co\\.jp/","extract":"
([\\s\\S]*?)
([\\s\\S]*)

[\\s\\S]*?(\\d{4}\u5e74\\d+\u6708\\d+\u65e5\u3000\\d+\u6642\\d+\u5206)

\\s*[\\s\\S]*?<[\\s\\S]*?>([\\s\\S]*?)<[^>]*?[\\s\\S]*?([\\s\\S]*?)","extract_capture":["title","body"]},"tencount":{"handle":"http://tencount[\\s\\S]blogdb[\\s\\S]jp/\\?","extract":"(?:|)([\\s\\S]*?)(?:|)([\\s\\S]*?)
([\\s\\S]*?)
","extract_capture":["title","body"]},"netkeiba":{"handle":"http://news\\.netkeiba\\.com/","extract":"

\\s*([\\s\\S]*?)\\s*

[\\s\\S]*?
\\s*
\\s*([\\s\\S]*?)

\\s*
(\\d{4}\u5e74\\d{2}\u6708\\d{2}\u65e5)
","extract_capture":["title","body","date"]},"okinawatimes_day":{"handle":"http://www[\\s\\S]okinawatimes[\\s\\S]co[\\s\\S]jp/day/\\d+_\\d+[\\s\\S]html","extract":"
([\\s\\S]*?)
([\\s\\S]*?)","extract_capture":["title","body"]},"bbc":{"handle":"http://news\\.bbc\\.co\\.uk/","extract":"
([\\s\\S]*?)
[\\s\\S]*?([\\s\\S]*?)","extract_capture":["title","body"]},"drecom":{"handle":"http://blog\\.drecom\\.jp/","extract":"
\\s*([\\s\\S]*?)
[\\s\\S]*?
(?:\\s*([\\s\\S]*?))?
","extract_capture":["body","body_more"]},"mycom_journal":{"handle":"http://journal\\.mycom\\.co\\.jp/","extract":"([\\s\\S]*?)","extract_capture":["body"]},"newsforge":{"handle":"http://[\\s\\S]*?\\.newsforge\\.com/article[\\s\\S]pl","extract":"

([\\s\\S]*?)

([\\s\\S]*?)
","extract_capture":["title","body"]},"distrowatch":{"handle":"http://distrowatch\\.com/","extract":"[\\s\\S]*?[^>]*?>([\\s\\S]*?)[\\s\\S]*?]*?>([\\s\\S]*?)","extract_capture":["title","body"]},"theregister":{"handle":"[\\s\\S]*?http://www\\.(theregister|regdeveloper|reghardware|channelregister)\\.co","extract":"
]*?>[\\s\\S]*?(?:
)?

([\\s\\S]*?)

([\\s\\S]*?)(?:
|)","extract_capture":["title","body"]},"osaka_nikkansports":{"handle":"http://osaka\\.nikkansports\\.com/","extract":"([\\s\\S]*)","extract_capture":["body"]},"forbes":{"handle":"http://www\\.forbes\\.com/","extract":"([\\s\\S]*?)([\\s\\S]*?)
","extract_capture":["title","body"]},"yakult":{"handle":"http://sns\\.yakult-swallows\\.co\\.jp/","extract":"

([\\s\\S]*?)

[\\s\\S]*?
([\\s\\S]*?)
","extract_capture":["title","body"]},"japan_zdnet_com":{"handle":"http://japan\\.zdnet\\.com/news","extract":"
[\\s\\S]*?

([\\s\\S]*?)

([\\s\\S]*?)","extract_capture":["title","body"]},"searchenginejournal":{"handle":"http://www\\.searchenginejournal\\.com/","extract":"]*?>]*?>([\\s\\S]*?)[\\s\\S]*?(

<(?:b|strong)>[\\s\\S]*?)

","extract_capture":["title","body"]},"reuters":{"handle":"http://go\\.reuters\\.com/","extract":"
([\\s\\S]*?)
[\\s\\S]*?([\\s\\S]*?)","extract_capture":["title","body"]},"sciam":{"handle":"http://www\\.sciam\\.com/article","extract":"
([\\s\\S]*?)","extract_capture":["title","body"]},"zakzak":{"handle":"http://www\\.zakzak\\.co\\.jp/(?:top|spo|gei)/\\d+","extract":"([\\s\\S]*?)\\r?\\n[\\s\\S]*?([\\s\\S]*?)","extract_capture":["title","body"]},"asahi_com":{"handle":"http://www\\.asahi\\.com/","extract":"
[\\s\\S]*?
([\\s\\S]*?)([\\s\\S]*?)[\\s\\S]*?([\\s\\S]*?)","extract_capture":["title","body"]},"indiesmusic_com":{"handle":"http://www\\.indiesmusic\\.com/itemview\\.asp\\?id=\\d+","extract":"[\\s\\S]*?src=\"/images/itemview_title\\.gif\"[\\s\\S]*?
([\\s\\S]*?)
[\\s\\S]*?([\\s\\S]*?)[\\s\\S]*?
([\\s\\S]*?)
[\\s\\S]*?([\\s\\S]*?
]*? class=\"titleArticle\"[^>]*?>([\\s\\S]*?)\"\"
)","extract_capture":["image","title1","title2","body1","body2"]},"sportsnavi":{"handle":"http://sportsnavi\\.yahoo\\.co\\.jp/[\\s\\S]*/headlines/","extract":"([\\s\\S]*?)[\\s\\S]*?\\[ [\\s\\S]*? (\\d+[\\s\\S]*?) \\]","extract_capture":["body","date"]},"worldtimes":{"handle":"http://www\\.worldtimes\\.co\\.jp/","extract":"

([\\s\\S]*?)

[\\s\\S]*?
([\\s\\S]*?)([\\s\\S]*?)
([\\s\\S]*?)
([\\s\\S]*?)([\\s\\S]*?)
\\s*\\[ (\\d{4}\u5e74\\d\\d\u6708\\d\\d\u65e5\u4ed8|\\d{4}\u5e74\\d\\d\u6708\\d\\d\u65e5 \\d\\d:\\d\\d)","extract_capture":["body","date"]},"ti-da_net":{"handle":"http://[\\s\\S]*?\\.ti-da\\.net/","extract":"
([\\s\\S]*?)
[\\s\\S]*?[\\s\\S]*?[\\s\\S]*?
([\\s\\S]*?)
","extract_capture":["body","body_more"]},"qwik":{"handle":"http://qwik\\.jp","extract":"([\\s\\S]+?)","extract_capture":["body"]},"arstechnica":{"handle":"http://feeds\\.feedburner\\.com/arstechnica/","extract":"

[^>]*?([\\s\\S]*?)[^>]*?

([\\s\\S]*?)

","extract_capture":["title","body"]},"wired_com":{"handle":"http://www\\.wired\\.com/news","extract":"

[\\s\\S]*?

([\\s\\S]*?)

[\\s\\S]*?(

[\\s\\S]*?)

","extract_capture":["title","body"]}}; var eft = new EntryFullText(rules); var w = unsafeWindow; var _onload = w.onload; var onload = function(){ w.Keybind.add('e', eft.fill_active_item.bind(eft)); w.Keybind.add('E', eft.delete_cache.bind(eft)); } w.onload = function(){ _onload(); onload(); } })();