| 109 | | /* |
| 110 | | EOF |
| 111 | | |
| 112 | | |
| 113 | | require "rubygems" |
| 114 | | require "rake" |
| 115 | | require "mechanize" |
| 116 | | require "yaml" |
| 117 | | require "pathname" |
| 118 | | |
| 119 | | |
| 120 | | desc "upload to userscripts.org" |
| 121 | | task :release do |
| 122 | | file = Pathname.new(__FILE__).read |
| 123 | | name = file[%r|@name\s+(.+)\s*|, 1] |
| 124 | | |
| 125 | | config = YAML.load(Pathname.new("~/.userscript.org.yaml").expand_path.read) |
| 126 | | |
| 127 | | agent = WWW::Mechanize.new |
| 128 | | |
| 129 | | puts "Logging in to userscripts.org" |
| 130 | | page = agent.get("http://userscripts.org/login") |
| 131 | | form = page.forms.with.action("/sessions").first |
| 132 | | form.login = config["mail"] |
| 133 | | form.password = config["pass"] |
| 134 | | page = agent.submit(form, form.buttons.name("commit")) |
| 135 | | |
| 136 | | puts "Move to your scripts page." |
| 137 | | page = agent.click(page.links.text("Your scripts")) |
| 138 | | |
| 139 | | puts "Move to script page #{name}" |
| 140 | | page = agent.click(page.links.text(name)) |
| 141 | | puts "Move to edit page" |
| 142 | | page = agent.click(page.links.text("Edit/update source")) |
| 143 | | |
| 144 | | puts "Update and posting new script" |
| 145 | | form = page.forms.first |
| 146 | | form["which_source"] = "textarea" |
| 147 | | form["script[src]"] = file |
| 148 | | |
| 149 | | page = agent.submit(form, form.buttons.name("commit")) |
| 150 | | p page.root/"//p[text() = 'a few seconds ago.']" |
| 151 | | puts "Done" |
| 152 | | end |
| 153 | | |
| 154 | | # */ |