はてなキーワード: regexpとは
// ==UserScript==
// @name deny_ega
// @namespace hogehoge
// @include http://b.hatena.ne.jp/*
// ==/UserScript==
var entry_list = document.getElementsByClassName('entry-body');
for (var i = 0; i < entry_list.length; i++) {
var reg = RegExp("http:\/\/blog.livedoor.jp\/ikiradio\/");
var txt = entry_list[i].getElementsByTagName('blockquote')[0].getAttribute('cite');
if(txt.match(reg)) {
entry_list[i].style.display = 'none';
}
}
どうしても、という状況のために。(http://i.hatena.ne.jp/idea/24510、http://i.hatena.ne.jp/idea/24505)
javascript:(function(h,a){if(location.href.match(/(^.+a.hatena.ne.jp).+\/(simple)?/)){var%20s=RegExp.$2,u=RegExp.$1+"/check?url=",x=new%20RegExp("/a\\.[^/]+/"+(s?"go":"map")+"\\?"),y=new%20RegExp("^.+?\\?"+(s?"|\\d{14}$":""),"g"),d=document,l=d.links,i=0,L;while(L=l[i++]){h=L.href;if(h.match(x)&&(!l[i]||l[i++].href.indexOf(u))){a=d.createElement("img");a.src=u+(encodeURIComponent||encodeURI)(h.replace(y,""))+"&robots=1";a.style.display="none";L.parentNode.insertBefore(a,L.nextSibling)}}}})()
全角&を半角&に置換。
imgのsrc=にhttp://a.hatena.ne.jp/checkを呼んでる。表示する必要はないのでdisplay : none。
実行すると、リストされているサイトをhttp://a.hatena.ne.jp/checkに渡し、強制的に更新チェックします。よってアンテナのページが複数にわたる場合は各ページで実行する必要がある。
元のブックマークレット:
http://www.hatena.ne.jp/tool/bookmarklet#antenna
↓
<style type="text/css">dt{float:left;clear:left;width:10em;}</style>
<meta content="charset=Shift_JIS"/>
<script type="text/javascript"></p> <p>window.onload = init;</p> <p>var url = [</p> <p> "<a href="http://www.senkyo.metro.tokyo.jp/h19sangiin/san_kekka/h19san_hkai.html">http://www.senkyo.metro.tokyo.jp/h19sangiin/san_kekka/h19san_hkai.html</a>",</p> <p> "<a href="http://www.senkyo.metro.tokyo.jp/h17shugiin/sokuhou/7kaijyo_s.htm">http://www.senkyo.metro.tokyo.jp/h17shugiin/sokuhou/7kaijyo_s.htm</a>",</p> <p> "<a href="http://www.senkyo.metro.tokyo.jp/h17togisen/sokuhou/2kaijyo_s.htm">http://www.senkyo.metro.tokyo.jp/h17togisen/sokuhou/2kaijyo_s.htm</a>",</p> <p> "<a href="http://www.senkyo.metro.tokyo.jp/data/h16san_hkai.html">http://www.senkyo.metro.tokyo.jp/data/h16san_hkai.html</a>",</p> <p> "<a href="http://www.senkyo.metro.tokyo.jp/data/h15shu_hkai.html">http://www.senkyo.metro.tokyo.jp/data/h15shu_hkai.html</a>",</p> <p> "<a href="http://www.senkyo.metro.tokyo.jp/data/data01_01_03.html">http://www.senkyo.metro.tokyo.jp/data/data01_01_03.html</a>",</p> <p> "<a href="http://www.senkyo.metro.tokyo.jp/data/data01_02_05.html">http://www.senkyo.metro.tokyo.jp/data/data01_02_05.html</a>",</p> <p> "<a href="http://www.senkyo.metro.tokyo.jp/data/data03_04.html">http://www.senkyo.metro.tokyo.jp/data/data03_04.html</a>",</p> <p> "<a href="http://www.senkyo.metro.tokyo.jp/data/data01_05_05.html">http://www.senkyo.metro.tokyo.jp/data/data01_05_05.html</a>"</p> <p>];</p> <p>var base = "<a href="http://www.senkyo.metro.tokyo.jp/data/tokuhyo_23ku/">http://www.senkyo.metro.tokyo.jp/data/tokuhyo_23ku/</a>";</p> <p>var file = ["chiyoda","chuou","minato","shinjyuku","bunkyo",</p> <p> "taitho","sumida","koutho","sinagawa","meguro",</p> <p> "ohta","setagaya","shibuya","nakaono","suginami",</p> <p> "toshima","kita","arakawa","itabashi","nerima",</p> <p> "adachi","katushika","edogawa"];</p> <p>for(var i=0; i<23; i++){</p> <p> url.push(base + file[i] + "\.html");</p> <p>}</p> <p>var id = [</p> <p> "2007 参院比", "2005 衆院比", "2005 都議会", "2004 参院比", "2003 衆院比",</p> <p> "2001 参院比", "2001 都議会", "2000 衆院比", "1998 参院比", "1997 都議会"</p> <p>];</p> <p>var ku = [</p> <p> "千代田","中央","港","新宿","文京",</p> <p> "台東","墨田","江東","品川","目黒",</p> <p> "大田","世田谷","渋谷","中野","杉並",</p> <p> "豊島","北","荒川","板橋","練馬",</p> <p> "足立","葛飾","江戸川"</p> <p>];</p> <p>var regexku = new RegExp("(" + ku.join("|") + ")区");</p> <p>var iframe = [];</p> <p>var data = {};</p> <p>var parse = [ function(){</p> <p> var d = iframe[0].contentWindow.document;</p> <p> var td = d.getElementsByTagName("td");</p> <p> for(var i=0, l=td.length; i<l; i++){</p> <p> if(regexku.test(td[i].firstChild.nodeValue)){</p> <p> for(var j=0, e=td[i]; j<10; j++){</p> <p> e = e.nextSibling;</p> <p> }</p> <p> data[RegExp.$1 + "0"] = e.firstChild.firstChild.nodeValue.replace(/\.\d+/,"");</p> <p> }</p> <p> }</p> <p> show();</p> <p>}, function(){</p> <p> var d = iframe[1].contentWindow.document;</p> <p> var nobr = d.getElementsByTagName("nobr");</p> <p> for(var i=0, l=nobr.length; i<l; i++){</p> <p> if(regexku.test(nobr[i].firstChild.nodeValue)){</p> <p> for(var j=0, e=nobr[i].parentNode; j<4; j++){</p> <p> e = e.nextSibling;</p> <p> }</p> <p> data[RegExp.$1 + "1"] = e.firstChild.nodeValue;</p> <p> }</p> <p> }</p> <p> show();</p> <p>}, function(){</p> <p> var d = iframe[2].contentWindow.document;</p> <p> var nobr = d.getElementsByTagName("nobr");</p> <p> for(var i=0, l=nobr.length; i<l; i++){</p> <p> if(regexku.test(nobr[i].firstChild.nodeValue) && nobr[i].parentNode.tagName == "SPAN"){</p> <p> for(var j=0, e=nobr[i]; j<6; j++){</p> <p> e = e.parentNode;</p> <p> }</p> <p> var e2 = e.nextSibling.nextSibling.firstChild.childNodes[2].firstChild;</p> <p> var k = 0;</p> <p> data[RegExp.$1 + "2"] = 0;</p> <p> while(e2){</p> <p> if(e2.firstChild.firstChild.nodeValue.indexOf("公明党") != -1){</p> <p> data[RegExp.$1 + "2"] += parseInt(e2.parentNode.nextSibling.childNodes[k+2].firstChild.nodeValue.replace(",",""), 10);</p> <p> }</p> <p> e2 = e2.nextSibling;</p> <p> k++;</p> <p> }</p> <p> data[RegExp.$1 + "2"] = int2str(data[RegExp.$1 + "2"]);</p> <p> }</p> <p> }</p> <p> show();</p> <p>}, function(){</p> <p> var d = iframe[3].contentWindow.document;</p> <p> var td = d.getElementsByTagName("td");</p> <p> for(var i=0, l=td.length; i<l; i++){</p> <p> if(regexku.test(td[i].firstChild.nodeValue)){</p> <p> for(var j=0, e=td[i]; j<19; j++){</p> <p> e = e.nextSibling;</p> <p> }</p> <p> data[RegExp.$1 + "3"] = e.firstChild.firstChild.nodeValue.replace(/\.\d+/,"");</p> <p> }</p> <p> }</p> <p> show();</p> <p>}, function(){</p> <p> var d = iframe[4].contentWindow.document;</p> <p> var td = d.getElementsByTagName("td");</p> <p> var regexku2 = /(大田|世田谷|練馬|足立|江戸川)/;</p> <p> for(var i=0, l=td.length; i<l; i++){</p> <p> if(regexku.test(td[i].firstChild.nodeValue)){</p> <p> data[RegExp.$1 + "4"] = td[i].nextSibling.nextSibling.firstChild.nodeValue.replace(/\.\d+/,"");</p> <p> continue;</p> <p> }</p> <p> if(regexku2.test(td[i].firstChild.nodeValue)){</p> <p> data[RegExp.$1 + "4"] = (data[RegExp.$1 + "4"] || 0) </p> <p> + parseInt(td[i].nextSibling.nextSibling.firstChild.nodeValue.replace(",","").replace(/\.\d+/,""));</p> <p> }</p> <p> }</p> <p> for(var j=0; j<5; j++){</p> <p> data[ku[[10,11,19,20,22][j]]+"4"] = int2str(data[ku[[10,11,19,20,22][j]]+"4"]);</p> <p> }</p> <p> show();</p> <p>}, function(){</p> <p> var d = iframe[5].contentWindow.document;</p> <p> var td = d.getElementsByTagName("td");</p> <p> for(var i=0, l=td.length; i<l; i++){</p> <p> if(regexku.test(td[i].firstChild.firstChild.nodeValue)){</p> <p> for(var j=0, e=td[i]; j<10; j++){</p> <p> e = e.nextSibling;</p> <p> }</p> <p> data[RegExp.$1 + "5"] = e.firstChild.firstChild.nodeValue.replace(/\.\d+/,"");</p> <p> }</p> <p> }</p> <p> show();</p> <p>}, function(){</p> <p> var d = iframe[6].contentWindow.document;</p> <p> var td = d.getElementsByTagName("td");</p> <p> for(var i=0, l=td.length; i<l; i++){</p> <p> if(regexku.test(td[i].firstChild.firstChild.nodeValue)){</p> <p> for(var j=0, e=td[i]; j<7; j++){</p> <p> e = e.nextSibling;</p> <p> }</p> <p> data[RegExp.$1 + "6"] = e.firstChild.firstChild.nodeValue.replace(/\.\d+/,"").replace("-","0");</p> <p> }</p> <p> }</p> <p> show();</p> <p>}, function(){</p> <p> var d = iframe[7].contentWindow.document;</p> <p> var td = d.getElementsByTagName("td");</p> <p> for(var i=0, l=td.length; i<l; i++){</p> <p> if(regexku.test(td[i].firstChild.firstChild.nodeValue)){</p> <p> for(var j=0, e=td[i]; j<9; j++){</p> <p> e = e.nextSibling;</p> <p> }</p> <p> data[RegExp.$1 + "7"] = e.firstChild.firstChild.nodeValue;</p> <p> }</p> <p> }</p> <p> show();</p> <p>}, function(){</p> <p> var d = iframe[8].contentWindow.document;</p> <p> var td = d.getElementsByTagName("td");</p> <p> for(var i=0, l=td.length; i<l; i++){</p> <p> if(regexku.test(td[i].firstChild.firstChild.nodeValue)){</p> <p> data[RegExp.$1 + "8"] = int2str(td[i].nextSibling.firstChild.firstChild.firstChild.nodeValue);</p> <p> }</p> <p> }</p> <p> show();</p> <p>}, function(n){ return function(){</p> <p> var d = iframe[n+9].contentWindow.document;</p> <p> var td = d.getElementsByTagName("td");</p> <p> data[ku[n]+"9"] = 0;</p> <p> for(var i=0, l=td.length; i<l; i++){</p> <p> if((((td[i].firstChild || 0).firstChild || 0).nodeValue || "").indexOf("公明") == 0){</p> <p> data[ku[n]+"9"] += parseInt(td[i].parentNode.lastChild.firstChild.firstChild.nodeValue.replace(",",""));</p> <p> }</p> <p> }</p> <p> data[ku[n]+"9"] = int2str(data[ku[n]+"9"]);</p> <p> show();</p> <p>}}];</p> <p>function init(){</p> <p> for(var i=0; i<23; i++){</p> <p> var dl = document.createElement("dl");</p> <p> dl.appendChild(document.createTextNode("\n【" + ku[i] + "区における公明票】\n"));</p> <p> for(var j=0; j<10; j++){</p> <p> var dt = document.createElement("dt");</p> <p> var dd = document.createElement("dd");</p> <p> dt.innerText = id[j];</p> <p> dl.appendChild(dt);</p> <p> dl.appendChild(dd);</p> <p> }</p> <p> document.body.firstChild.appendChild(dl);</p> <p> }</p> <p> for(var i=0; i<32; i++){</p> <p> var e = document.createElement("iframe");</p> <p> iframe[i] = e;</p> <p> e.style.display = "none";</p> <p> if(i<9) var f = parse[i];</p> <p> else var f = parse[9](i-9);</p> <p> e.attachEvent("onload", f);</p> <p> e.src = url[i];</p> <p> document.body.appendChild(e);</p> <p> }</p> <p>}</p> <p>function show(){</p> <p> for(var i=0; i<23; i++){</p> <p> var dl = document.body.firstChild.childNodes[i];</p> <p> for(var j=0; j<10; j++){</p> <p> var dt = dl.childNodes[j*2+1];</p> <p> dt.innerText = id[j] + " " + (data[ku[i]+j] || "");</p> <p> dt.nextSibling.innerText = bar(data[ku[i]+j], j);</p> <p> }</p> <p> }</p> <p>}</p> <p>function int2str(num){</p> <p> return new String(num).split("").reverse().join("").replace(/(\d{3})/g,"$1,").split("").reverse().join("");</p> <p>}</p> <p>function bar(str, flag){</p> <p> str = str || "";</p> <p> if(str == "" || str.length < 5) return "";</p> <p> var num = parseInt(str.match(/\d+/)) + 1;</p> <p> var arrow = (flag == 2 || flag == 6 || flag == 9) ? " ←" : "";</p> <p> var _bar = new Array(num).join("|") + arrow;</p> <p> return _bar;</p> <p>}</p> <p></script>
ふと思い立って昼休みに作った。経過時間別に背景色もつきます。
グループ分けとかしてるとうまく動かないかも。
// ==UserScript== // @name order_home_mymixi // @namespace http://anond.hatelabo.jp/ // @include http://mixi.jp/ // @include http://mixi.jp/home.pl // ==/UserScript== (function() { if (window != window.parent) return; var homeTds = document.evaluate('//div[@id="mymixiList"]//td', document.body, null, 7, null); for (var i = 0; i < homeTds.snapshotLength; i++) homeTds.snapshotItem(i).innerHTML = 'loading...'; GM_xmlhttpRequest({ method: 'GET', url: 'http://mixi.jp/list_friend_simple.pl', onload: function(res) { var friends = []; var bgColor = { '01': '#ffffff', '02': '#fee7c6', '03': '#ffd8a7' }; var div = document.createElement('div'); div.innerHTML = res.responseText; var tds = document.evaluate('//div[@id="friendList"]//td', div, null, 7, null); for (var i = 0; i < tds.snapshotLength; i++) { var td = tds.snapshotItem(i); var klass = td.getAttribute('class'); if (!klass || klass.search(/^iconState(01|02|03)/) == -1) continue; friends.push({ color: bgColor[RegExp.$1], anchor: td.getElementsByTagName('a')[0], name: td.getElementsByTagName('p')[0].innerHTML.replace(/^(.+)\(/, '$1 (') }); } for (var i = 0; i < homeTds.snapshotLength; i++) { var td = homeTds.snapshotItem(i); td.innerHTML = ''; td.style.background = friends[i].color; td.appendChild(friends[i].anchor); var span = document.createElement('span'); span.innerHTML = friends[i].name; td.appendChild(span); } } }); })();
bookmarkletでおk
javascript:s=prompt('Enter word');alert(s+':'+document.body.textContent.match(new RegExp(s,'g')).length)
.
本記事末尾のローカルなkey mappingを実現するコードを改良してプラグインにしました。
↓
Vimperatorでローカルなkey mappingを実現するプラグイン local_mappings.js を書いた。
http://anond.hatelabo.jp/20080826124641
2008-07-14 - やぬすさんとこの日記
http://d.hatena.ne.jp/janus_wel/20080714
→n秒後/前に移動するkey mappingも忘れずに!
Re: autocmd が分からない - hogehoge
http://d.hatena.ne.jp/teramako/20080731/p1
のコードをいじった。
" --- autocmd --- " nicovideo " cでコメント入力、Cでコマンド入力、sでシーク、lでボリューム調整、 " pで停止/再生、mでミュートのon/off、vでコメの表示トグル、zでズーム。 javascript <<EOM liberator.plugins.nicomap = function(){ // no args var list=[ ["p","nicopause"], ["m","nicomute"], ["v","nicomementvisible"], ["z","nicosize"], ["s","nicoseek"], ]; // has args var list2=[ ["c","nicomment"], ["C","nicommand"], ["l","nicovolume"], ["s","nicoseek"], ]; if(buffer.URL.indexOf("http://www.nicovideo.jp/watch") == 0){ for (var j=0; j<list.length; j++){ let i = j; liberator.mappings.addUserMap([1],[list[i][0]],list[i][1], function(){ liberator.execute(list[i][1]); },{ rhs:":"+list[i][1]+"<CR>" } ); } for (var j=0; j<list2.length; j++){ let i = j; liberator.mappings.addUserMap([1],[list2[i][0]],list2[i][1], function(){ liberator.execute('normal :'+list2[i][1]+'<Space>'); },{ rhs:":"+list2[i][1]+"<Space>" } ); } } else { for (var i=0; i<list.length; i++){ liberator.mappings.remove(1,list[i][0]); } for (var i=0; i<list2.length; i++){ liberator.mappings.remove(1,list2[i][0]); } } }; liberator.autocommands.add('LocationChange','.*','js liberator.plugins.nicomap()'); EOM
http://d.hatena.ne.jp/nokturnalmortum/20080802#1217633913
.
現在のマウスカーソル位置でクリックイベント発生するkey mappingを設定できればより快適なんだが・・・。
(「コメントする」ボタンのDOMノードが取得できれば、dispatchEventでいけそうだけど)
" ************* local key mappings **************** javascript <<EOM (function(){ function setlocalmap(obj){ var list = obj.list; var list2 = obj.list2; var exp = obj.exp; if(list.constructor != Array || list2.constructor != Array){ echr("invalid argument: array argument required");return; } if(exp.constructor != RegExp){ echr("invalid argument: regex argument required");return; } if(exp.test(liberator.buffer.URL)){ for (var j=0; j<list.length; j++){ let i = j; liberator.mappings.addUserMap([1],[list[i][0]],list[i][1], function(){ liberator.execute(list[i][1]); },{ rhs:":"+list[i][1]+"<CR>" } ); } for (var j=0; j<list2.length; j++){ let i = j; liberator.mappings.addUserMap([1],[list2[i][0]],list2[i][1], function(){ liberator.execute('normal :'+list2[i][1]+'<Space>'); },{ rhs:":"+list2[i][1]+"<Space>" } ); } } else { for (var i=0; i<list.length; i++){ liberator.mappings.remove(1,list[i][0]); } for (var i=0; i<list2.length; i++){ liberator.mappings.remove(1,list2[i][0]); } } } /** * Add Key Mappings to Specific Web Pages * @param obj : has following properties * list : commands that take no args * list2 : commands that take args * exp : target page's URL (regex) * @see Re: autocmd が分からない - hogehoge * http://d.hatena.ne.jp/teramako/20080731/p1 */ liberator.plugins.addLocalUserMap = function(obj){ liberator.plugins[obj.name + "MapSetter"] = function(){ setlocalmap(obj); } liberator.autocommands.add( 'LocationChange', '.*', 'js liberator.plugins.' + obj.name + 'MapSetter()' ); }; // nicovideo // cでコメント入力、Cでコマンド入力、sでシーク、lでボリューム調整、 // pで停止/再生、mでミュートのon/off、vでコメの表示トグル、zでズーム。 var nicovideo = { name : 'nico', exp : /^http:\/\/www.nicovideo.jp\/watch/, list : [ ["p","nicopause"], ["m","nicomute"], ["v","nicomementvisible"], ["z","nicosize"], ["s","nicoseek"], ], list2 : [ ["c","nicomment"], ["C","nicommand"], ["l","nicovolume"], ["s","nicoseek"], ], }; liberator.plugins.addLocalUserMap(nicovideo); })(); EOM
結局概要表示機能追加した。unsafeWindow使いまくり。大丈夫かいな。
// ==UserScript== // @name Hatena Bookmark Tree Expander // @namespace http://anond.hatelabo.jp/ // @include http://b.hatena.ne.jp/entry/* // ==/UserScript== // <div class="info"> // <ul id="similar_entries" class="bookmarklist"> // <li></li> // </ul> // </div> // <div class="info"> // <ul id="referred_entries" class="bookmarklist"> // <li id="referred-entry-\d+"></li> // </ul> // </div> // <div class="info"> // <ul id="relation_diary" class="bookmarklist"> // <li id="diary-{id}-\d+"></li> // </ul> // </div> (function() { function main() { loadBookmarkCommentViewer(); similar.prototype.rootAppend(); referred.prototype.rootAppend(); } function HBTM(target) { this.target = target; this.targetXPath = "//ul[@id='"+target+"']/li"; this.targetRegExp = new RegExp('<ul id="'+target+'"(.|\\s)*?</ul>'); } HBTM.prototype = { openIcon: '<img width="15" height="15" class="icon" style="opacity: 0.6" src="http://anond.hatelabo.jp/images/common/open.gif"/>', closeIcon: '<img width="15" height="15" class="icon" style="opacity: 0.6" src="http://anond.hatelabo.jp/images/common/close.gif"/>', loadingIcon: '<img width="13" height="13" class="icon" src="http://anond.hatelabo.jp/images/common/loading.gif"/>', commentIcon: function(url) { return '<img class="hatena-bcomment-view-icon" src="http://r.hatena.ne.jp/images/popup.gif" onclick="iconImageClickHandler(this, \''+url+'\', event);">' }, create: function() { this.comment = document.createElement("span"); this.comment.innerHTML = this.commentIcon($X("string(descendant::a/@href)", this.node).value()); this.open = document.createElement("a"); this.open.href = "javascript:void(0)"; this.open.innerHTML = this.openIcon; this.close = document.createElement("a"); this.close.href = "javascript:void(0)"; this.close.innerHTML = this.closeIcon; this.close.style.display = "none"; this.loading = document.createElement("span"); this.loading.innerHTML = this.loadingIcon; this.loading.style.display = "none"; this.node.appendChild(this.comment); this.node.appendChild(document.createTextNode(" ")); this.node.appendChild(this.open); this.node.appendChild(this.close); this.node.appendChild(this.loading); this.open.addEventListener("click", bind(this.openAct, this), false); this.close.addEventListener("click", bind(this.closeAct, this), false); }, openAct: function() { this.open.style.display = "none"; if (this.tree) { this.tree.style.display = "block"; this.close.style.display = "inline"; } else { this.loading.style.display = "inline"; this.load(); } }, closeAct: function() { if (this.tree) { this.tree.style.display = "none"; this.close.style.display = "none"; this.open.style.display = "inline"; } }, load: function() { var url = $X("string(descendant::a[starts-with(@href, '/entry/')]/@href)", this.node).value(); GM_xmlhttpRequest({ method: "GET", url: "http://b.hatena.ne.jp"+url, onload: bind(this.loadCallback, this) }); }, loadCallback: function(result) { var match = result.responseText.match(this.targetRegExp); if (match) { var sandbox = document.createElement("div"); sandbox.innerHTML = match[0].replace(this.target,""); this.tree = sandbox.firstChild; } else { this.tree = document.createElement("ul"); } this.append(); this.loading.style.display = "none"; this.close.style.display = "inline"; }, append: function() { this.tree.style.backgroundColor = "transparent"; this.tree.style.listStyleType = "circle"; this.node.appendChild(this.tree); $X("li", this.tree).each(function(n) { var a = $X("a",n).node(); var c = $X("count(//li/a[@href='"+a.href+"'])").value(); if (c > 1) n.parentNode.removeChild(n); }); $X("li", this.tree).each(bind(function(node){new this.constructor(node)}, this)); }, rootAppend: function() { $X(this.targetXPath).each(bind(function(node){new this.constructor(node)}, this)); } }; function similar(node) { this.node = node; this.create(); } similar.prototype = new HBTM("similar_entries"); similar.prototype.constructor = similar; function referred(node) { this.node = node; this.create(); } referred.prototype = new HBTM("referred_entries"); referred.prototype.constructor = referred; function loadBookmarkCommentViewer() { var head = document.getElementsByTagName("head")[0]; var script = document.createElement("script"); script.type = "text/javascript"; script.src = "http://b.hatena.ne.jp/js/BookmarkCommentViewerAllInOne.1.2.js"; head.appendChild(script); var css = document.createElement("link"); css.rel="stylesheet"; css.href="http://d.hatena.ne.jp/css/base.css"; css.type="text/css"; css.media="all"; head.insertBefore(css, head.firstChild); window.addEventListener("load",function(){ var BCV = unsafeWindow.BookmarkCommentViewer; BCV.options['screenshot'] = true; var asyncCommnetView = BCV.asyncCommnetView; BCV.asyncCommnetView = function(url, onCompleteCallback) { var div = asyncCommnetView(url, function(){ onCompleteCallback.apply(this, arguments); new unsafeWindow.Ten.XHR("http://b.hatena.ne.jp/entry/rss/"+url, {}, function(result) { if (! result.responseText.match(/<description>(.*?)<\/description>/)) return; if (! RegExp.$1) return; // var desc = document.createTextNode("desc: "+RegExp.$1); var desc = document.createElement("li"); desc.appendChild(document.createTextNode("desc: "+RegExp.$1)); div.lastChild.insertBefore(desc,div.lastChild.getElementsByTagName("li")[0]); }); }); return div; }; BCV.asyncCommnetView.origin = asyncCommnetView; }, false); } function bind(f,o) {return function() {return f.apply(o, arguments)}} function $X(xpath, context) { if (!(this instanceof $X)) return new $X(xpath, context); this.xpath = xpath; this.context = context || document; } $X.prototype = { evaluate: function() { var result = document.evaluate(this.xpath, this.context, null, this.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.FIRST_ORDERED_NODE_TYPE: return result.singleNodeValue; } return result; }, node: function() { this.type = XPathResult.FIRST_ORDERED_NODE_TYPE; return this.evaluate(); }, value: function() { this.type = XPathResult.ANY_TYPE; return this.evaluate(); }, each: function(func) { this.type = XPathResult.ORDERED_NODE_SNAPSHOT_TYPE; var result = this.evaluate(); for (var i=0; i<result.snapshotLength; i++) func(result.snapshotItem(i)); } }; main(); })();
YourFileHost で動画再生している時に下の文字をアドレスバーにコピペして、Enterキー押すと簡単にflvファイル落とせるね!
javascript:if(document.body.innerHTML.match(/<param\sname=\"movie\"(.*?)%2526cid%253D(.*?)%2526(.*?)%2526cdnkey%253D(.*?)%2526/)){location.href="http://cdn.yourfilehost.com/unit1/flash8/"+RegExp.$2.substr(0,2)+"/"+RegExp.$2+".flv?key="+decodeURIComponent(RegExp.$4)}else{alert("Failed");}
ブックマークのURLに登録して再生中にそのブックマーク開くと、同じように落とせるしこっちの方が簡単だね。
ブックマークレットってやつだね。
ま、全部試してないけど、これとかは落とせたね。
http://www.yourfilehost.com/media.php?cat=video&file=one_night_stand.wmv
firefoxでしか確認していないけれど、URL、正規表現、XPathで指定できる様にしてみたよ。
// ==UserScript== // @name filter for Hatena::Bookmark // @namespace http://anond.hatelabo.jp/ // @include http://b.hatena.ne.jp/hotentry* // @include http://b.hatena.ne.jp/entrylist* // origin http://anond.hatelabo.jp/20080302214727 // ==/UserScript== (function(){ var itemxpath = "//div[@class='entry']"; function xpathgenURL(url) {return "//div[@class='entry' and descendant::a[starts-with(@href,'"+url+"')]]"} var filters = [ // start with '//' then xpath // moconico douga // {"tag": "div", "name": "entry", "pattern": "nicovideo\.jp"}, "//div[@class='entry' and descendant::a[contains(@href,'nicovideo.jp')]]", /* // tag of "2ch" {"tag": "a", "name": "tag", "pattern": "2ch", "parentNum": HatebuTagParentNum}, {"tag": "a", "name": "tag", "pattern": "\\*2ch", "parentNum": HatebuTagParentNum}, ***/ // start with 'http' then url // 2ch blogs // livedoor // {"tag": "div", "name": "entry", // "pattern": /http:\/\/blog\.livedoor\.jp\/(insidears|dqnplus)\//}, "http://blog.livedoor.jp/insidears/", "http://blog.livedoor.jp/dqnplus/", // {"tag": "div", "name": "entry", // "pattern": /http:\/\/(guideline|alfalfa|news4vip)\.livedoor\.biz\//}, "http://guideline.livedoor.biz/", "http://alfalfa.livedoor.biz/", "http://news4vip.livedoor.biz/", // typeof /regexp/ is function (@firefox) then regexp pattern // fc2 // {"tag": "div", "name": "entry", // "pattern": /http:\/\/(urasoku|news23vip|waranote|vipvipblogblog|netanabe|res2ch|kanasoku|tenkomo)\.blog\d+\.fc2\.com\//}, /http:\/\/(urasoku|news23vip|waranote|vipvipblogblog|netanabe|res2ch|kanasoku|tenkomo)\.blog\d+\.fc2\.com\//, // tag of "neta" // {"tag": "a", "name": "tag", "pattern": "ネタ", "parentNum": HatebuTagParentNum}, "//div[@class='entry' and descendant::a[@class='tag' and string()='ネタ']]", // {"tag": "a", "name": "tag", "pattern": "*ネタ", "parentNum": HatebuTagParentNum}, "//div[@class='entry' and descendant::a[@class='tag' and string()='*ネタ']]", // hatena anonymouse diary // {"tag": "div", "name": "entry", "pattern": /http:\/\/anond\.hatelabo\.jp\//} "http://anond.hatelabo.jp/", ]; for (var i=0; i<filters.length; i++) { var filter = filters[i]; var type = typeof filter; var regexp; var xpath; if (type == "function") { xpath = itemxpath; regexp = filter; } else if (type == "string") { if (filter.match(/^http/)) { xpath = xpathgenURL(filter); } else if (filter.match(/^\/\//)) { xpath = filter; } else { next; } } var removeNodes = document.evaluate(xpath,document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null); for (var j=0; j<removeNodes.snapshotLength; j++) { var node = removeNodes.snapshotItem(j); if (!regexp || node.innerHTML.match(regexp)) { node.parentNode.removeChild(node); } } } })();
ついでに増田版も作ってみたよ。
// ==UserScript== // @name filter for Hatelabo::AnonymousDiary // @namespace http://anond.hatelabo.jp/ // @include http://anond.hatelabo.jp/ // @include http://anond.hatelabo.jp/*?page=* // @exclude http://anond.hatelabo.jp/YourID/* // ==/UserScript== // origin http://anond.hatelabo.jp/20080302214727 (function(){ var itemxpath = "//div[@class='section']"; function xpathgenURL(url) {return "//div[@class='section' and descendant::a[starts-with(@href,'"+url+"')]]"} var filters = [ // start with '//' then xpath "//div[@class='section' and child::h3[starts-with(string(),'■はてなの嫌われ者!')]]", // start with 'http' then url "http://anond.hatelabo.jp/", // typeof /regexp/ is function (@firefox) then regexp pattern /釣り/, ]; for (var i=0; i<filters.length; i++) { var filter = filters[i]; var type = typeof filter; var regexp; var xpath; if (type == "function") { xpath = itemxpath; regexp = filter; } else if (type == "string") { if (filter.match(/^http/)) { xpath = xpathgenURL(filter); } else if (filter.match(/^\/\//)) { xpath = filter; } else { next; } } var removeNodes = document.evaluate(xpath,document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null); for (var j=0; j<removeNodes.snapshotLength; j++) { var node = removeNodes.snapshotItem(j); if (!regexp || node.innerHTML.match(regexp)) { node.parentNode.removeChild(node); } } } })();
http://anond.hatelabo.jp/20071009142256 の人ですが、ごめん、結構適当書いてました。余計な事してました。ぜんぜん確認してませんでした。という事でバグフィクス版。
javascript:l=location;w=window;u=l.pathname;(function(){wd='/product/';st=u.indexOf(wd);if(st==-1){wd='/ASIN/';st=u.indexOf(wd);}if(st==-1){wd='/dp/';st=u.indexOf(wd);}if(st!=-1){asin=u.substring(st+wd.length,st+10+wd.length);if(prompt('Shortest Amazon URL and this open with Hatena','http://www.amazon.co.jp/dp/'+asin)){w.open('http://d.hatena.ne.jp/asin/'+asin,'_blank','');}}else{w.alert('no asin info');}}());
ただ、正規表現使えばもっとシンプルになる。って事で同じ動作を書きなおしてみました。
javascript:(function(){if(location.pathname.match(/\/(product|ASIN|dp)\/(.{10})/)){asin=RegExp.$2;if(prompt('Shortest Amazon URL and this open with Hatena','http://www.amazon.co.jp/dp/'+asin))open('http://d.hatena.ne.jp/asin/'+asin,'_blank')}else{alert('no asin info')}})();
javascript:(function(){if(location.pathname.match(/\/(product|ASIN|dp)\/(.{10})/)){asin=RegExp.$2;if(prompt('Jump this shortest Amazon URL','http://www.amazon.co.jp/dp/'+asin))location.href='http://www.amazon.co.jp/dp/'+asin}else{alert('no asin info')}})();
/* Ten */
if (typeof(Ten) == 'undefined') {
Ten = {};
}
Ten.NAME = 'Ten';
Ten.VERSION = 0.06;
/* Ten.Class */
Ten.Class = function(klass, prototype) {
if (klass && klass.initialize) {
var c = klass.initialize;
} else if(klass && klass.base) {
var c = function() { return klass.base[0].apply(this, arguments) };
} else {
var c = function() {};
}
c.prototype = prototype || {};
c.prototype.constructor = c;
Ten.Class.inherit(c, klass);
if (klass && klass.base) {
for (var i = 0; i < klass.base.length; i++) {
var parent = klass.base[i];
if (i == 0) {
c.SUPER = parent;
c.prototype.SUPER = parent.prototype;
}
Ten.Class.inherit(c, parent);
Ten.Class.inherit(c.prototype, parent.prototype);
}
}
return c;
}
Ten.Class.inherit = function(child,parent) {
for (var prop in parent) {
if (typeof(child[prop]) != 'undefined' || prop == 'initialize') continue;
child[prop] = parent[prop];
}
}
/*
// Basic Ten Classes
**/
/* Ten.JSONP */
Ten.JSONP = new Ten.Class({
initialize: function(uri,obj,method) {
if (Ten.JSONP.Callbacks.length) {
setTimeout(function() {new Ten.JSONP(uri,obj,method)}, 500);
return;
}
var del = uri.match(/\?/) ? '&' : '?';
uri += del + 'callback=Ten.JSONP.callback';
if (!uri.match(/timestamp=/)) {
uri += '&' + encodeURI(new Date());
}
if (obj && method) Ten.JSONP.addCallback(obj,method);
this.script = document.createElement('script');
this.script.src = uri;
this.script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(this.script);
},
addCallback: function(obj,method) {
Ten.JSONP.Callbacks.push({object: obj, method: method});
},
callback: function(args) {
// alert('callback called');
var cbs = Ten.JSONP.Callbacks;
for (var i = 0; i < cbs.length; i++) {
var cb = cbs[i];
cb.object[cb.method].call(cb.object, args);
}
Ten.JSONP.Callbacks = [];
},
MaxBytes: 8000,
Callbacks: []
});
/* Ten.XHR */
Ten.XHR = new Ten.Class({
initialize: function(uri,opts,obj,method) {
if (!uri) return;
this.request = Ten.XHR.getXMLHttpRequest();
this.callback = {object: obj, method: method};
var xhr = this;
var prc = this.processReqChange;
this.request.onreadystatechange = function() {
prc.apply(xhr, arguments);
}
var method = opts.method || 'GET';
this.request.open(method, uri, true);
if (method == 'POST') {
this.request.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
}
var data = opts.data ? Ten.XHR.makePostData(opts.data) : null;
this.request.send(data);
},
getXMLHttpRequest: function() {
var xhr;
var tryThese = [
function () { return new XMLHttpRequest(); },
function () { return new ActiveXObject('Msxml2.XMLHTTP'); },
function () { return new ActiveXObject('Microsoft.XMLHTTP'); },
function () { return new ActiveXObject('Msxml2.XMLHTTP.4.0'); },
];
for (var i = 0; i < tryThese.length; i++) {
var func = tryThese[i];
try {
xhr = func;
return func();
} catch (e) {
//alert(e);
}
}
return xhr;
},
makePostData: function(data) {
var pairs = [];
var regexp = /%20/g;
for (var k in data) {
var v = data[k].toString();
var pair = encodeURIComponent(k).replace(regexp,'+') + '=' +
encodeURIComponent(v).replace(regexp,'+');
pairs.push(pair);
}
return pairs.join('&');
}
},{
processReqChange: function() {
var req = this.request;
if (req.readyState == 4) {
if (req.status == 200) {
var cb = this.callback;
cb.object[cb.method].call(cb.object, req);
} else {
alert("There was a problem retrieving the XML data:\n" +
req.statusText);
}
}
}
});
/* Ten.Observer */
Ten.Observer = new Ten.Class({
initialize: function(element,event,obj,method) {
var func = obj;
if (typeof(method) == 'string') {
func = obj[method];
}
this.element = element;
this.event = event;
this.listener = function(event) {
return func.call(obj, new Ten.Event(event || window.event));
}
if (this.element.addEventListener) {
if (this.event.match(/^on(.+)$/)) {
this.event = RegExp.$1;
}
this.element.addEventListener(this.event, this.listener, false);
} else if (this.element.attachEvent) {
this.element.attachEvent(this.event, this.listener);
}
}
},{
stop: function() {
if (this.element.removeEventListener) {
this.element.removeEventListener(this.event,this.listener,false);
} else if (this.element.detachEvent) {
this.element.detachEvent(this.event,this.listener);
}
}
});
/* Ten.Event */
Ten.Event = new Ten.Class({
initialize: function(event) {
this.event = event;
},
keyMap: {
8:"backspace", 9:"tab", 13:"enter", 19:"pause", 27:"escape", 32:"space",
33:"pageup", 34:"pagedown", 35:"end", 36:"home", 37:"left", 38:"up",
39:"right", 40:"down", 44:"printscreen", 45:"insert", 46:"delete",
112:"f1", 113:"f2", 114:"f3", 115:"f4", 116:"f5", 117:"f6", 118:"f7",
119:"f8", 120:"f9", 121:"f10", 122:"f11", 123:"f12",
144:"numlock", 145:"scrolllock"
}
},{
mousePosition: function() {
if (!this.event.clientX) return;
return Ten.Geometry.getMousePosition(this.event);
},
isKey: function(name) {
var ecode = this.event.keyCode;
if (!ecode) return;
var ename = Ten.Event.keyMap[ecode];
if (!ename) return;
return (ename == name);
},
targetIsFormElements: function() {
var target = this.event.target;
if (!target) return;
var T = (target.tagName || '').toUpperCase();
return (T == 'INPUT' || T == 'SELECT' || T == 'OPTION' ||
T == 'BUTTON' || T == 'TEXTAREA');
},
stop: function() {
var e = this.event;
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
} else {
e.cancelBubble = true;
e.returnValue = false;
}
}
});
/* Ten.DOM */
Ten.DOM = new Ten.Class({
getElementsByTagAndClassName: function(tagName, className, parent) {
if (typeof(parent) == 'undefined') {
parent = document;
}
var children = parent.getElementsByTagName(tagName);
if (className) {
var elements = [];
for (var i = 0; i < children.length; i++) {
var child = children[i];
var cls = child.className;
if (!cls) {
continue;
}
var classNames = cls.split(' ');
for (var j = 0; j < classNames.length; j++) {
if (classNames[j] == className) {
elements.push(child);
break;
}
}
}
return elements;
} else {
return children;
}
},
removeEmptyTextNodes: function(element) {
var nodes = element.childNodes;
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) {
node.parentNode.removeChild(node);
}
}
},
nextElement: function(elem) {
do {
elem = elem.nextSibling;
} while (elem && elem.nodeType != 1);
return elem;
},
prevElement: function(elem) {
do {
elem = elem.previousSibling;
} while (elem && elem.nodeType != 1);
return elem;
},
scrapeText: function(node) {
var rval = [];
(function (node) {
var cn = node.childNodes;
if (cn) {
for (var i = 0; i < cn.length; i++) {
arguments.callee.call(this, cn[i]);
}
}
var nodeValue = node.nodeValue;
if (typeof(nodeValue) == 'string') {
rval.push(nodeValue);
}
})(node);
return rval.join('');
},
onLoadFunctions: [],
loaded: false,
timer: null,
addEventListener: function(event,func) {
if (event != 'load') return;
Ten.DOM.onLoadFunctions.push(func);
Ten.DOM.checkLoaded();
},
checkLoaded: function() {
var c = Ten.DOM;
if (c.loaded) return true;
if (document && document.getElementsByTagName &&
document.getElementById && document.body) {
if (c.timer) {
clearInterval(c.timer);
c.timer = null;
}
for (var i = 0; i < c.onLoadFunctions.length; i++) {
c.onLoadFunctions[i]();
}
c.onLoadFunctions = [];
c.loaded = true;
} else {
c.timer = setInterval(c.checkLoaded, 13);
}
}
});
/* Ten.Style */
Ten.Style = new Ten.Class({
applyStyle: function(elem, style) {
for (prop in style) {
elem.style[prop] = style[prop];
}
}
});
/* Ten.Geometry */
Ten.Geometry = new Ten.Class({
initialize: function() {
if (Ten.Geometry._initialized) return;
var func = Ten.Geometry._functions;
var de = document.documentElement;
if (window.innerWidth) {
func.getWindowWidth = function() { return window.innerWidth; }
func.getWindowHeight = function() { return window.innerHeight; }
func.getXScroll = function() { return window.pageXOffset; }
func.getYScroll = function() { return window.pageYOffset; }
} else if (de && de.clientWidth) {
func.getWindowWidth = function() { return de.clientWidth; }
func.getWindowHeight = function() { return de.clientHeight; }
func.getXScroll = function() { return de.scrollLeft; }
func.getYScroll = function() { return de.scrollTop; }
} else if (document.body.clientWidth) {
func.getWindowWidth = function() { return document.body.clientWidth; }
func.getWindowHeight = function() { return document.body.clientHeight; }
func.getXScroll = function() { return document.body.scrollLeft; }
func.getYScroll = function() { return document.body.scrollTop; }
}
Ten.Geometry._initialized = true;
},
_initialized: false,
_functions: {},
getScroll: function() {
if (!Ten.Geometry._initialized) new Ten.Geometry;
return {
x: Ten.Geometry._functions.getXScroll(),
y: Ten.Geometry._functions.getYScroll()
};
},
getMousePosition: function(pos) {
// pos should have clientX, clientY same as mouse event
if ((navigator.userAgent.indexOf('Safari') > -1) &&
(navigator.userAgent.indexOf('Version/') < 0)) {
return {
x: pos.clientX,
y: pos.clientY
};
} else {
var scroll = Ten.Geometry.getScroll();
return {
x: pos.clientX + scroll.x,
y: pos.clientY + scroll.y
};
}
},
getElementPosition: function(e) {
return {
x: e.offsetLeft,
y: e.offsetTop
};
},
getWindowSize: function() {
if (!Ten.Geometry._initialized) new Ten.Geometry;
return {
w: Ten.Geometry._functions.getWindowWidth(),
h: Ten.Geometry._functions.getWindowHeight()
};
}
});
/* Ten.Position */
Ten.Position = new Ten.Class({
initialize: function(x,y) {
this.x = x;
this.y = y;
},
subtract: function(a,b) {
return new Ten.Position(a.x - b.x, a.y - b.y);
}
});
/*
// require Ten.js
**/
/* Ten.SubWindow */
Ten.SubWindow = new Ten.Class({
initialize: function() {
var c = this.constructor;
if (c.singleton && c._cache) {
return c._cache;
}
var div = document.createElement('div');
Ten.Style.applyStyle(div, Ten.SubWindow._baseStyle);
Ten.Style.applyStyle(div, c.style);
this.window = div;
this.addContainerAndCloseButton();
document.body.appendChild(div);
if (c.draggable) {
this._draggable = new Ten.Draggable(div, this.handle);
}
if (c.singleton) c._cache = this;
return this;
},
_baseStyle: {
color: '#000',
position: 'absolute',
display: 'none',
zIndex: 2,
left: 0,
top: 0,
backgroundColor: '#fff',
border: '1px solid #bbb'
},
style: {
padding: '2px',
textAlign: 'center',
borderRadius: '6px',
MozBorderRadius: '6px',
width: '100px',
height: '100px'
},
handleStyle: {
position: 'absolute',
top: '0px',
left: '0px',
backgroundColor: '#f3f3f3',
borderBottom: '1px solid #bbb',
width: '100%',
height: '30px'
},
containerStyle: {
margin: '32px 0 0 0',
padding: '0 10px'
},
// closeButton: 'close.gif',
closeButton: 'http://s.hatena.com/images/close.gif',
closeButtonStyle: {
position: 'absolute',
top: '8px',
right: '10px',
cursor: 'pointer'
},
_baseScreenStyle: {
position: 'absolute',
top: '0px',
left: '0px',
display: 'none',
zIndex: 1,
overflow: 'hidden',
width: '100%',
height: '100%'
},
screenStyle: {},
showScreen: true,
singleton: true,
draggable: true,
_cache: null
},{
screen: null,
windowObserver: null,
visible: false,
addContainerAndCloseButton: function() {
var win = this.window;
var c = this.constructor;
var div = document.createElement('div');
win.appendChild(div);
Ten.Style.applyStyle(div, c.containerStyle);
this.container = div;
if (c.handleStyle) {
var handle = document.createElement('div');
Ten.Style.applyStyle(handle, c.handleStyle);
win.appendChild(handle);
this.handle = handle;
}
if (c.closeButton) {
var btn = document.createElement('img');
btn.src = c.closeButton;
btn.alt = 'close';
Ten.Style.applyStyle(btn, c.closeButtonStyle);
win.appendChild(btn);
new Ten.Observer(btn, 'onclick', this, 'hide');
this.closeButton = btn;
}
if (c.showScreen) {
var screen = document.createElement('div');
Ten.Style.applyStyle(screen, Ten.SubWindow._baseScreenStyle);
Ten.Style.applyStyle(screen, c.screenStyle);
document.body.appendChild(screen);
this.screen = screen;
new Ten.Observer(screen, 'onclick', this, 'hide');
}
},
show: function(pos) {
pos = (pos.x && pos.y) ? pos : {x:0, y:0};
with (this.window.style) {
display = 'block';
left = pos.x + 'px';
top = pos.y + 'px';
}
if (this.screen) {
with (this.screen.style) {
display = 'block';
left = Ten.Geometry.getScroll().x + 'px';
top = Ten.Geometry.getScroll().y + 'px';
}
}
this.windowObserver = new Ten.Observer(document.body, 'onkeypress', this, 'handleEscape');
this.visible = true;
},
handleEscape: function(e) {
if (!e.isKey('escape')) return;
this.hide();
},
hide: function() {
if (this._draggable) this._draggable.endDrag();
this.window.style.display = 'none';
if (this.screen) this.screen.style.display = 'none';
if (this.windowObserver) this.windowObserver.stop();
this.visible = false;
}
});
/* Ten.Draggable */
Ten.Draggable = new Ten.Class({
initialize: function(element,handle) {
this.element = element;
this.handle = handle || element;
this.startObserver = new Ten.Observer(this.handle, 'onmousedown', this, 'startDrag');
this.handlers = [];
}
},{
startDrag: function(e) {
if (e.targetIsFormElements()) return;
this.delta = Ten.Position.subtract(
e.mousePosition(),
Ten.Geometry.getElementPosition(this.element)
);
this.handlers = [
new Ten.Observer(document, 'onmousemove', this, 'drag'),
new Ten.Observer(document, 'onmouseup', this, 'endDrag'),
new Ten.Observer(this.element, 'onlosecapture', this, 'endDrag')
];
e.stop();
},
drag: function(e) {
var pos = Ten.Position.subtract(e.mousePosition(), this.delta);
Ten.Style.applyStyle(this.element, {
left: pos.x + 'px',
top: pos.y + 'px'
});
e.stop();
},
endDrag: function(e) {
for (var i = 0; i < this.handlers.length; i++) {
this.handlers[i].stop();
}
if(e) e.stop();
}
});
/* Hatena */
if (typeof(Hatena) == 'undefined') {
Hatena = {};
}
/* Hatena.User */
Hatena.User = new Ten.Class({
initialize: function(name) {
this.name = name;
},
getProfileIcon: function(name) {
if (!name) name = 'user';
var pre = name.match(/^[\w-]{2}/)[0];
var img = document.createElement('img');
img.src = 'http://www.hatena.ne.jp/users/' + pre + '/' + name + '/profile_s.gif';
img.alt = name;
img.setAttribute('class', 'profile-icon');
img.setAttribute('width','16px');
img.setAttribute('height','16px');
with (img.style) {
margin = '0 3px';
border = 'none';
verticalAlign = 'middle';
}
return img;
}
}, {
profileIcon: function() {
return Hatena.User.getProfileIcon(this.name);
}
});
/* Hatena.Star */
if (typeof(Hatena.Star) == 'undefined') {
Hatena.Star = {};
}
/*
// Hatena.Star.* classes //
**/
if (window.location && window.location.host.match(/hatena\.com/)) {
Hatena.Star.BaseURL = 'http://s.hatena.com/';
} else {
Hatena.Star.BaseURL = 'http://s.hatena.ne.jp/';
}
Hatena.Star.Token = null;
/* Hatena.Star.User */
Hatena.Star.User = new Ten.Class({
base: [Hatena.User],
initialize: function(name) {
if (Hatena.Star.User._cache[name]) {
return Hatena.Star.User._cache[name];
} else {
this.name = name;
Hatena.Star.User._cache[name] = this;
return this;
}
},
_cache: {}
},{
userPage: function() {
return Hatena.Star.BaseURL + this.name + '/';
}
});
/* Hatena.Star.Entry */
Hatena.Star.Entry = new Ten.Class({
initialize: function(e) {
this.entry = e;
this.uri = e.uri;
this.title = e.title;
this.star_container = e.star_container;
this.comment_container = e.comment_container;
this.stars = [];
this.comments = [];
},
maxStarCount: 11
},{
flushStars: function() {
this.stars = [];
this.star_container.innerHTML = '';
},
bindStarEntry: function(se) {
this.starEntry = se;
for (var i = 0; i < se.stars.length; i++) {
if (typeof(se.stars[i]) == 'number') {
this.stars.push(new Hatena.Star.InnerCount(se.stars[i],this));
} else {
this.stars.push(new Hatena.Star.Star(se.stars[i]));
}
}
if (se.comments && !this.comments.length) {
for (var i = 0; i < se.comments.length; i++) {
this.comments.push(new Hatena.Star.Comment(se.comments[i]));
}
}
this.can_comment = se.can_comment;
},
setCanComment: function(v) {
this.can_comment = v;
},
showButtons: function() {
this.addAddButton();
this.addCommentButton();
},
addAddButton: function() {
if (this.star_container) {
this.addButton = new Hatena.Star.AddButton(this);
this.star_container.appendChild(this.addButton);
}
},
addCommentButton: function() {
if (this.comment_container) {
this.commentButton = new Hatena.Star.CommentButton(this);
this.comment_container.appendChild(this.commentButton.img);
}
},
showStars: function() {
var klass = this.constructor;
// if (this.stars.length > klass.maxStarCount) {
// var ic = new Hatena.Star.InnerCount(this.stars.slice(1,this.stars.length));
// this.star_container.appendChild(this.stars[0]);
// this.star_container.appendChild(ic);
// this.star_container.appendChild(this.stars[this.stars.length - 1]);
// } else {
for (var i = 0; i < this.stars.length; i++) {
this.star_container.appendChild(this.stars[i]);
}
},
showCommentButton: function() {
if (this.can_comment) {
this.commentButton.show();
if (this.comments.length) this.commentButton.activate();
} else {
// this.commentButton.hide();
}
},
addStar: function(star) {
this.stars.push(star);
this.star_container.appendChild(star);
},
addComment: function(com) {
if (!this.comments) this.comments = [];
if (this.comments.length == 0) {
this.commentButton.activate();
}
this.comments.push(com);
},
showCommentCount: function() {
this.comment_container.innerHTML += this.comments.length;
}
});
/* Hatena.Star.Button */
Hatena.Star.Button = new Ten.Class({
createButton: function(args) {
var img = document.createElement('img');
img.src = args.src;
img.alt = img.title = args.alt;
with (img.style) {
cursor = 'pointer';
margin = '0 3px';
padding = '0';
border = 'none';
verticalAlign = 'middle';
}
return img;
}
});
/* Hatena.Star.AddButton */
Hatena.Star.AddButton = new Ten.Class({
base: ['Hatena.Star.Button'],
initialize: function(entry) {
this.entry = entry;
this.lastPosition = null;
var img = Hatena.Star.Button.createButton({
src: Hatena.Star.AddButton.ImgSrc,
alt: 'Add Star'
});
this.observer = new Ten.Observer(img,'onclick',this,'addStar');
this.img = img;
return img;
},
ImgSrc: Hatena.Star.BaseURL + 'images/add.gif'
},{
addStar: function(e) {
this.lastPosition = e.mousePosition();
var uri = Hatena.Star.BaseURL + 'star.add.json?uri=' + encodeURIComponent(this.entry.uri) +
'&title=' + encodeURIComponent(this.entry.title);
if (Hatena.Star.Token) {
uri += '&token=' + Hatena.Star.Token;
}
new Ten.JSONP(uri, this, 'receiveResult');
},
receiveResult: function(args) {
var name = args ? args.name : null;
if (name) {
this.entry.addStar(new Hatena.Star.Star({name: name}));
//alert('Succeeded in Adding Star ' + args);
} else if (args.errors) {
var pos = this.lastPosition;
pos.x -= 10;
pos.y += 25;
var scroll = Ten.Geometry.getScroll();
var scr = new Hatena.Star.AlertScreen();
var alert = args.errors[0];
scr.showAlert(alert, pos);
}
}
});
/* Hatena.Star.CommentButton */
Hatena.Star.CommentButton = new Ten.Class({
base: ['Hatena.Star.Button'],
initialize: function(entry) {
this.entry = entry;
this.lastPosition = null;
var img = Hatena.Star.Button.createButton({
src: Hatena.Star.CommentButton.ImgSrc,
alt: 'Comments'
});
img.style.display = 'none';
this.observer = new Ten.Observer(img,'onclick',this,'showComments');
this.img = img;
},
ImgSrc: Hatena.Star.BaseURL + 'images/comment.gif',
ImgSrcActive: Hatena.Star.BaseURL + 'images/comment_active.gif'
},{
showComments: function(e) {
if (!this.screen) this.screen = new Hatena.Star.CommentScreen();
this.screen.bindEntry(this.entry);
var pos = e.mousePosition();
pos.y += 25;
this.screen.showComments(this.entry, pos);
},
hide: function() {
this.img.style.display = 'none';
},
show: function() {
this.img.style.display = 'inline';
},
activate: function() {
this.show();
this.img.src = Hatena.Star.CommentButton.ImgSrcActive;
}
});
/* Hatena.Star.Star */
Hatena.Star.Star = new Ten.Class({
initialize: function(args) {
if (args.img) {
this.img = args.img;
this.name = this.img.getAttribute('alt');
} else {
this.name = args.name;
var img = document.createElement('img');
img.src = Hatena.Star.Star.ImgSrc;
img.alt = this.name;
with (img.style) {
padding = '0';
border = 'none';
}
this.img = img;
}
new Ten.Observer(this.img,'onmouseover',this,'showName');
new Ten.Observer(this.img,'onmouseout',this,'hideName');
if (this.name) {
this.user = new Hatena.Star.User(this.name);
this.img.style.cursor = 'pointer';
new Ten.Observer(this.img,'onclick',this,'goToUserPage');
}
if (args.count && args.count > 1) {
var c = document.createElement('span');
c.setAttribute('class', 'hatena-star-inner-count');
Ten.Style.applyStyle(c, Hatena.Star.InnerCount.style);
c.innerHTML = args.count;
var s = document.createElement('span');
s.appendChild(img);
s.appendChild(c);
return s;
} else {
return this.img;
}
},
ImgSrc: Hatena.Star.BaseURL + 'images/star.gif'
},{
showName: function(e) {
if (!this.screen) this.screen = new Hatena.Star.NameScreen();
var pos = e.mousePosition();
pos.x += 10;
pos.y += 25;
this.screen.showName(this.name, pos);
},
hideName: function() {
if (!this.screen) return;
this.screen.hide();
},
goToUserPage: function() {
window.location = this.user.userPage();
}
});
/* Hatena.Star.InnerCount */
Hatena.Star.InnerCount = new Ten.Class({
initialize: function(count, e) {
this.count = count;
this.entry = e;
var c = document.createElement('span');
c.setAttribute('class', 'hatena-star-inner-count');
Ten.Style.applyStyle(c, Hatena.Star.InnerCount.style);
c.style.cursor = 'pointer';
c.innerHTML = count;
new Ten.Observer(c,'onclick',this,'showInnerStars');
this.container = c;
return c;
},
style: {
color: '#f4b128',
fontWeight: 'bold',
fontSize: '80%',
fontFamily: '"arial", sans-serif',
margin: '0 2px'
}
},{
showInnerStars: function() {
var url = Hatena.Star.BaseURL + 'entry.json?uri=' +
encodeURIComponent(this.entry.uri);
new Ten.JSONP(url, this, 'receiveStarEntry');
},
receiveStarEntry: function(res) {
var se = res.entries[0];
var e = this.entry;
if (encodeURIComponent(se.uri) != encodeURIComponent(e.uri)) return;
e.flushStars();
e.bindStarEntry(se);
e.addAddButton();
e.showStars();
}
});
/* Hatena.Star.Comment */
Hatena.Star.Comment = new Ten.Class({
initialize: function(args) {
this.name = args.name;
this.body = args.body;
}
},{
asElement: function() {
var div = document.createElement('div');
with (div.style) {
margin = '0px 0';
padding = '5px 0';
borderBottom = '1px solid #ddd';
}
var ico = Hatena.User.getProfileIcon(this.name);
div.appendChild(ico);
var span = document.createElement('span');
with(span.style) {
fontSize = '90%';
}
span.innerHTML = this.body;
div.appendChild(span);
return div;
}
});
/* Hatena.Star.NameScreen */
Hatena.Star.NameScreen = new Ten.Class({
base: [Ten.SubWindow],
style: {
padding: '2px',
textAlign: 'center'
},
containerStyle: {
margin: 0,
padding: 0
},
handleStyle: null,
showScreen: false,
closeButton: null,
draggable: false
},{
showName: function(name, pos) {
this.container.innerHTML = '';
this.container.appendChild(Hatena.User.getProfileIcon(name));
this.container.appendChild(document.createTextNode(name));
this.show(pos);
}
});
/* Hatena.Star.AlertScreen */
Hatena.Star.AlertScreen = new Ten.Class({
base: [Ten.SubWindow],
style: {
padding: '2px',
textAlign: 'center',
borderRadius: '6px',
MozBorderRadius: '6px',
width: '240px',
height: '120px'
},
handleStyle: {
position: 'absolute',
top: '0px',
left: '0px',
backgroundColor: '#f3f3f3',
borderBottom: '1px solid #bbb',
width: '100%',
height: '30px',
borderRadius: '6px 6px 0 0',
MozBorderRadius: '6px 6px 0 0'
}
},{
showAlert: function(msg, pos) {
this.container.innerHTML = msg;
var win = Ten.Geometry.getWindowSize();
var scr = Ten.Geometry.getScroll();
var w = parseInt(this.constructor.style.width) + 20;
if (pos.x + w > scr.x + win.w) pos.x = win.w + scr.x - w;
this.show(pos);
}
});
/* Hatena.Star.CommentScreen */
Hatena.Star.CommentScreen = new Ten.Class({
base: [Ten.SubWindow],
initialize: function() {
var self = this.constructor.SUPER.call(this);
if (!self.commentsContainer) self.addCommentsContainer();
return self;
},
style: {
width: '280px',
height: '280px',
overflowY: 'auto',
padding: '2px',
textAlign: 'center',
borderRadius: '6px',
MozBorderRadius: '6px'
},
handleStyle: {
position: 'absolute',
top: '0px',
left: '0px',
backgroundColor: '#f3f3f3',
borderBottom: '1px solid #bbb',
width: '100%',
height: '30px',
borderRadius: '6px 6px 0 0',
MozBorderRadius: '6px 6px 0 0'
},
containerStyle: {
margin: '32px 0 0 0',
textAlign: 'left',
padding: '0 10px'
},
getLoadImage: function() {
var img = document.createElement('img');
img.src = Hatena.Star.BaseURL + 'images/load.gif';
img.setAttribute('alt', 'Loading');
with (img.style) {
verticalAlign = 'middle';
margin = '0 2px';
}
return img;
}
},{
addCommentsContainer: function() {
var div = document.createElement('div');
with (div.style) {
marginTop = '-3px';
}
this.container.appendChild(div);
this.commentsContainer = div;
},
showComments: function(e, pos) {
var comments = e.comments;
if (!comments) comments = [];
this.commentsContainer.innerHTML = '';
for (var i=0; i<comments.length; i++) {
this.commentsContainer.appendChild(comments[i].asElement());
}
if (e.starEntry && !e.can_comment) {
this.hideCommentForm();
} else {
this.addCommentForm();
}
var win = Ten.Geometry.getWindowSize();
var scr = Ten.Geometry.getScroll();
var w = parseInt(this.constructor.style.width) + 20;
if (pos.x + w > scr.x + win.w) pos.x = win.w + scr.x - w;
this.show(pos);
},
bindEntry: function(e) {
this.entry = e;
},
sendComment: function(e) {
if (!e.isKey('enter')) return;
var body = this.commentInput.value;
if (!body) return;
this.commentInput.disabled = 'true';
this.showLoadImage();
var url = Hatena.Star.BaseURL + 'comment.add.json?body=' + encodeURIComponent(body) +
'&uri=' + encodeURIComponent(this.entry.uri) +
'&title=' + encodeURIComponent(this.entry.title);
new Ten.JSONP(url, this, 'receiveResult');
},
receiveResult: function(args) {
if (!args.name || !args.body) return;
this.commentInput.value = '';
this.commentInput.disabled = '';
this.hideLoadImage();
var com = new Hatena.Star.Comment(args);
this.entry.addComment(com);
this.commentsContainer.appendChild(com.asElement());
},
showLoadImage: function() {
if (!this.loadImage) return;
this.loadImage.style.display = 'inline';
},
hideLoadImage: function() {
if (!this.loadImage) return;
this.loadImage.style.display = 'none';
},
hideCommentForm: function() {
if (!this.commentForm) return;
this.commentForm.style.display = 'none';
},
addCommentForm: function() {
if (this.commentForm) {
this.commentForm.style.display = 'block';
return;
}
var form = document.createElement('div');
this.container.appendChild(form);
this.commentForm = form;
with (form.style) {
margin = '0px 0';
padding = '5px 0';
// borderTop = '1px solid #ddd';
}
//if (Hatena.Visitor) {
// form.appendChild(Hatena.Visitor.profileIcon());
//} else {
// form.appendChild(Hatena.User.getProfileIcon());
//}
var input = document.createElement('input');
input.type = 'text';
with (input.style) {
width = '215px';
border = '1px solid #bbb';
padding = '3px';
}
form.appendChild(input);
this.commentInput = input;
var img = this.constructor.getLoadImage();
this.loadImage = img;
this.hideLoadImage();
form.appendChild(img);
new Ten.Observer(input,'onkeypress',this,'sendComment');
}
});
/* Hatena.Star.EntryLoader */
Hatena.Star.EntryLoader = new Ten.Class({
initialize: function() {
var entries = Hatena.Star.EntryLoader.loadEntries();
this.entries = [];
for (var i = 0; i < entries.length; i++) {
var e = new Hatena.Star.Entry(entries[i]);
e.showButtons();
this.entries.push(e);
}
this.getStarEntries();
},
createStarContainer: function() {
var sc = document.createElement('span');
sc.setAttribute('class', 'hatena-star-star-container');
sc.style.marginLeft = '1px';
return sc;
},
createCommentContainer: function() {
var cc = document.createElement('span');
cc.setAttribute('class', 'hatena-star-comment-container');
cc.style.marginLeft = '1px';
return cc;
},
scrapeTitle: function(node) {
var rval = [];
(function (node) {
if (node.tagName == 'SPAN' &&
(node.className == 'sanchor' ||
node.className == 'timestamp')) {
return;
} else if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) {
return;
}
var cn = node.childNodes;
if (cn) {
for (var i = 0; i < cn.length; i++) {
arguments.callee.call(this, cn[i]);
}
}
var nodeValue = node.nodeValue;
if (typeof(nodeValue) == 'string') {
rval.push(nodeValue);
}
})(node);
return rval.join('');
},
headerTagAndClassName: ['h3',null],
getHeaders: function() {
var t = Hatena.Star.EntryLoader.headerTagAndClassName;
return Ten.DOM.getElementsByTagAndClassName(t[0],t[1],document);
},
loadEntries: function() {
var entries = [];
//var headers = document.getElementsByTagName('h3');
var c = Hatena.Star.EntryLoader;
var headers = c.getHeaders();
for (var i = 0; i < headers.length; i++) {
var header = headers[i];
var a = header.getElementsByTagName('a')[0];
if (!a) continue;
var uri = a.href;
var title = '';
// Ten.DOM.removeEmptyTextNodes(header);
var cns = header.childNodes;
title = c.scrapeTitle(header);
var cc = c.createCommentContainer();
header.appendChild(cc);
var sc = c.createStarContainer();
header.appendChild(sc);
entries.push({
uri: uri,
title: title,
star_container: sc,
comment_container: cc
});
}
return entries;
}
},{
getStarEntries: function() {
var url = Hatena.Star.BaseURL + 'entries.json?';
for (var i = 0; i < this.entries.length; i++) {
if (url.length > Ten.JSONP.MaxBytes) {
new Ten.JSONP(url, this, 'receiveStarEntries');
url = Hatena.Star.BaseURL + 'entries.json?';
}
url += 'uri=' + encodeURIComponent(this.entries[i].uri) + '&';
}
new Ten.JSONP(url, this, 'receiveStarEntries');
},
receiveStarEntries: function(res) {
var entries = res.entries;
if (!entries) entries = [];
for (var i = 0; i < this.entries.length; i++) {
var e = this.entries[i];
for (var j = 0; j < entries.length; j++) {
var se = entries[j];
if (!se.uri) continue;
if (encodeURIComponent(se.uri) == encodeURIComponent(e.uri)) {
e.bindStarEntry(se);
entries.splice(j,1);
break;
}
}
if (typeof(e.can_comment) == 'undefined') {
e.setCanComment(res.can_comment);
}
e.showStars();
e.showCommentButton();
}
}
});
/* Hatena.Star.WindowObserver */
Hatena.Star.WindowObserver = new Ten.Class({
initialize: funct
http://anond.hatelabo.jp/20070522023230
<html> <head> <title>Test</title> <script> dayString = new Array('<font color="#ff0000">日</font>','月','火','水','木','金','<font color="#0000ff">土</font>'); function init() { h1s = document.getElementsByTagName("h1"); for(var i=0; i < h1s.length; i++) { var h1 = h1s[i]; if (h1.innerHTML.match(/([0-9]+)年([0-9]+)月([0-9]+)日/)) { var yy = RegExp.$1; var mm = RegExp.$2; var dd = RegExp.$3; var day = new Date(yy,mm-1,dd).getDay(); h1.innerHTML = yy+"年"+mm+"月"+dd+"日("+dayString[day]+")"; } } } </script> </head> <body onload="init()"> <h1>2007年05月10日</h1> <h1>2007年05月18日</h1> <h1>2007年05月19日</h1> <h1>2007年05月20日</h1> </body>
素人なのでよくわからないぜ。
追記: バグっていたので直しました。ごめん。 > http://anond.hatelabo.jp/20070522034339
以下の二つに留意、つまり乱用禁止。
取説未満
// ==UserScript== // @name anond pickup of the day // @namespace http://anond.hatelabo.jp/ // @description pickup section of the day at Hatelabo::AnonymousDiary // @include http://anond.hatelabo.jp/2* // ==/UserScript== (function(){ var trackbackThreshold = 10; var ignoreList = { "/20070801172335": 33, "/20070806163721": 10, }; // only section of the day if (! location.pathname.match(/^\/\d{8}$/)) { return; } // regist ancher that kick main routine var a = document.createElement("a"); a.href = "#"; a.innerHTML = "pickup of the day"; a.addEventListener("click", grab, false); var firstPager_l = document.evaluate("//div[@class='pager-l']",document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue; firstPager_l.appendChild(a); function Outline() { this.outline = document.createElement("ul"); this.text = document.createElement("textarea"); this.text.style.overflow = "auto"; this.text.style.width = "100%"; this.text.style.height = "15em"; this.text.innerHTML = "</ul><\n><ul>\n"; this.list = new Array(); } Outline.prototype.setup = function() { var parent = document.getElementById("body"); parent.insertBefore(this.outline, parent.firstChild); parent.insertBefore(this.text, parent.firstChild); } Outline.prototype.append = function(section) { var h3 = section.getElementsByTagName("h3")[0]; var sectionName = h3.firstChild.pathname.replace(/\//,""); var sectionText = h3.textContent.replace(/\s*$/,""); if (sectionText == "\u25a0") { sectionText = sectionName; } this.text.innerHTML += '<h2>[http://anond.hatelabo.jp/'+sectionName+ ":title="+sectionText.replace(/^\u25a0/,"").replace(/]/g,"&#93;")+"] "+ '<a href="http://b.hatena.ne.jp/entry/http://anond.hatelabo.jp/'+sectionName+'">'+ '<img src="http://b.hatena.ne.jp/entry/image/http://anond.hatelabo.jp/'+sectionName+'">'+ "</a></h2>\n"; h3.firstChild.name = sectionName; var li = document.createElement("li"); li.innerHTML = '<a href="#'+sectionName+'">' + sectionText.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">") + "</a>"; var nextSibling = 0; for (var i in this.list) { if (nextSibling < i && i < sectionName) { nextSibling = i; } } if (nextSibling) { this.outline.insertBefore(li, this.list[nextSibling]); } else { this.outline.appendChild(li); } this.list[sectionName] = li; } var outline = new Outline(); function CC(day) { this.li = document.createElement("li"); this.li.innerHTML = '<a href="/'+day+'" target="_blank">' + day + "</a>"; this.day = day; this.n = new Array(); } CC.prototype.pp = function(id) { this.n.push(id); if (this.n.length > 10) { this.li.innerHTML = '<a href="/'+this.day+'" target="_blank">' + this.day + "</a> " + this.n.length; } else { this.li.innerHTML += ' <a href="/'+id+'" target="_blank">*</a>'; } } function Count() { this.count = document.createElement("ul"); this.list = new Array(); } Count.prototype.setup = function() { var parent = document.getElementById("body"); parent.insertBefore(this.count, parent.firstChild); } Count.prototype.append = function(day, id) { var nextSibling = 0; for (var i in this.list) { if (nextSibling < i && i <= day) { nextSibling = i; } } if (nextSibling == day) { this.list[nextSibling].pp(id); } else { var cc = new CC(day); if (nextSibling) { this.count.insertBefore(cc.li, this.list[nextSibling].li); } else { this.count.appendChild(cc.li); } this.list[day] = cc; cc.pp(id); } } Count.prototype.appendSection = function(section) { var id = section.getElementsByTagName("h3")[0].firstChild.pathname.replace(/\//,""); var today = id.match(/\d{8}/)[0]; var anchors = section.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) { if (anchors[i].href && anchors[i].host == "anond.hatelabo.jp" && anchors[i].pathname.match(/\/(\d{8})\d{6}/) && RegExp.$1 != today) { this.append(RegExp.$1, id); } } } var count = new Count(); function Hide(){} Hide.prototype.setup = function() { this.style = document.createElement("style"); this.style.id = "hide"; this.style.type = "text/css"; document.getElementsByTagName("head")[0].appendChild(this.style); var self = this; this.a = new Object(); this.a.visible = document.createElement("a"); this.a.visible.id = "visible"; this.a.visible.href = "#"; this.a.visible.innerHTML = "visible hide section"; // this.a.visible.setAttribute("onclick","document.getElementById('hide').innerHTML = 'div.hide {display: block}';document.getElementById('visible').style.display = 'none';document.getElementById('unvisible').style.display = 'inline';"); this.a.visible.addEventListener("click", function(){self.visible()}, false); firstPager_l.parentNode.insertBefore(this.a.visible, firstPager_l); this.a.unvisible = document.createElement("a"); this.a.unvisible.id = "unvisible"; this.a.unvisible.href = "#"; this.a.unvisible.innerHTML = "unvisible hide section"; // this.a.visible.setAttribute("onclick","document.getElementById('hide').innerHTML = 'div.hide {display: none}';document.getElementById('visible').style.display = 'inline';document.getElementById('unvisible').style.display = 'none';"); this.a.unvisible.addEventListener("click", function(){self.unvisible()}, false); firstPager_l.parentNode.insertBefore(this.a.unvisible, firstPager_l); this.unvisible(); } Hide.prototype.visible = function() { this.style.innerHTML = "div.hide {display: block}"; this.a.visible.style.display = "none"; this.a.unvisible.style.display = "inline"; } Hide.prototype.unvisible = function() { this.style.innerHTML = "div.hide {display: none}"; this.a.visible.style.display = "inline"; this.a.unvisible.style.display = "none"; } Hide.prototype.append = function(section) { if (section.className.match(/hide/)) { return; } section.className += " hide"; count.appendSection(section); } Hide.prototype.is = function(section) { return section.className.match(/hide/); } var hide = new Hide(); // main routine function grab(){ if (! document.body.innerHTML.match(/<div class="pager-r">(\d+)/)) { return; } var pages = RegExp.$1 -0; if (pages <= 0 || pages > 40) { // check error and limit 1000 entry return; } //pages = 2; firstPager_l.style.display = "none"; outline.setup(); hide.setup(); count.setup(); var mainbody = document.evaluate("//div[@class='body']", document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue; mainbody.innerHTML = "\n"; for (var i=1; i<=pages; i++) { cat(mainbody, i); } } // page load and concatenate function cat(container, page) { container.innerHTML += "<!-- page " + page + " -->\n"; GM_xmlhttpRequest({ method: "GET", url: "http://anond.hatelabo.jp" + location.pathname + "?page=" + page, onload: function(result) { result.responseText.match(/<div class="body">((.|\s)*?)\s*<\/div>\s*<\/div>\s*<div class="pager-l">/); container.innerHTML = container.innerHTML.replace("<!-- page " + page + " -->", RegExp.$1); if (! container.innerHTML.match(/<!-- page \d+ -->/)) { // document.documentElement.innerHTML = document.documentElement.innerHTML.replace(/(src|href)=\"\//mg, "$1=\"http://anond.hatelabo.jp/"); pickup(); } } }); } // pickup section at last cat() concatenate after function pickup() { var target = document.evaluate( "//div[@class='section' and child::*[not(@class='sectionfooter') and descendant::a[starts-with(@href,'http://anond.hatelabo.jp/2') or starts-with(@href,'/2') and not(child::span[@class='sanchor'])]]]", document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null); for (var i=0; i<target.snapshotLength; i++) { hide.append(target.snapshotItem(i)); } var tbs = document.evaluate( "//p[@class='sectionfooter']/a[2]", document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null); for (var i=0; i<tbs.snapshotLength; i++) { var tb = tbs.snapshotItem(i); if (tb.innerHTML == "\u30c8\u30e9\u30c3\u30af\u30d0\u30c3\u30af(0)") { hide.append(tb.parentNode.parentNode); } else if (! hide.is(tb.parentNode.parentNode)) { trackback(tb); } } } // count trackbacks function trackback(tb) { GM_xmlhttpRequest({ method: "GET", url: "http://anond.hatelabo.jp/" + tb.pathname.match(/\d{14}/), onload: function(result) { var link = result.responseText.match(/<a name="tb">(.|\s)*/)[0].match(/<li>\s*<a href="http:\/\/anond.hatelabo.jp\/\d{14}"/g); var n = link.length; for (var l in link) { var m = "/" + link[l].match(/\d{14}/); if (m in ignoreList) { n -= ignoreList[m]; } } if (n < trackbackThreshold) { hide.append(tb.parentNode.parentNode); } else { tb.innerHTML = tb.innerHTML.replace(/\)$/, "/"+n+")"); outline.append(tb.parentNode.parentNode); } } }); } })();