| 1 | // ==UserScript==
|
|---|
| 2 | // @name Post this page!
|
|---|
| 3 | // @namespace http://yuroyoro.com/
|
|---|
| 4 | // @description Usage: Ctrl + Shift + I -> Post now nrowsing url on Twitter and wassr.(今見ているページのURLをTwitterとWassrにPOST)
|
|---|
| 5 | // @include http://*
|
|---|
| 6 | // ==/UserScript==
|
|---|
| 7 | (function() {
|
|---|
| 8 |
|
|---|
| 9 | var show_icon = true; // ICONを表示するか
|
|---|
| 10 | var use_keybind = true; // ctrl + shift + I でのkeybindを利用するか
|
|---|
| 11 | var use_twitter = true; // twitterを利用するか
|
|---|
| 12 | var use_wassr = true; // wassrを利用するか
|
|---|
| 13 | var use_hatenahike = true; // はてなハイクを利用するか
|
|---|
| 14 | var display_main = false; // 現在Mainを表示しているかの状態
|
|---|
| 15 | var init_url = false; // すでにTinyURLしたか
|
|---|
| 16 | var page_title = ''; // 表示中のページタイトル
|
|---|
| 17 | var page_url = ''; // 表示中のURL
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | if (self.location.href != top.location.href) {
|
|---|
| 21 | return;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | // IFrame対応(CrossDomainでは効果なし…。))
|
|---|
| 25 | if (window != window.parent) {
|
|---|
| 26 | var iframes = window.parent.document.getElementsByTagName("iframe");
|
|---|
| 27 | for (var i=0; i<iframes.length; i++) {
|
|---|
| 28 | if (iframes[i].src == document.location) {
|
|---|
| 29 | return;
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | GM_addStyle(<><![CDATA[
|
|---|
| 36 | div#PostThisPage_icon{
|
|---|
| 37 | z-index: 250;
|
|---|
| 38 | position: fixed;
|
|---|
| 39 | bottom: 0px;
|
|---|
| 40 | left: 0px;
|
|---|
| 41 | overflow: hidden;
|
|---|
| 42 | opacity: 0.9;
|
|---|
| 43 | min-height: 21px;
|
|---|
| 44 | min-width: 21px;
|
|---|
| 45 | max-height: 21px;
|
|---|
| 46 | max-width: 21px;
|
|---|
| 47 | padding: 0px;
|
|---|
| 48 | margin : 0px;
|
|---|
| 49 | background-color: transparent
|
|---|
| 50 | border : none;
|
|---|
| 51 | }
|
|---|
| 52 | div#PostThisPage_icon img{
|
|---|
| 53 | border : none;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | div#PostThisPage_main{
|
|---|
| 57 | z-index: 250;
|
|---|
| 58 | position: fixed;
|
|---|
| 59 | top: 20%;
|
|---|
| 60 | left: 0px;
|
|---|
| 61 | overflow: auto;
|
|---|
| 62 | opacity: 0.85;
|
|---|
| 63 | min-height: 150px;
|
|---|
| 64 | width: 100%;
|
|---|
| 65 | padding: 0px;
|
|---|
| 66 | margin : 0px;
|
|---|
| 67 | background-color: #F9E3C5;
|
|---|
| 68 | border : none;
|
|---|
| 69 | border-top : 1px solid #F47B0F;
|
|---|
| 70 | border-bottom : 1px solid #F47B0F;
|
|---|
| 71 |
|
|---|
| 72 | -x-system-font:none;
|
|---|
| 73 | font-family: Helvetica, Verdana, sans-serif;
|
|---|
| 74 | font-size:1.2em;
|
|---|
| 75 | font-size-adjust:none;
|
|---|
| 76 | font-stretch:normal;
|
|---|
| 77 | font-style:normal;
|
|---|
| 78 | font-variant:normal;
|
|---|
| 79 | font-weight:normal;
|
|---|
| 80 | line-height:1.1;
|
|---|
| 81 | color:#666666;
|
|---|
| 82 | text-align:center;
|
|---|
| 83 | text-indent:0;
|
|---|
| 84 | text-rendering:optimizelegibility;
|
|---|
| 85 | text-transform:none;
|
|---|
| 86 | vertical-align:text-top;
|
|---|
| 87 | word-spacing:normal;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | div#PostThisPage_main div#PostThisPage_form div#PostThisPage_title{
|
|---|
| 91 | width:50%;
|
|---|
| 92 | text-align : left;
|
|---|
| 93 | margin-left:auto;
|
|---|
| 94 | margin-right:auto
|
|---|
| 95 | }
|
|---|
| 96 | div#PostThisPage_main div#PostThisPage_form div#PostThisPage_title h3#PostThisPage_title_text{
|
|---|
| 97 | font-weight:bold;
|
|---|
| 98 | font-size : 1.2em;
|
|---|
| 99 | color : #F9B25D;
|
|---|
| 100 | margin : 10px 0px;
|
|---|
| 101 | background:transparent ;
|
|---|
| 102 | height:auto;
|
|---|
| 103 | line-height:auto;
|
|---|
| 104 | padding :0px;
|
|---|
| 105 | border : none;
|
|---|
| 106 | }
|
|---|
| 107 | div#PostThisPage_main div#PostThisPage_form hr#PostThisPage_hr{
|
|---|
| 108 | border :none;
|
|---|
| 109 | width : 100%;
|
|---|
| 110 | border-top: 1px solid #F47B0F;
|
|---|
| 111 | display : block;
|
|---|
| 112 | }
|
|---|
| 113 | div#PostThisPage_main div#PostThisPage_form div#PostThisPage_content {
|
|---|
| 114 | text-align : left;
|
|---|
| 115 | width:50%;
|
|---|
| 116 | margin-left:auto;
|
|---|
| 117 | margin-right:auto
|
|---|
| 118 | }
|
|---|
| 119 | div#PostThisPage_main div#PostThisPage_form div#PostThisPage_content div#PostThisPage_info{
|
|---|
| 120 | width : 100%;
|
|---|
| 121 | vertical-align : bottom;
|
|---|
| 122 | }
|
|---|
| 123 | div#PostThisPage_main div#PostThisPage_form div#PostThisPage_content div#PostThisPage_info_container{
|
|---|
| 124 | width : 85%;
|
|---|
| 125 | float : left;
|
|---|
| 126 | vertical-align :bottom
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | div#PostThisPage_main div#PostThisPage_form div#PostThisPage_content div.PostThisPage_page_info{
|
|---|
| 130 | font-size : 0.7em;
|
|---|
| 131 | padding-left : 15px;
|
|---|
| 132 | margin : 4px ;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | div#PostThisPage_main div#PostThisPage_form div#PostThisPage_content div#PostThisPage_message{
|
|---|
| 136 | clear: both;
|
|---|
| 137 | width : 85%;
|
|---|
| 138 | font-size : 0.7em;
|
|---|
| 139 | color : #F9B25D;
|
|---|
| 140 | background-color : #FFFFFF;
|
|---|
| 141 | border :1px solid #F47B0F;
|
|---|
| 142 | margin : 4px 0px;
|
|---|
| 143 | padding : 5px;
|
|---|
| 144 | display :none;
|
|---|
| 145 | }
|
|---|
| 146 | div#PostThisPage_main div#PostThisPage_form div#PostThisPage_content span#PostThisPage_counter{
|
|---|
| 147 | float : right;
|
|---|
| 148 | color:#F9B25D;
|
|---|
| 149 | font-size:22pt !important;
|
|---|
| 150 | font-family:'Georgia','Serif';
|
|---|
| 151 | width : 14%;
|
|---|
| 152 | text-align:right;
|
|---|
| 153 | font-size-adjust:none;
|
|---|
| 154 | font-style:normal;
|
|---|
| 155 | font-variant:normal;
|
|---|
| 156 | font-weight:normal;
|
|---|
| 157 | line-height : 1.4;
|
|---|
| 158 | }
|
|---|
| 159 | div#PostThisPage_main div#PostThisPage_form div#PostThisPage_content textarea#PostThisPage_textarea{
|
|---|
| 160 | -x-system-font:none;
|
|---|
| 161 | font-size:0.8em;
|
|---|
| 162 | height:5em;
|
|---|
| 163 | line-height:1.1;
|
|---|
| 164 | overflow:auto;
|
|---|
| 165 | margin : 2px 0px;
|
|---|
| 166 | padding: 5px;
|
|---|
| 167 | width:100%;
|
|---|
| 168 | -moz-appearance:textfield-multiline;
|
|---|
| 169 | -moz-user-select:text;
|
|---|
| 170 | background-color:-moz-field;
|
|---|
| 171 | border:1px solid #F47B0F;
|
|---|
| 172 | color:-moz-fieldtext;
|
|---|
| 173 | cursor:text;
|
|---|
| 174 | text-align:start;
|
|---|
| 175 | text-indent:0;
|
|---|
| 176 | text-rendering:optimizelegibility;
|
|---|
| 177 | text-transform:none;
|
|---|
| 178 | vertical-align:text-bottom;
|
|---|
| 179 | word-spacing:normal;
|
|---|
| 180 | }
|
|---|
| 181 | div#PostThisPage_main div#PostThisPage_form div#PostThisPage_checks{
|
|---|
| 182 | text-align : left;
|
|---|
| 183 | padding-left : 20px;
|
|---|
| 184 | margin : 10px 0px;
|
|---|
| 185 | font-size : 0.8em;
|
|---|
| 186 | }
|
|---|
| 187 | div#PostThisPage_main div#PostThisPage_form div#PostThisPage_checks label{
|
|---|
| 188 | margin : 0px 8px;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | div#PostThisPage_main div#PostThisPage_form input#update_button{
|
|---|
| 192 | background-color:#808080;
|
|---|
| 193 | border:1px solid black;
|
|---|
| 194 | color:#FFFFFF;
|
|---|
| 195 | cursor:pointer;
|
|---|
| 196 | font-size:0.9em;
|
|---|
| 197 | font-weight:bold;
|
|---|
| 198 | margin-top:5px;
|
|---|
| 199 | margin-bottom:5px;
|
|---|
| 200 | padding:2px 8px;
|
|---|
| 201 | -moz-appearance:button;
|
|---|
| 202 | -moz-binding:none;
|
|---|
| 203 | -moz-box-sizing:border-box;
|
|---|
| 204 | -moz-user-select:none;
|
|---|
| 205 | -x-system-font:-moz-button;
|
|---|
| 206 | font-family:-moz-use-system-font;
|
|---|
| 207 | font-size-adjust:-moz-use-system-font;
|
|---|
| 208 | font-stretch:-moz-use-system-font;
|
|---|
| 209 | font-style:-moz-use-system-font;
|
|---|
| 210 | font-variant:-moz-use-system-font;
|
|---|
| 211 | line-height:normal !important;
|
|---|
| 212 | text-align:center;
|
|---|
| 213 | white-space:pre;
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | ]]></>);
|
|---|
| 217 |
|
|---|
| 218 | // 初期化
|
|---|
| 219 | function init(){
|
|---|
| 220 |
|
|---|
| 221 | // Main Div生成
|
|---|
| 222 | var view = c('div');
|
|---|
| 223 | view.id = 'PostThisPage_main';
|
|---|
| 224 | view.style.display = 'none';
|
|---|
| 225 |
|
|---|
| 226 | var form = c('div');
|
|---|
| 227 | form.id = 'PostThisPage_form';
|
|---|
| 228 | view.appendChild(form);
|
|---|
| 229 |
|
|---|
| 230 | document.body.appendChild(view);
|
|---|
| 231 | init_form( form );
|
|---|
| 232 |
|
|---|
| 233 | // ICON用Div生成
|
|---|
| 234 | var icon = c('div');
|
|---|
| 235 | icon.id = 'PostThisPage_icon';
|
|---|
| 236 | var icon_img = c('img');
|
|---|
| 237 | icon_img.src = ICON_IMAGE;
|
|---|
| 238 | icon.appendChild( icon_img );
|
|---|
| 239 | document.body.appendChild( icon );
|
|---|
| 240 |
|
|---|
| 241 | // ICONクリックでMainをtoggleする
|
|---|
| 242 | icon.addEventListener('click', toggle_PostThisPage_main, false);
|
|---|
| 243 |
|
|---|
| 244 | // ICONを表示するかの設定を取得
|
|---|
| 245 | var config_show_icon = GM_getValue('PostThisPage_show_icon');
|
|---|
| 246 | if( config_show_icon != undefined) show_icon = config_show_icon;
|
|---|
| 247 | if( !show_icon) hide_PostThisPage_icon();
|
|---|
| 248 |
|
|---|
| 249 | // keybindを利用するかの設定を取得
|
|---|
| 250 | var config_use_keybind = GM_getValue('PostThisPage_use_keybind');
|
|---|
| 251 | if( config_use_keybind != undefined) use_keybind = config_use_keybind;
|
|---|
| 252 | if( use_keybind ){
|
|---|
| 253 | // ctrl + shift + i にkeybind
|
|---|
| 254 | addEventListener('keydown', function(e){
|
|---|
| 255 | var c = (e.ctrlKey)
|
|---|
| 256 | var s = (e.shiftKey)
|
|---|
| 257 | var v = (e.keyCode == 73)
|
|---|
| 258 | if (c && s && v) {
|
|---|
| 259 | toggle_PostThisPage_main();
|
|---|
| 260 | }
|
|---|
| 261 | }, true);
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | // twitterを利用するかの設定を取得
|
|---|
| 265 | var config_use_twitter = GM_getValue('PostThisPage_use_twitter');
|
|---|
| 266 | if( config_use_twitter != undefined) use_twitter = config_use_twitter;
|
|---|
| 267 | if( !use_twitter ){
|
|---|
| 268 | e('PostThisPage_check_twitter').style.display = 'none';
|
|---|
| 269 | e('PostThisPage_check_twitter_label').style.display = 'none';
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | // wassrを利用するかの設定を取得
|
|---|
| 273 | var config_use_wassr = GM_getValue('PostThisPage_use_wassr');
|
|---|
| 274 | if( config_use_wassr != undefined) use_wassr = config_use_wassr;
|
|---|
| 275 | if( !use_wassr ){
|
|---|
| 276 | e('PostThisPage_check_wassr').style.display = 'none';
|
|---|
| 277 | e('PostThisPage_check_wassr_label').style.display = 'none';
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | // はてなハイクを利用するかの設定を取得
|
|---|
| 281 | var config_use_hatenahike = GM_getValue('PostThisPage_use_hatenahike');
|
|---|
| 282 | if( config_use_hatenahike != undefined) use_hatenahike = config_use_hatenahike;
|
|---|
| 283 | if( !use_wassr ){
|
|---|
| 284 | e('PostThisPage_check_hatenahike').style.display = 'none';
|
|---|
| 285 | e('PostThisPage_check_hatenahike_label').style.display = 'none';
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | function init_form(){
|
|---|
| 291 | var form = e('PostThisPage_form');
|
|---|
| 292 |
|
|---|
| 293 | var title = c('div');
|
|---|
| 294 | title.id = 'PostThisPage_title';
|
|---|
| 295 |
|
|---|
| 296 | var title_text = c('h3');
|
|---|
| 297 | title_text.id = 'PostThisPage_title_text';
|
|---|
| 298 | title_text.innerHTML = 'いまここみてる';
|
|---|
| 299 | title.appendChild(title_text);
|
|---|
| 300 |
|
|---|
| 301 | form.appendChild( title);
|
|---|
| 302 |
|
|---|
| 303 | var hr = c('hr');
|
|---|
| 304 | hr.id = 'PostThisPage_hr';
|
|---|
| 305 | form.appendChild(hr);
|
|---|
| 306 |
|
|---|
| 307 | var content = c('div');
|
|---|
| 308 | content.id = 'PostThisPage_content';
|
|---|
| 309 |
|
|---|
| 310 | var info = c('div');
|
|---|
| 311 | info.id = 'PostThisPage_info';
|
|---|
| 312 |
|
|---|
| 313 | var info_container = c('div');
|
|---|
| 314 | info_container.id = 'PostThisPage_info_container';
|
|---|
| 315 |
|
|---|
| 316 | var page_title = c('div');
|
|---|
| 317 | page_title.id = 'PostThisPage_page_title';
|
|---|
| 318 | page_title.className = 'PostThisPage_page_info';
|
|---|
| 319 | info_container.appendChild(page_title);
|
|---|
| 320 |
|
|---|
| 321 | var page_url = c('div');
|
|---|
| 322 | page_url.id = 'PostThisPage_page_url';
|
|---|
| 323 | page_url.className = 'PostThisPage_page_info';
|
|---|
| 324 | info_container.appendChild(page_url);
|
|---|
| 325 | info.appendChild(info_container);
|
|---|
| 326 |
|
|---|
| 327 | var counter = c('span');
|
|---|
| 328 | counter.id = 'PostThisPage_counter';
|
|---|
| 329 | info.appendChild( counter );
|
|---|
| 330 |
|
|---|
| 331 | content.appendChild( info );
|
|---|
| 332 |
|
|---|
| 333 | var message = c('div');
|
|---|
| 334 | message.id = 'PostThisPage_message';
|
|---|
| 335 | content.appendChild( message );
|
|---|
| 336 |
|
|---|
| 337 | var text = c('textarea');
|
|---|
| 338 | with( text ) {
|
|---|
| 339 | id = 'PostThisPage_textarea';
|
|---|
| 340 | rows = 2;
|
|---|
| 341 | cols = 40;
|
|---|
| 342 | addEventListener('keyup' , updateStatusTextCharCounter ,false);
|
|---|
| 343 | addEventListener('focus' , updateStatusTextCharCounter ,false);
|
|---|
| 344 | addEventListener('blur' , updateStatusTextCharCounter ,false);
|
|---|
| 345 | // ctrl + enter でPOST
|
|---|
| 346 | addEventListener('keydown', function(e){
|
|---|
| 347 | var c = (e.ctrlKey)
|
|---|
| 348 | var v = (e.keyCode == 13)
|
|---|
| 349 | if (c && v) {
|
|---|
| 350 | post();
|
|---|
| 351 | }
|
|---|
| 352 | }, true);
|
|---|
| 353 | }
|
|---|
| 354 | content.appendChild( text );
|
|---|
| 355 |
|
|---|
| 356 | var checks = c('div');
|
|---|
| 357 | checks.id = 'PostThisPage_checks';
|
|---|
| 358 |
|
|---|
| 359 | var check_title = c('input');
|
|---|
| 360 | with(check_title){
|
|---|
| 361 | id = 'PostThisPage_check_title';
|
|---|
| 362 | type = 'checkbox';
|
|---|
| 363 | checked = 'true';
|
|---|
| 364 | addEventListener('change' , append_title , false );
|
|---|
| 365 | }
|
|---|
| 366 | checks.appendChild( check_title );
|
|---|
| 367 | var check_title_label = c('label');
|
|---|
| 368 | with(check_title_label){
|
|---|
| 369 | id = 'PostThisPage_check_title_label';
|
|---|
| 370 | innerHTML = 'タイトルを追加する';
|
|---|
| 371 | }
|
|---|
| 372 | check_title_label.setAttribute('for','PostThisPage_check_title');
|
|---|
| 373 | checks.appendChild( check_title_label );
|
|---|
| 374 |
|
|---|
| 375 | var check_twitter = c('input');
|
|---|
| 376 | with(check_twitter){
|
|---|
| 377 | id = 'PostThisPage_check_twitter';
|
|---|
| 378 | type = 'checkbox';
|
|---|
| 379 | checked = 'true';
|
|---|
| 380 | }
|
|---|
| 381 | checks.appendChild( check_twitter );
|
|---|
| 382 | var check_twitter_label = c('label');
|
|---|
| 383 | with(check_twitter_label){
|
|---|
| 384 | id = 'PostThisPage_check_twitter_label';
|
|---|
| 385 | innerHTML = 'Twitter';
|
|---|
| 386 | }
|
|---|
| 387 | check_twitter_label.setAttribute('for','PostThisPage_check_twitter');
|
|---|
| 388 | checks.appendChild( check_twitter_label );
|
|---|
| 389 |
|
|---|
| 390 | var check_wassr = c('input');
|
|---|
| 391 | with(check_wassr){
|
|---|
| 392 | id = 'PostThisPage_check_wassr';
|
|---|
| 393 | type = 'checkbox';
|
|---|
| 394 | checked = 'true';
|
|---|
| 395 | }
|
|---|
| 396 | checks.appendChild( check_wassr );
|
|---|
| 397 | var check_wassr_label = c('label');
|
|---|
| 398 | with(check_wassr_label){
|
|---|
| 399 | id = 'PostThisPage_check_wassr_label';
|
|---|
| 400 | innerHTML = 'Wassr';
|
|---|
| 401 | }
|
|---|
| 402 | check_wassr_label.setAttribute('for','PostThisPage_check_wassr');
|
|---|
| 403 | checks.appendChild( check_wassr_label );
|
|---|
| 404 |
|
|---|
| 405 | var check_hatenahike = c('input');
|
|---|
| 406 | with(check_hatenahike){
|
|---|
| 407 | id = 'PostThisPage_check_hatenahike';
|
|---|
| 408 | type = 'checkbox';
|
|---|
| 409 | checked = 'true';
|
|---|
| 410 | }
|
|---|
| 411 | checks.appendChild( check_hatenahike );
|
|---|
| 412 | var check_hatenahike_label = c('label');
|
|---|
| 413 | with(check_hatenahike_label){
|
|---|
| 414 | id = 'PostThisPage_check_hatenahike_label';
|
|---|
| 415 | innerHTML = 'はてなハイク';
|
|---|
| 416 | }
|
|---|
| 417 | check_hatenahike_label.setAttribute('for','PostThisPage_check_hatenahike');
|
|---|
| 418 | checks.appendChild( check_hatenahike_label );
|
|---|
| 419 |
|
|---|
| 420 | content.appendChild( checks );
|
|---|
| 421 |
|
|---|
| 422 | var center = c('center');
|
|---|
| 423 | var btn = c('input');
|
|---|
| 424 | with(btn){
|
|---|
| 425 | id = 'update_button';
|
|---|
| 426 | type = 'button';
|
|---|
| 427 | value = '投稿する';
|
|---|
| 428 | addEventListener('click' , post , false );
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | center.appendChild( btn );
|
|---|
| 432 | content.appendChild( center );
|
|---|
| 433 |
|
|---|
| 434 | form.appendChild( content );
|
|---|
| 435 |
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | // Title.URLをセット
|
|---|
| 439 | function set_page_info(){
|
|---|
| 440 | u('PostThisPage_page_title' , 'Title : ' + page_title);
|
|---|
| 441 | u('PostThisPage_page_url', 'URL : ' + page_url);
|
|---|
| 442 | var text = e('PostThisPage_textarea');
|
|---|
| 443 | text.value = '[ ' + page_url + ' : ' + page_title + ' ]';
|
|---|
| 444 | // カーソル位置を先頭にしておく
|
|---|
| 445 | text.setSelectionRange(0,0)
|
|---|
| 446 | updateStatusTextCharCounter();
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | // ICONの表示切り替え
|
|---|
| 450 | function hide_PostThisPage_icon(){
|
|---|
| 451 | var icon = e('PostThisPage_icon');
|
|---|
| 452 | icon.style.display = 'none';
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | // ICONの表示切り替え
|
|---|
| 456 | function show_PostThisPage_icon(){
|
|---|
| 457 | var icon = e('PostThisPage_icon');
|
|---|
| 458 | icon.style.display = 'block';
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | // ICON表示設定の切り替え
|
|---|
| 462 | function setIconSetting(){
|
|---|
| 463 | if( show_icon ){
|
|---|
| 464 | hide_PostThisPage_icon();
|
|---|
| 465 | show_icon = false;
|
|---|
| 466 | }
|
|---|
| 467 | else{
|
|---|
| 468 | show_PostThisPage_icon();
|
|---|
| 469 | show_icon = true;
|
|---|
| 470 | }
|
|---|
| 471 | GM_setValue('PostThisPage_show_icon' , show_icon);
|
|---|
| 472 | }
|
|---|
| 473 |
|
|---|
| 474 | // keybind利用設定の切り替え
|
|---|
| 475 | function setKeybindSetting(){
|
|---|
| 476 | if( use_keybind ){
|
|---|
| 477 | use_keybind = false;
|
|---|
| 478 | }
|
|---|
| 479 | else{
|
|---|
| 480 | use_keybind = true;
|
|---|
| 481 | }
|
|---|
| 482 | GM_setValue('PostThisPage_use_keybind' , use_keybind);
|
|---|
| 483 | }
|
|---|
| 484 |
|
|---|
| 485 | // Twitter利用設定の切り替え
|
|---|
| 486 | function setTwitterSetting(){
|
|---|
| 487 | if( use_twitter ){
|
|---|
| 488 | use_twitter = false;
|
|---|
| 489 | }
|
|---|
| 490 | else{
|
|---|
| 491 | use_twitter = true;
|
|---|
| 492 | }
|
|---|
| 493 | GM_setValue('PostThisPage_use_twitter' , use_twitter);
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | // Wassr利用設定の切り替え
|
|---|
| 497 | function setWassrSetting(){
|
|---|
| 498 | if( use_wassr ){
|
|---|
| 499 | use_wassr = false;
|
|---|
| 500 | }
|
|---|
| 501 | else{
|
|---|
| 502 | use_wassr = true;
|
|---|
| 503 | }
|
|---|
| 504 | GM_setValue('PostThisPage_use_wassr' , use_wassr);
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | // はてなハイク利用設定の切り替え
|
|---|
| 508 | function setHatenaHikeSetting(){
|
|---|
| 509 | if( use_hatenahike ){
|
|---|
| 510 | use_hatenahike = false;
|
|---|
| 511 | }
|
|---|
| 512 | else{
|
|---|
| 513 | use_hatenahike = true;
|
|---|
| 514 | }
|
|---|
| 515 | GM_setValue('PostThisPage_use_hatenahike' , use_hatenahike);
|
|---|
| 516 | }
|
|---|
| 517 |
|
|---|
| 518 | // Mainの表示切り替え
|
|---|
| 519 | function show_PostThisPage_main(){
|
|---|
| 520 | var main = e('PostThisPage_main');
|
|---|
| 521 | main.style.display = 'block';
|
|---|
| 522 | display_main = true;
|
|---|
| 523 | // TinyURLしていないかったらやる
|
|---|
| 524 | if( !init_url ){
|
|---|
| 525 | page_title = document.title;
|
|---|
| 526 | createTinyURL( top.location.href,
|
|---|
| 527 | function(url){
|
|---|
| 528 | page_url = url;
|
|---|
| 529 | set_page_info();
|
|---|
| 530 | } ,
|
|---|
| 531 | function(){
|
|---|
| 532 | page_url = top.location.href;
|
|---|
| 533 | set_page_info();
|
|---|
| 534 | }
|
|---|
| 535 | );
|
|---|
| 536 | init_url = true;
|
|---|
| 537 | }
|
|---|
| 538 | // textにフォーカス
|
|---|
| 539 | var text = e('PostThisPage_textarea');
|
|---|
| 540 | text.focus();
|
|---|
| 541 | }
|
|---|
| 542 | // Mainの表示切り替え
|
|---|
| 543 | function hide_PostThisPage_main(){
|
|---|
| 544 | var main = e('PostThisPage_main');
|
|---|
| 545 | if (main) {
|
|---|
| 546 | main.style.display = 'none';
|
|---|
| 547 | display_main = false;
|
|---|
| 548 | }
|
|---|
| 549 | }
|
|---|
| 550 | // Mainの表示切り替え
|
|---|
| 551 | function toggle_PostThisPage_main(){
|
|---|
| 552 | if( display_main ){
|
|---|
| 553 | hide_PostThisPage_main();
|
|---|
| 554 | }else{
|
|---|
| 555 | show_PostThisPage_main();
|
|---|
| 556 | }
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | // TinyURLを生成する
|
|---|
| 560 | function createTinyURL(url,callback,error) {
|
|---|
| 561 | GM_xmlhttpRequest({
|
|---|
| 562 | method : 'get',
|
|---|
| 563 | url : 'http://tinyurl.com/api-create.php?url=' + url,
|
|---|
| 564 | onload : function(res) {
|
|---|
| 565 | if (res.responseText != 'Error') callback(res.responseText)
|
|---|
| 566 | else if (typeof error == 'function') error(res)
|
|---|
| 567 | },
|
|---|
| 568 | onerror: error,
|
|---|
| 569 | })
|
|---|
| 570 | }
|
|---|
| 571 |
|
|---|
| 572 | // Textareaに入力された文字数を表示する
|
|---|
| 573 | function updateStatusTextCharCounter() {
|
|---|
| 574 | var text = e('PostThisPage_textarea');
|
|---|
| 575 |
|
|---|
| 576 | len = text.value.length;
|
|---|
| 577 | var counter = e('PostThisPage_counter');
|
|---|
| 578 | counter.innerHTML = '' + (len);
|
|---|
| 579 |
|
|---|
| 580 | var t_lable = e('PostThisPage_check_twitter_label');
|
|---|
| 581 | var w_lable = e('PostThisPage_check_wassr_label');
|
|---|
| 582 | var h_lable = e('PostThisPage_check_hatenahike_label');
|
|---|
| 583 | t_lable.innerHTML = 'Twitter (' + (140 - len) + ')';
|
|---|
| 584 | w_lable.innerHTML = 'Wassr (' + (255 - len) + ')';
|
|---|
| 585 | h_lable.innerHTML = 'はてなハイク (' + (255 - len) + ')';
|
|---|
| 586 |
|
|---|
| 587 | if( len > 130 ){
|
|---|
| 588 | t_lable.style.color = '#d40d12';
|
|---|
| 589 | }
|
|---|
| 590 | else if( len > 120 ){
|
|---|
| 591 | t_lable.style.color = '#5c0002';
|
|---|
| 592 | }
|
|---|
| 593 | else{
|
|---|
| 594 | t_lable.style.color = '#666666';
|
|---|
| 595 | }
|
|---|
| 596 |
|
|---|
| 597 | if( len > 255 ){
|
|---|
| 598 | w_lable.style.color = '#d40d12';
|
|---|
| 599 | }
|
|---|
| 600 | else if( len > 240 ){
|
|---|
| 601 | w_lable.style.color = '#5c0002';
|
|---|
| 602 | }
|
|---|
| 603 | else{
|
|---|
| 604 | w_lable.style.color = '#666666';
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | if( len > 255 ){
|
|---|
| 608 | h_lable.style.color = '#d40d12';
|
|---|
| 609 | }
|
|---|
| 610 | else if( len > 240 ){
|
|---|
| 611 | h_lable.style.color = '#5c0002';
|
|---|
| 612 | }
|
|---|
| 613 | else{
|
|---|
| 614 | h_lable.style.color = '#666666';
|
|---|
| 615 | }
|
|---|
| 616 | }
|
|---|
| 617 |
|
|---|
| 618 | // TextArea内にPageのTitleを付与/削除
|
|---|
| 619 | function append_title(){
|
|---|
| 620 | var chk = e('PostThisPage_check_title');
|
|---|
| 621 | var text = e('PostThisPage_textarea');
|
|---|
| 622 | var value = text.value;
|
|---|
| 623 |
|
|---|
| 624 | if( !chk.checked ){
|
|---|
| 625 | var s = '[ ' + page_url + ' : ' + page_title + ' ]';
|
|---|
| 626 | value = value.replace( s , '[ ' + page_url + ' ]' );
|
|---|
| 627 | text.value = value;
|
|---|
| 628 | }
|
|---|
| 629 | else{
|
|---|
| 630 | var s = '[ ' + page_url + ' ]';
|
|---|
| 631 | value = value.replace( s , '[ ' + page_url + ' : ' + page_title + ' ]' );
|
|---|
| 632 | text.value = value;
|
|---|
| 633 | }
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | // 発言をPOST
|
|---|
| 637 | function post(){
|
|---|
| 638 | clear_message();
|
|---|
| 639 | var t_chk = e('PostThisPage_check_twitter');
|
|---|
| 640 | var w_chk = e('PostThisPage_check_wassr');
|
|---|
| 641 | var h_chk = e('PostThisPage_check_hatenahike');
|
|---|
| 642 | var text = e('PostThisPage_textarea');
|
|---|
| 643 | var value = text.value;
|
|---|
| 644 |
|
|---|
| 645 | if( t_chk.checked) post_twitter( value );
|
|---|
| 646 |
|
|---|
| 647 | if( w_chk.checked) post_wassr( value );
|
|---|
| 648 |
|
|---|
| 649 | if( h_chk.checked) post_HatenaHike( value );
|
|---|
| 650 | }
|
|---|
| 651 |
|
|---|
| 652 | // TwitterにPost
|
|---|
| 653 | function post_twitter(status) {
|
|---|
| 654 | if( !use_twitter ) return;
|
|---|
| 655 | if( status.length > 140 ){
|
|---|
| 656 | append_message('発言が140文字を超えるため、Twitterには投稿しません。');
|
|---|
| 657 | return;
|
|---|
| 658 | }
|
|---|
| 659 | GM_xmlhttpRequest({
|
|---|
| 660 | method : 'post',
|
|---|
| 661 | url : 'http://twitter.com/statuses/update.json',
|
|---|
| 662 | headers: {
|
|---|
| 663 | 'Content-type': 'application/x-www-form-urlencoded',
|
|---|
| 664 | },
|
|---|
| 665 | data : 'status=' + encodeURIComponent(status),
|
|---|
| 666 | onload : function(res) {
|
|---|
| 667 | append_message('Twitterに投稿しました。');
|
|---|
| 668 | },
|
|---|
| 669 | onerror: function(res) {
|
|---|
| 670 | append_message('Twitterへの投稿に失敗しました。- ' + status + ' - ' + res.status + ': ' + res.statusText);
|
|---|
| 671 | },
|
|---|
| 672 | });
|
|---|
| 673 | }
|
|---|
| 674 |
|
|---|
| 675 | // WassrにPOST
|
|---|
| 676 | function post_wassr(status) {
|
|---|
| 677 | if( !use_wassr ) return;
|
|---|
| 678 | if( status.length > 255 ){
|
|---|
| 679 | append_message('発言が255文字を超えるため、Wassrには投稿しません。');
|
|---|
| 680 | return;
|
|---|
| 681 | }
|
|---|
| 682 |
|
|---|
| 683 | GM_xmlhttpRequest({
|
|---|
| 684 | method : 'post',
|
|---|
| 685 | url : 'http://api.wassr.jp/statuses/update.json',
|
|---|
| 686 | headers: {
|
|---|
| 687 | 'Content-type': 'application/x-www-form-urlencoded',
|
|---|
| 688 | },
|
|---|
| 689 | data : 'status=' + encodeURIComponent(status) + '&source=PostThisPage!',
|
|---|
| 690 | onload : function(res) {
|
|---|
| 691 | append_message('Wassrに投稿しました。');
|
|---|
| 692 | },
|
|---|
| 693 | onerror: function(res) {
|
|---|
| 694 | console.log(res);
|
|---|
| 695 | append_message('Wassrへの投稿に失敗しました。');
|
|---|
| 696 | },
|
|---|
| 697 | });
|
|---|
| 698 | }
|
|---|
| 699 |
|
|---|
| 700 | // はてなハイクにPOST
|
|---|
| 701 | function post_HatenaHike(status) {
|
|---|
| 702 | if( !use_hatenahike ) return;
|
|---|
| 703 | if( status.length > 255 ){
|
|---|
| 704 | append_message('発言が255文字を超えるため、はてなハイクには投稿しません。');
|
|---|
| 705 | return;
|
|---|
| 706 | }
|
|---|
| 707 |
|
|---|
| 708 | GM_xmlhttpRequest({
|
|---|
| 709 | method : 'post',
|
|---|
| 710 | url : 'http://h.hatena.ne.jp/api/statuses/update.json',
|
|---|
| 711 | headers: {
|
|---|
| 712 | 'Content-type': 'application/x-www-form-urlencoded',
|
|---|
| 713 | },
|
|---|
| 714 | data : 'status=' + encodeURIComponent(status) + '&source=PostThisPage!',
|
|---|
| 715 | onload : function(res) {
|
|---|
| 716 | append_message('はてなハイクに投稿しました。');
|
|---|
| 717 | },
|
|---|
| 718 | onerror: function(res) {
|
|---|
| 719 | console.log(res);
|
|---|
| 720 | append_message('はてなハイクへの投稿に失敗しました。');
|
|---|
| 721 | },
|
|---|
| 722 | });
|
|---|
| 723 | }
|
|---|
| 724 |
|
|---|
| 725 | // MessageをClear
|
|---|
| 726 | function clear_message( ){
|
|---|
| 727 | var m = e('PostThisPage_message');
|
|---|
| 728 | m.innerHTML = "";
|
|---|
| 729 | m.style.display = 'none';
|
|---|
| 730 | }
|
|---|
| 731 | // Messageを出す
|
|---|
| 732 | function append_message( msg ){
|
|---|
| 733 | var m = e('PostThisPage_message');
|
|---|
| 734 | m.innerHTML += msg + '<br/>';
|
|---|
| 735 | m.style.display = 'block';
|
|---|
| 736 | }
|
|---|
| 737 |
|
|---|
| 738 | // Util
|
|---|
| 739 | function c(tag_name) {
|
|---|
| 740 | return document.createElement(tag_name);
|
|---|
| 741 | }
|
|---|
| 742 |
|
|---|
| 743 | function u(id, text) {
|
|---|
| 744 | e(id).innerHTML = text;
|
|---|
| 745 | }
|
|---|
| 746 |
|
|---|
| 747 | function e(id) {
|
|---|
| 748 | return document.getElementById(id);
|
|---|
| 749 | }
|
|---|
| 750 |
|
|---|
| 751 | var console = {
|
|---|
| 752 | _defined: false,
|
|---|
| 753 | log: function(object) {
|
|---|
| 754 | if (!console._defined) {
|
|---|
| 755 | console._defined = true;
|
|---|
| 756 | location.href = "javascript:" + uneval(function() {
|
|---|
| 757 | document.addEventListener("consoleData",
|
|---|
| 758 | function(event) {
|
|---|
| 759 | console.log.apply(this, event.getData("object"));
|
|---|
| 760 | },
|
|---|
| 761 | false);
|
|---|
| 762 | }) + "()";
|
|---|
| 763 | }
|
|---|
| 764 | setTimeout(send, 100, arguments);
|
|---|
| 765 | function send(object) {
|
|---|
| 766 | var event = document.createEvent("DataContainerEvent");
|
|---|
| 767 | event.initEvent("consoleData", true, false);
|
|---|
| 768 | event.setData("object", object);
|
|---|
| 769 | document.dispatchEvent(event);
|
|---|
| 770 | }
|
|---|
| 771 | }
|
|---|
| 772 | };
|
|---|
| 773 |
|
|---|
| 774 |
|
|---|
| 775 | var ICON_IMAGE = 'data:image/png;base64,'+
|
|---|
| 776 | 'iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAMAAAC6V+0/AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ'+
|
|---|
| 777 | 'bWFnZVJlYWR5ccllPAAAAJNQTFRF+a1K+KAr+ac79ZU895cY95wk+NOi//nx+Lpp+MSA97BS+8J3'+
|
|---|
| 778 | '+8mG9Igl98mX+M6X/NCW+MmL96Ev/vLi+Ny596Y7+N25+L909q9q97Vd+rRZ/uvS9Y8x9pYk+Niu'+
|
|---|
| 779 | '9IEa9o0N+Nau9ZtH9rBp9rV1+rto9I4x97yA97x0/d20+Jkc95IN/Nal/eTD9HsP+ePF////7+nb'+
|
|---|
| 780 | '2wAAADF0Uk5T////////////////////////////////////////////////////////////////'+
|
|---|
| 781 | 'AB+aTiEAAADLSURBVHjabNHZcsIwDAVQObGDQxL2tS3QslPZvvz/11U4YGagepLPg65Gpmsqnzp6'+
|
|---|
| 782 | 'mvoHid0belOqN6Q5jHtBr2cosxckC8Bc7o+xrytSPNotFvuzYUVV7cnx1PYLIGzyJpxQ9K3O6Oq0'+
|
|---|
| 783 | 'kGCOSdNI0806MrNVQeQhWgxyehixF7bR2nTHBYJUPlne7L7S7xrh2PsBbJ327HA7ExhSQj8V/JoL'+
|
|---|
| 784 | 'FirhoIvZ6jszJcAJq6XVh7Fc1JQj/0Bi+oyBTvHggR/Pn3C38/0JMAA9ZzpShQk06wAAAABJRU5E'+
|
|---|
| 785 | 'rkJggg==';
|
|---|
| 786 |
|
|---|
| 787 | init();
|
|---|
| 788 |
|
|---|
| 789 |
|
|---|
| 790 | GM_registerMenuCommand('Post this page! - icon', setIconSetting);
|
|---|
| 791 | GM_registerMenuCommand('Post this page! - keybind', setKeybindSetting);
|
|---|
| 792 | GM_registerMenuCommand('Post this page! - Twitter', setTwitterSetting);
|
|---|
| 793 | GM_registerMenuCommand('Post this page! - Wassr', setWassrSetting);
|
|---|
| 794 | GM_registerMenuCommand('Post this page! - はてなハイク', setHatenaHikeSetting);
|
|---|
| 795 | })(); |
|---|