特定のurlの時にjsを実行させるchromeエクステンション

f:id:kytiken:20111113195701p:image
http://www.pixiv.net/bookmark_add.php?type=illust&illust_id=hoge

この画面のブックマークを追加ボタンを自動でクリックするJSを書いた

こうだ


pixadd.js

document.getElementsByName("submit")[0].click()

これを"http://www.pixiv.net/bookmark_add.php?type=illust&illust_id=hoge"のurlの時に実行してくれるエクステンションを作ろうと思う

まず適当な作業用フォルダを作る
そのフォルダの中にさっきつくった"pixadd.js"ファイルを置き、"manifest.json"というファイルを作る

manifest.json

{
  "name": "hoge",
  "version": "1.0",
  "description": "The first extension that I made.",
  "content_scripts": [
    {
      "matches": ["http://www.pixiv.net/bookmark_add.php?type=illust&illust_id=*"],
      "js": ["pixadd.js"]
    }
  ]
}

あとは拡張機能の設定をデベロッパーモードで開き
パッケージ化されていない拡張機能を読み込むをクリックし
さっきのフォルダを選択します
これで完成

詳しくは公式ドキュメントページへ
http://code.google.com/chrome/extensions/docs.html

俺得なgithub URL
https://github.com/kytiken/pixadd

twitter apiをrubyでいじってみたときのメモ

#! ruby -Ku
require "rubygems"
require "Twitter"

nico = Twitter.new

nico.consumer_key="hogehoge"
nico.consumer_secret="hogehoge"
nico.oauth_token="hogehoge"
nico.oauth_token_secret="hogehoge"

smnumbers = Array.new
hashtags = nico.search("#nicovideo") #"#nicovideo"がついているツイートを検索
hashtags.to_s.each{|tweets|
tweets.scan(/#sm\d*/){|smnumber| #"#sm12345"の部分を抜き出す
smnumbers.push(smnumber)
}
}

puts smnumbers #"#nicovideo"がついているツイートのsm番号が20件取得できているはず

rubyでatndの登録ユーザー名をとってくる時のメモ

require 'rubygems'
require 'open-uri'
require 'rexml/document'

class GetAtnd
def initialize(id = "hoge")
@id = id
end

def get_user_uri #REXML::Documentオブジェクトの取得メソッド
atnd_api_page = "http://api.atnd.org/events/users/?event_id=#{@id}/"
source = open(atnd_api_page)
@user = REXML::Document.new source
end

def user_each
@user.elements.each('hash/events/event/users/user/nickname'){|f|
puts f.text
}
end

def get_info_uri #REXML::Documentオブジェクトの取得メソッド
atnd_api_page = "http://api.atnd.org/events/?event_id=#{@id}/"
source = open(atnd_api_page)
@info = REXML::Document.new source
end

def event_title
@info.elements.each('hash/events/event/title'){|f|
puts f.text
}
end
end

hoge = GetAtnd.new(イベント番号)
hoge.get_user_uri
hoge.user_each
hoge.get_info_uri
hoge.event_title

#あとこれをつかってアプリケーション開発するやる気がほしい

mechanizeを使ってrubyでniconicoにログインするときのメモ

require 'rubygems'
require 'mechanize'
require 'open-uri'

agent = Mechanize.new
page = agent.get('http://com.nicovideo.jp/community/') #認証画面のURI
form = page.form()
form.field_with(:name=>"mail").value = "登録しているメール"
form.field_with(:name=>"password").value = "登録しているパスワード"
form.submit()

page = agent.get('http://com.nicovideo.jp/community/')
puts page.title