| | 459 | // copied from FLASH KEY (c) id:brazil |
| | 460 | // http://userscripts.org/scripts/show/11996 |
| | 461 | // slightly modified. |
| | 462 | var FlashMessage = new function(){ |
| | 463 | GM_addStyle(<><![CDATA[ |
| | 464 | #FLASH_MESSAGE{ |
| | 465 | position : fixed; |
| | 466 | font-size : 200%; |
| | 467 | z-index : 10000; |
| | 468 | |
| | 469 | padding : 20px 50px 20px 50px; |
| | 470 | left : 50%; |
| | 471 | top : 50%; |
| | 472 | margin : -1em; |
| | 473 | |
| | 474 | background-color : #444; |
| | 475 | color : #FFF; |
| | 476 | -moz-border-radius: 0.3em; |
| | 477 | min-width : 1em; |
| | 478 | text-align : center; |
| | 479 | } |
| | 480 | ]]></>) |
| | 481 | var opacity = 0.9; |
| | 482 | var flash = document.createElement('div'); |
| | 483 | flash.id = 'FLASH_MESSAGE'; |
| | 484 | hide(flash); |
| | 485 | document.body.appendChild(flash); |
| | 486 | var canceler; |
| | 487 | this.showFlashMessageWindow = function (string, duration) { |
| | 488 | duration = duration || 400; |
| | 489 | canceler && canceler(); |
| | 490 | flash.innerHTML = string; |
| | 491 | flash.style.MozOpacity = opacity; |
| | 492 | show(flash); |
| | 493 | flash.style.marginLeft = (-(flash.offsetWidth/2))+'px'; |
| | 494 | |
| | 495 | canceler = callLater(function(){ |
| | 496 | canceler = tween(function(value){ |
| | 497 | flash.style.MozOpacity = opacity * (1-value); |
| | 498 | }, 100, 5); |
| | 499 | }, duration); |
| | 500 | }; |
| | 501 | |
| | 502 | // ----[Utility]------------------------------------------------- |
| | 503 | function callLater(callback, interval){ |
| | 504 | var timeoutId = setTimeout(callback, interval); |
| | 505 | return function(){ |
| | 506 | clearTimeout(timeoutId) |
| | 507 | } |
| | 508 | } |
| | 509 | function tween(callback, span, count){ |
| | 510 | count = (count || 20); |
| | 511 | var interval = span / count; |
| | 512 | var value = 0; |
| | 513 | var calls = 0; |
| | 514 | var intervalId = setInterval(function(){ |
| | 515 | callback(calls / count); |
| | 516 | |
| | 517 | if(count == calls){ |
| | 518 | canceler(); |
| | 519 | return; |
| | 520 | } |
| | 521 | calls++; |
| | 522 | }, interval); |
| | 523 | var canceler = function(){ |
| | 524 | clearInterval(intervalId) |
| | 525 | hide(flash) |
| | 526 | } |
| | 527 | return canceler; |
| | 528 | } |
| | 529 | function hide(target){ |
| | 530 | target.style.display='none'; |
| | 531 | } |
| | 532 | function show(target, style){ |
| | 533 | target.style.display=(style || ''); |
| | 534 | } |
| | 535 | } |
| | 536 | |