forked from NV/nice-alert.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnice_alert.user.js
109 lines (97 loc) · 3.43 KB
/
nice_alert.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// ==UserScript==
// @name Nice alert
// @namespace http://userscripts.ru/js/nice-alert/
// @include *
// @description Makes alert box suck less
// @copyright 2008+, Nikita Vasilyev (http://userscripts.org/scripts/show/43780)
// @version 1.1
// @licence LGPL 3
// ==/UserScript==
(function(){
var w = window.wrappedJSObject || window;
if (w.alert.is_nice) return;
w.alert = function alert (msg){
if (typeof GM_addStyle == 'undefined') {
/**
* Example: GM_addStyle('* {color:red}')
* @param {String} css
*/
function GM_addStyle(css) {
var head = document.getElementsByTagName('head')[0];
if (head) {
var style = document.createElement("style");
style.type = "text/css";
style.appendChild(document.createTextNode(css));
head.appendChild(style);
}
}
}
GM_addStyle('#nice_alert {\
font: 14px/16px sans-serif !important;\
position: fixed !important;\
top: 0 !important;\
right: 0 !important;\
margin: 0 !important;\
padding: 0 !important;\
list-style-type: none !important;\
float: left !important;\
cursor: pointer !important;\
text-align: left !important;\
z-index: 9999 !important;\
}\
#nice_alert ALERTBOX {\
background-color: InfoBackground !important;\
color: InfoText !important;\
border-bottom: 1px solid #ccc !important;\
border-bottom: 1px solid rgba(0,0,0,0.3) !important;\
margin: 0 !important;\
opacity: 0;\
float: right !important;\
clear: both !important;\
overflow: hidden !important;\
font-size: 14px !important;\
white-space: pre-wrap !important;\
outline: 0 !important;\
-webkit-box-shadow: 0px 2px 8px rgba(0,0,0,0.2);\
-moz-box-shadow: 0px 2px 8px rgba(0,0,0,0.3);\
}');
var nice_alert = document.getElementById('nice_alert') || document.createElement('ALERTGROUP');
nice_alert.id = 'nice_alert';
document.documentElement.appendChild(nice_alert);
nice_alert.addEventListener('click',function(e){
var t = e.target;
if (t.tagName == 'ALERTBOX') {
var h = t.clientHeight - 18;
t.style.height = h +'px';
var closing = setInterval(function(){
t.style.opacity -= 0.1;
t.style.paddingTop = parseInt(t.style.paddingTop) - 1 +'px';
t.style.paddingBottom = parseInt(t.style.paddingBottom) - 1 +'px';
var currentHeight = parseInt(t.style.height) - h/10;
t.style.height = (currentHeight < 0 ? 0 : currentHeight) +'px';
if (t.style.opacity <= 0) {
t.style.display = 'none';
clearInterval(closing);
}
}, 30);
}
}, false);
var cache = document.createElement('ALERTBOX');
cache.style.padding = '0px 16px';
cache.tabIndex = 0;
(w.alert = function alert (msg) {
w.alert.is_nice = 'Of course it is!';
var box = cache.cloneNode(false);
box.appendChild(document.createTextNode(msg));
nice_alert.appendChild(box);
var showing = setInterval(function(){
box.style.opacity = box.style.opacity/1 + 0.1;
box.style.paddingTop = parseInt(box.style.paddingTop) + 1 +'px';
box.style.paddingBottom = parseInt(box.style.paddingBottom) + 1 +'px';
if (box.style.opacity >= 0.9) {
clearInterval(showing);
}
}, 30);
})(msg);
};
})();