その変数に'apple'とか'banana'とかが入ってるかどうかを判別するっていうロジックを作るときに
const re = new RegExp("apple") if(re.test(str)) console.log("match")
みたいなサンプルコードを見つけてきて
const re_apple = new RegExp("apple") const re_banana = new RegExp("banana") if ( re_apple.test(str) || re_banana.test(str) ) console.log("match")
っていうコードを書く人がおるんよ
別にプログラミング初めて3ヶ月の初心者じゃ無くて20年以上やってるようなベテランだったり
なんならチーフプログラマーとして若手指導してるような人でもこういうレベルの人って割といるわけ
これに対して
「正規表現でORを書くべき」
「includeで十分」
とかいう指摘ももちろん正しいんだけど
綺麗にコードを書くっていうのは
「これってappleとかbanana以外に増えたりしないの?」
「fruitsかどうかを判別するならその変数を作った方が良くない?」
っていうのを考えて実装するのが綺麗にコードを書くっていうことで
変数名だとか整形とかは大事だけどそういう話じゃ無いんだよね
ちなみに
「正規表現でORを書きましょう」
とかをPRのレビューでコメントしても
「動いてるからいいじゃない」
「綺麗に書いても性能上意味ない」
「言ってることが良く分からない。何が違うのか」
とか言ってくるし
言ってこなくて言われた通りに直しても次もまた同じことしてくるのでマジでレビューって大変だよ
]]>で動くスクリプトでたとえば投稿後10分以内にブクマされページに乗ったら「1 user」が「1 user セルクマ 1とか5(何分後にブクマされたか)」になる。もしマイナスなら誤判定なので無視して。
時間を置いたセルクマには効かないし普通のファーストブクマカがどれぐらいの頻度で確認してるかしらないけど5分以内や1分以内もポロポロあるのでまあ目安に。
増田のURLと一覧の時刻表示の差分を取ってます。
増田じゃpre記法でも記号が変換されるみたいだから手作業で
.forEach(div => {
('.entrylist-contents-title > a')
if(diffSec >
とかの
<>
を
<>
に変えてね
他にも見落としあるかも
誤判定が減るから非公開ファーストブクマを判定できたらいいんだけどね。
// ==UserScript==
// @name hatebu masuda selkmark
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 特定時間以内にブクマされた増田を強調する
// @author You
// @match https://b.hatena.ne.jp/site/anond.hatelabo.jp*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const threshold = 60 * 10 // 何秒以内か
const domain = 'https://anond.hatelabo.jp/'
const dateTemplate = '202301020304' // 時分まで urlの時刻表記
const dateTest = new RegExp('\\d{' + dateTemplate.length + '}')
document.querySelectorAll('div.entrylist-contents').forEach(div => {
const masuda = div.querySelector('.entrylist-contents-title > a')
const dateStr = masuda.href.substring(domain.length + dateTemplate.length, domain.length)
if (!dateTest.test(dateStr)) {
// キーワードとか
console.log('not diary', dateStr)
return
}
// new Dateできるように変換
// https://amateur-engineer.com/javascript-date-yyyymmddhhmm/
const year = parseInt(dateStr.substring(0, 4))
const month = parseInt(dateStr.substring(4, 6))
const day = parseInt(dateStr.substring(6, 8))
const hour = parseInt(dateStr.substring(8, 10))
const min = parseInt(dateStr.substring(10, 12))
const date = new Date(year, month - 1, day, hour, min)
const bukumaDate = new Date(div.querySelector('.entrylist-contents-date').textContent) // 2023/01/23 00:00
const diffSec = (bukumaDate - date) / 1000 // ms to sec
if (diffSec > threshold) {
return
}
// ブクマ数 user
const user = div.querySelector('span.entrylist-contents-users a').lastChild
user.textContent += ' セルクマ ' + (diffSec / 60)
// 古い記事がマイナスになる でも2015年ぐらいの記事までかな?新着はセーフ臭い
/*
if(diffSec < 0) {
user.textContent += ' 異常差分:' + diffSec
}
*/
})
})();
]]>スクリプト保守とかするつもりないから、保守とかするつもりのあるパワーの溢れた人が
これ参考とかにしてもっとかっちょよくしたのを greasy fork あたりに公開してくれ
そしたら俺もそれ使う
ブラウザの開発環境を開いて、開発コンソールを開く
localStorage.hatebu_ng_word_list に非表示のトリガーになる文字列を|区切りで登録する。
localStorage.hatebu_ng_word_list = "池田信夫|フェミ|弱者男性|やまもといちろう"
大なり小なり(>)が実体参照で表示されるのはよくわからん。使う人で適宜コードを直してくれ。
// ==UserScript== // @name はてブの一覧NG記事非表示 // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author masuda // @match https://b.hatena.ne.jp/* // @icon https://www.google.com/s2/favicons?sz=64&domain=hatena.ne.jp // @grant none // ==/UserScript== (function() { 'use strict'; if (!localStorage.hatebu_ng_word_list) { return; } console.log("はてブの一覧NG記事非表示", localStorage.hatebu_ng_word_list); /* * 例: * localStorage.hatebu_ng_word_list = * "池田信夫|フェミ|弱者男性|やまもといちろう|togetter.com"; */ let words = localStorage.hatebu_ng_word_list.split('|').map(w => new RegExp(w)); function entryDelete(els) { els.forEach(el => { let hit = false; words.forEach(w => { hit = hit|| w.test(el.textContent); }); if (hit) { el.remove(); } }); } // entrylist-header-main li 1つ目のアイテム entryDelete(document.querySelectorAll('.entrylist-header-main > li')); // 2つ目以降の li アイテム entryDelete(document.querySelectorAll('.entrylist-item > li')); })();
文字は正規表現として評価されて、ヒットした記事項目をページから削除する(DOMから要素を削除する)。
際限なくNG登録できるけど、沢山非表示するとつまらない一覧になる
]]>わたしは「なにか作ってみろ」系の言説にはまったく同意しません。
わたし自身、会社に3ヶ月間みっちり導入教育をしてもらい(COBOL85とPL/I。時代がわかる……)、基本的なアルゴリズム(コントロールブレーク、マッチング、マスタ-トランザクション、ソート、マージ、etc.いよいよ時代がわかる……)の演習を(給料をもらいながら)やって、その後もプログラムとつかず離れずでフラフラと生きてきました。
こういう経験は新卒カードがあるから有効なもので、では1から始めるとしたら……、というときに、プログラミングスクール(専門学校)というのは悪くない選択肢ではないかと思います。が、行ったことないので正直わかりません。
実際自分が1から始めるという立場になったら、まったくオロオロして元増田さんのように世のなか(の気にいらないヤツら)に呪詛を吐いて満足するだけだったと思います(当然ながらそれをいくらやってもプログラミングは上達しません)。
話をプログラミングだけに限っていえば、一番大事なのはやりかたじゃなくて動機だろうと思います。
「なにか作ってみよう」というのは、なにか作ってみようと思ってない人にはまったく心に響かないでしょう。
動機ドリブンで「なにか作ってみた」人といえば思いだすのは、MikuMikuDanceの樋口優さん(ミクを簡単に踊らせたい!)とhinadanの若宮正子さん(高齢者にも遊べるゲームが欲しい!)でしょうか。
ただかれらはわたしから見れば(モチベーションを維持しそれを行動に移す)天才で、あんまり参考にならないのも確かです。
あと、元増田さんの動機は「プログラミングを生業にしたい」ということなので、野良プログラマでは履歴書上でのアピール力が弱いかも、と思います。
ビジネスで使われるアルゴリズムにはそれなりのルールがあります。安全な(バグの出にくい)コードの書きかた、「車輪の再発明」はぜず、枯れた(将棋で言えば定跡のような)アルゴリズムを使う、ほかの人に使ってもらえるための工夫(可読性の向上など)、etc.です。
「なにか作ってみよう」を繰りかえしても、そういった作法的なものが身につくかどうか、それは才能に関わってくる問題だと思います。才能だのみの手法を推奨するのは無責任だと思いますね。
また、たとえば「例をコピーして解析する」というのもある意味有効なプログラミング学習法ですが、「下手に習うと下手が伝染る」ともいいます。どれがお手本として優れているか、それを見る目はある程度ビジネス用途のプログラムに関わっていないと持てないというジレンマがあります。
野生のプログラマで就職に有効なくらいの力を見せるとしたら、なにかのコミッター(なにする人かよく知りませんが)とかになって「××ならこの人」となったり、プログラミングコンテストで上位の成績を残したりしなければいけないのかもしれません。
どうしたものでしょうね。ブクマカのみなさんの反応を見ると、専門学校でもあまり就職に有利にならない(ホントか?専門学校の意味あるのか?)という話ですが、目的が就職ならば、一番の近道のような気がします。
そこらへんからは、元増田さんがなにをしたいか、あるいは聞いてみたいだけだったのかによります。仕事には適性とやる気が大事です。あとは年齢と必要性かな。進路はオーダーメイド以外にはありえないので、提示された案を自分で選んでそれに賭けるしかないのかな、と思います。
自分がまず作ったもの晒してみろよ
さて、この文章は実はこの一文に反応してのものです。(↑のは前書き)
GWあたりからトシも考えずにRubyの再入門をしていまして、手始めに「首相動静」の整形ツールを作ってみました。
初心者で(Rubyに関しては仕事で使ったことないので)なにか作ってみよう、というとこの程度ですね。
これで就職に有利になるかというと、あんまりそうは思えないなあ。Excelのマクロが組めるとかのほうがどこかの事務所に潜りこめそうですよ(でもそれも最近はインフレ気味かもしれませんね)。
朝日新聞の首相動静は詳細ですが、改行が入っておらず、大変読みにくいものです。こんな感じです。
【午前】9時31分、自民党本部。33分、同党役員会。10時2分、官邸。5分、閣議。21分、宇宙開発戦略本部。34分、柴山昌彦文部科学相。38分、岩屋毅防衛相。41分、山下貴司法相。11時3分、安全保障と防衛力に関する懇談会。
【午後】0時11分、政府・与党連絡会議。44分、山口那津男公明党代表。1時27分、日韓議員連盟の額賀福志郎会長、河村建夫幹事長。2時20分、行政改革推進会議。52分、兼原信克官房副長官補、秋葉剛男外務事務次官。3時36分、麻生太郎財務相、財務省の岡本薫明事務次官、太田充主計局長。4時7分、太田氏出る。可部哲生理財局長加わる。15分、全員出る。25分、黒川弘務法務事務次官。34分、谷内正太郎国家安全保障局長、北村滋内閣情報官、宮川正内閣衛星情報センター所長。41分、谷内、宮川両氏出る。5時3分、北村氏出る。10分、東京・永田町のザ・キャピトルホテル東急。宴会場「鳳凰」で中曽根康弘世界平和研究所設立30周年記念式典に出席し、あいさつ。20分、官邸。6時18分、ガーナのアクフォアド大統領を出迎え。記念撮影。19分、儀仗(ぎじょう)隊による栄誉礼、儀仗。27分、アクフォアド大統領と会談。7時12分、署名式、共同記者発表。32分、公邸。首相主催の夕食会。8時43分、アクフォアド大統領を見送り。9時、ヨルダンのアブドラ国王と電話協議。
ただ、これはフォーマットがはっきりしており、
と、例を見るかぎりキッチリとしたルールに則っているようです。
なので、「これだったら整形できるかも」と思い、再び学びはじめたRubyで整形ツールを作ってみることにしました。
【午前】
09時31分、自民党本部。
09時33分、同党役員会。
10時02分、官邸。
10時05分、閣議。
10時21分、宇宙開発戦略本部。
10時34分、柴山昌彦文部科学相。
10時38分、岩屋毅防衛相。
10時41分、山下貴司法相。
11時03分、安全保障と防衛力に関する懇談会。
【午後】
00時11分、政府・与党連絡会議。
00時44分、山口那津男公明党代表。
01時27分、日韓議員連盟の額賀福志郎会長、河村建夫幹事長。
02時20分、行政改革推進会議。
02時52分、兼原信克官房副長官補、秋葉剛男外務事務次官。
03時36分、麻生太郎財務相、財務省の岡本薫明事務次官、太田充主計局長。
04時07分、太田氏出る。可部哲生理財局長加わる。
04時15分、全員出る。
04時25分、黒川弘務法務事務次官。
04時34分、谷内正太郎国家安全保障局長、北村滋内閣情報官、宮川正内閣衛星情報センター所長。
04時41分、谷内、宮川両氏出る。
05時03分、北村氏出る。
05時10分、東京・永田町のザ・キャピトルホテル東急。宴会場「鳳凰」で中曽根康弘世界平和研究所設立30周年記念式典に出席し、あいさつ。
05時20分、官邸。
06時18分、ガーナのアクフォアド大統領を出迎え。記念撮影。
06時19分、儀仗(ぎじょう)隊による栄誉礼、儀仗。
06時27分、アクフォアド大統領と会談。
07時12分、署名式、共同記者発表。
07時32分、公邸。首相主催の夕食会。
08時43分、アクフォアド大統領を見送り。
09時00分、ヨルダンのアブドラ国王と電話協議。
う~ん、見やすい!ことないですか?
あと、午後の時刻を24時間制にしたいな、とも思いますが、それは今後の課題(つぎに首相動静が話題になったとき)とします。全角数字の計算ってどうやるんだろう?
たぶんRubyistにいろいろ突っこまれると思うけど、こんな感じです。
プログラマは玉石混淆ですが、これは石のほうの例だと思っていただければさいわいです。
※ はてな記法にはシンタックスハイライトあるけど、増田だとInternal Server Errorになるのではずしました。見にくくてスマソ。
# encoding: utf-8 # 漢字コンバータのライブラリを取りこむ(Stringに漢字変換メソッドを付けてくれる。神) require 'kconv' # 正規表現パターン # 時刻をh時m分形式からhh時mm分形式にする # 否定後読みを使用する # 時は行頭にある OneDigitHour = /^((?<![0-1])[0-9]時)/ # 分は時のあとにある。このパターンとマッチすると、\1が時、\2が分になる。 OneDigitMinute = /^([0-9]{1,2}時)(?<![1-5])([0-9]分)/ # 分のない、時だけの行のパターン。否定先読みを使用 HourWithoutMinute = /^([0-9]{1,2}時)(?![0-5]?[0-9]分)/ # 行頭のh時m分をhh時mm分にするサブ処理(これは関数といっていいの?) def convTopHourMinute2TwoDigits(oneLine) # 時を変換 oneLine.sub!(OneDigitHour, "0\\1") # 分を変換 oneLine.sub!(OneDigitMinute, "\\10\\2") # 分がない場合"00分"を追加 oneLine.sub!(HourWithoutMinute, "\\100分") # 戻り値 oneLine end # 入力ファイルの名前 InputFilename = "首相動静2018年12月11日.txt" # 出力ファイルの名前 OutputFilename = "首相動静2018年12月11日_編集済.txt" # 入力ファイルをオープン inFile = File.open(InputFilename, "r") # 出力ファイルをオープン outFile = File.open(OutputFilename, "w") # 時刻パターンはシンプルに、h時、m分、h時m分、という3パターンを結合する # 1つのパターンで全部カバーするよりこちらのほうが見やすい。というか、脳の容量の問題で1文に書ききれなかった jikokuPattern = /[0-9]{1,2}時[0-9]{1,2}分、|[0-9]{1,2}時、|[0-9]{1,2}分、/ # 午前/午後 ampm = /(【午前】|【午後】)/ # 午前/午後、あるいは時刻の前で改行するためのパターン kaigyouSign = Regexp.union(ampm, jikokuPattern) # ファイル一括読み込み # 昔は1行ずつ読みこんでました。メインメモリが3MByteとかだったので contents = inFile.read.toutf8 # 入力終了。閉じておきます inFile.close # スコープの関係から、ここでローカル変数に代入 # ※ Rubyのスコープと暗黙の型には泣かされました。これに慣れるのがRubyのコツかしら # 明示的な型宣言はあったほうがいいと思うなあ。エラー出力の理由がわからなかったりするので。 hour = "" # デバッグ行はコメント化しています # 時刻パターンチェックのため、コンテンツを出力してみる # p jikokuPattern.match(contents) # エントリを改行サインで行に分ける contents.gsub!(kaigyouSign, "\n\\&") # "\\&"はマッチした文字列そのもの。2重のエスケープ"\\"が必要 # 改行チェックのため出力 # p contents # 入力を行で分割して各行ごとに処理 contents.split("\n") do |oneLine| # 午前/午後を示す開きカッコ"【"があるか if (oneLine =~ /^【/) then # そのまま出力 outFile.write(oneLine + "\n") # p "午前午後:" + oneLine next # 空白行は無視(スキップする) elsif (oneLine =~ /^[\s ]*$/) then # 出力しない # p " 空白行:<skip>" next # 行頭に「時」があるか elsif (oneLine =~ /^[0-9]{1,2}時/) then # あったら時間表示を抜きだしておく hour = oneLine.match(/^([0-9]{1,2}時)/)[0] # p " 時:" + oneLine outFile.write(convTopHourMinute2TwoDigits(oneLine) + "\n") next else # 「時」がなければつけて出力 oneLine = hour + oneLine # p "普通の行:" + oneLine outFile.write(convTopHourMinute2TwoDigits(oneLine) + "\n") end end
手でやったほうが早いね。
以上
]]>clang: warning: argument unused during compilation: '-I .'
clang: warning: argument unused during compilation: '-I proto'
clang: warning: argument unused during compilation: '-U _FORTIFY_SOURCE'
screen.c:1513:17: warning: self-comparison always evaluates to true [-Wtautological-compare]
if (curwin == curwin)
^
screen.c:5676:19: warning: self-comparison always evaluates to true [-Wtautological-compare]
&& Columns == Columns)
regexp.c:3790:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:3790:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:3790:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
regexp.c:4052:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:4052:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:4052:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
regexp.c:5276:25: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:5276:25: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:5276:25: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
regexp.c:5337:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
{ if ((rex.reg_match == ((void*)0))) *(&rex.reg_startpos[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.pos; else *(&rex.reg_startp[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.ptr; };
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:5337:24: note: remove extraneous parentheses around the comparison to silence this warning
{ if ((rex.reg_match == ((void*)0))) *(&rex.reg_startpos[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.pos; else *(&rex.reg_startp[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.ptr; };
~ ^ ~
regexp.c:5337:24: note: use '=' to turn this equality comparison into an assignment
{ if ((rex.reg_match == ((void*)0))) *(&rex.reg_startpos[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.pos; else *(&rex.reg_startp[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.ptr; };
^~
=
regexp.c:5355:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
{ if ((rex.reg_match == ((void*)0))) *(&rex.reg_endpos[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.pos; else *(&rex.reg_endp[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.ptr; };
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:5355:24: note: remove extraneous parentheses around the comparison to silence this warning
{ if ((rex.reg_match == ((void*)0))) *(&rex.reg_endpos[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.pos; else *(&rex.reg_endp[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.ptr; };
~ ^ ~
regexp.c:5355:24: note: use '=' to turn this equality comparison into an assignment
{ if ((rex.reg_match == ((void*)0))) *(&rex.reg_endpos[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.pos; else *(&rex.reg_endp[rp->rs_no]) = (&rp->rs_un.sesave)->se_u.ptr; };
^~
=
regexp.c:5516:22: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:5516:22: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:5516:22: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
regexp.c:6213:21: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:6213:21: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:6213:21: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
regexp.c:6266:25: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:6266:25: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:6266:25: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
regexp.c:6294:25: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:6294:25: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:6294:25: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
regexp.c:6325:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:6325:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:6325:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
regexp.c:6341:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:6341:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:6341:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
regexp.c:6363:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:6363:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:6363:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
regexp.c:7711:25: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:7711:25: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:7711:25: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
regexp.c:7740:23: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
regexp.c:7740:23: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
regexp.c:7740:23: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
In file included from regexp.c:8043:
./regexp_nfa.c:3995:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:3995:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:3995:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:4014:21: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:4014:21: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:4014:21: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:4036:21: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:4036:21: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:4036:21: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:4055:21: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:4055:21: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:4055:21: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:4086:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:4086:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:4086:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:4227:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:4227:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:4227:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:4609:25: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:4609:25: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:4609:25: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:4670:22: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:4670:22: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:4670:22: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:4733:25: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:4733:25: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:4733:25: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:4767:25: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:4767:25: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:4767:25: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:4954:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:4954:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:4954:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:5106:21: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:5106:21: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:5106:21: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:5120:21: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:5120:21: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:5120:21: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:5144:25: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:5144:25: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:5144:25: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:5231:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:5231:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:5231:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:5486:25: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:5486:25: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:5486:25: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:5608:21: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:5608:21: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:5608:21: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:5897:23: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:5897:23: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:5897:23: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:5987:26: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:5987:26: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:5987:26: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:6873:26: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:6873:26: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:6873:26: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:6997:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:6997:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:6997:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
./regexp_nfa.c:7095:24: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
if ((rex.reg_match == ((void*)0)))
~~~~~~~~~~~~~~^~~~~~~~~~~~~
./regexp_nfa.c:7095:24: note: remove extraneous parentheses around the comparison to silence this warning
if ((rex.reg_match == ((void*)0)))
~ ^ ~
./regexp_nfa.c:7095:24: note: use '=' to turn this equality comparison into an assignment
if ((rex.reg_match == ((void*)0)))
^~
=
]]>タグで切るか迷ったけど、テンプレをばさっと切るならタイトルのほうかなと。
素人でもこういうのが簡単に作れるようになるんだから、最近のブラウザのDeveloperToolとjQueryはすごいと思う。
// ==UserScript== // @name narou rank ng // @namespace http://use.i.E.your.homepage/ // @version 0.1 // @description enter something useful // @match http://yomou.syosetu.com/rank/list/* // @copyright 2012+, You // ==/UserScript== (function($){ // ここにNGワードを記載する var ngwords=["か[?\?]","令嬢","婚","ない","せん","王子","姫","乙女"]; $("div.rank_h").each(function(){ for ( key in ngwords){ reg = new RegExp(ngwords[key]); if( $("[id^=best]",this).html().match(reg) ){ $(this).css("display","none"); $(this).next().css("display","none"); } } }); })(jQuery);]]>
やや冗長かもしれないけど俺だったらこう書くなあ。(RegExpクラスを利用するための参照設定は忘れずに!)
ループでワークシートのセルにアクセスすると行数増えた時に使い物にならなくなるから、シートの値は必ず二次元配列に移して処理してるわ。
久々にプログラミングしたけどやっぱおもしれぇ!
求める答えが同じでもプログラミングする人のソースコードに対する思想の違いが顕著に表れるもんなー。
]]>autopagerize incrementalでググるとそれっぽいのが出てくる
こんなかんじの記述をAutopagerizeの適当な場所に追加したら連番URLでも使えるようになるはず
var pages = getElementsByXPath(this.info.pageElement, htmlDoc);
var url = this.getNextURL(this.info.nextLink, htmlDoc);
if (this.info.incremental) {
var exp = new RegExp(this.info.incremental.nextMatch,'i');
var _m = this.info.incremental.nextLink;
var step = this.info.incremental.step || 1;
url = this.requestURL.replace(exp,function(m0,m1){
var n = parseInt(m1,10) + step;
return _m.split('#').join(n);
});
}
var next = getFirstElementByXPath(xpath, doc);
if (next) {
if (this.info.incremental) {
var loc = this.requestURL || location.href;
var exp = new RegExp(this.info.incremental.nextMatch,'i');
var nextLink = this.info.incremental.nextLink;
var step = this.info.incremental.step || 1;
if (loc.match(exp)) {
return loc.replace(exp,nextLink.replace("#",parseInt(RegExp.$1)+step));
} else if (!loc.match(exp)) {
return loc + nextLink.replace("#",step);
}
} else {
return next.getAttribute('href') || next.getAttribute('action') || next.getAttribute('value');
}
}
連番に適応するSITEINFOはこんなかんじになる
pageelementは普通のsiteinfoと同じ
nextlinkはリンクをたどるわけじゃないので意味ないのだが一応書いておく必要があるので'//a'とでも書いておけばいい
url: '^http://matome\.naver\.jp/odai/'
,incremental: {
nextMatch: 'page=(\\d+)'
,nextLink: 'page=#'
}
,pageElement: '//div[@role="main"]'
,nextLink: '//a'
サンプル
]]>// ==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';
}
}
]]>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に渡し、強制的に更新チェックします。よってアンテナのページが複数にわたる場合は各ページで実行する必要がある。
元のブックマークレット:
]]>Microsoft VBScript 実行時エラー エラー '800a0030'
DLL 読み込み時のエラーです。: 'regexp'
/zinc/functions/mobile.inc, 行 47
]]>●HTAプログラム
↓
<html>
<head>
<style type="text/css">dt{float:left;clear:left;width:10em;}</style>
<meta content="charset=Shift_JIS"/>
</head>
<body>
<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>
</body>
</html>
]]>グループ分けとかしてるとうまく動かないかも。
order_home_mymixi.user.js
// ==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); } } }); })();]]>
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
2008-08-02 - 地獄の猫日記
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]]>
// ==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(); })();]]>
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
]]>// ==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); } } } })();]]>
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')}})();
最初はダイアログでURLの修正が出来る様に、と思ってましたが、良く考えるとあまり意味なさそうなので止めました。
]]><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); } } }); } })();]]>