夜火博客

Javascript模拟的DOS窗口

2007-05-13
技术文章
脚本Script
3分钟
563字

from;0009’s blog [按九下”最小化”按钮可以关闭]

1
<html>
2
<head>
3
<title>夏天以南</title>
4
<script>
5
var timer;
6
var win = window.createPopup();
7
var cmdIndex = 0;
8
var closeMe = 0;
9
var currentCmdWindow;
10
function CurrentCmdFocus(obj)
11
{
12
 currentCmdWindow = obj;
13
 obj.rows(0).cells(0).style.filter = "progid:DXImageTransform.Microsoft.gradient(startColorStr=#0054E3,endColorStr=#358DFB,GradientType=1)";
14
 obj.style.zIndex = cmdIndex++;
15
}
162 collapsed lines
16
function CurrentCmdBlur(obj)
17
{
18
 var line = obj.getElementsByTagName("P")[obj.getElementsByTagName("P").length - 1];
19
 line.innerText = line.innerText.replace(/_$/, "");
20
 obj.rows(0).cells(0).style.filter = "progid:DXImageTransform.Microsoft.gradient(startColorStr=#6B79B8,endColorStr=#8C9ADB,GradientType=1)";
21
}
22
function CloseButtonClick(src)
23
{
24
 var msg1 = " CLOSE?
25
" +
26
 " 系统提示: 其实, 这只是一个普通的叉叉, 不是用来关闭的~~ @o@
27
" +
28
 "C:\WINDOWS\system32>";
29
 var paragraphs = src.parentNode.parentNode.parentNode.getElementsByTagName("P");
30
 paragraphs[paragraphs.length - 1].innerText = paragraphs[paragraphs.length - 1].innerText.replace(/_$/, "") + msg1;
31
}
32
function MaximizeButtonClick(src)
33
{
34
 var msg1 = " MAXIMIZE?
35
" +
36
 " 错了 #o#
37
" +
38
 "C:\WINDOWS\system32>";
39
 var paragraphs = src.parentNode.parentNode.parentNode.getElementsByTagName("P");
40
 paragraphs[paragraphs.length - 1].innerText = paragraphs[paragraphs.length - 1].innerText.replace(/_$/, "") + msg1;
41
 CreateCmdWindow(win.document.getElementById("Frame"),
42
 GetRandomNum(win.document.body.clientWidth - 400),
43
 GetRandomNum(win.document.body.clientHeight - 300));
44
}
45
function MinimizeButtonClick(src)
46
{
47
 if (closeMe < 9)
48
 {
49
 var msg1 = " MINIMIZE?
50
" +
51
 " 多按几下 ^-^
52
" +
53
 "C:\WINDOWS\system32>";
54
 var paragraphs = src.parentNode.parentNode.parentNode.getElementsByTagName("P");
55
 paragraphs[paragraphs.length - 1].innerText = paragraphs[paragraphs.length - 1].innerText.replace(/_$/, "") + msg1;
56
 closeMe++;
57
 }
58
 else
59
 {
60
 clearTimeout(timer);
61
 win.hide();
62
 window.document.body.style.display = "";
63
 window.document.body.innerHTML = "<div style="font:32pt;font-weight:bold;color:#BE5100;"><p></p><p></p></div>";
64
 setTimeout("Welcome(0)", 400);
65
 }
66
}
67
68
function Welcome(n)
69
{
70
 var msg1 = "Welcome to Neeao's blog ^_^";
71
 var msg2 = "<a href="http://www.neeao.com">Click Here</a>";
72
 if(n < msg1.length)
73
 {
74
 window.document.getElementsByTagName("P")[0].innerText += msg1.substr(n, 1);
75
 n++;
76
 setTimeout("Welcome(" + n + ")", 200);
77
 }
78
 else
79
 {
80
 window.document.getElementsByTagName("P")[1].innerHTML = msg2;
81
 }
82
}
83
84
function OpenCmdWindow(height)
85
{
86
 if (height < window.screen.availHeight)
87
 {
88
 height += 50;
89
 if (height >= window.screen.availHeight)
90
 {
91
 height = window.screen.availHeight;
92
 win.show(0, 0, window.screen.availWidth, window.screen.availHeight);
93
 CreateCmdWindow(win.document.getElementById("Frame"), 10, 10);
94
 Wink(true);
95
 }
96
 else
97
 {
98
 win.show(0, 0, window.screen.availWidth, height);
99
 }
100
 }
101
 else if (!win.isOpen)
102
 {
103
 win.show(0, 0, window.screen.availWidth, window.screen.availHeight);
104
 }
105
 timer = setTimeout("OpenCmdWindow(" + height + ")", 50);
106
}
107
108
function CreateCmdWindow(obj, left, top)
109
{
110
 var cmdWindow = win.document.createElement("TABLE");
111
 cmdWindow.border = 1;
112
 cmdWindow.className = "Cmd";
113
 cmdWindow.style.left = left;
114
 cmdWindow.style.top = top;
115
 cmdWindow.style.zIndex = cmdIndex++;
116
 var newRow = cmdWindow.insertRow();
117
 var newCell = newRow.insertCell();
118
 newCell.className = "Title";
119
 newCell.innerHTML = "<span>&nbsp;C:\WINDOWS\system32\cmd.exe</span>" +
120
 "<button onclick="window.parent.CloseButtonClick(this);">&times;</button>" +
121
 "<button onclick="window.parent.MaximizeButtonClick(this);">□</button>" +
122
 "<button onclick="window.parent.MinimizeButtonClick(this);">-</button>";
123
 newRow = cmdWindow.insertRow();
124
 newCell = newRow.insertCell();
125
 newCell.innerHTML = "<div class="Content">" +
126
 "<p>Microsoft Windows XP [Version 5.1.2600]</p>" +
127
 "<p>(C) Copyright 1985-2001 Microsoft Corp.</p>" +
128
 "<p>&nbsp;</p>" +
129
 "<p>C:\WINDOWS\system32&gt;</p>" +
130
 "<div class="Adorn"></div>" +
131
 "</div>";
132
 cmdWindow.onactivate = function (){ window.parent.CurrentCmdFocus(this); }
133
 cmdWindow.ondeactivate = function (){ window.parent.CurrentCmdBlur(this); }
134
 obj.appendChild(cmdWindow);
135
}
136
137
function Wink(show)
138
{
139
 if(currentCmdWindow != undefined && currentCmdWindow != null)
140
 {
141
 var line = currentCmdWindow.getElementsByTagName("P")[currentCmdWindow.getElementsByTagName("P").length - 1];
142
 if(show)
143
 {
144
 line.innerText += "_";
145
 }
146
 else
147
 {
148
 line.innerText = line.innerText.replace(/_$/, "");
149
 }
150
 }
151
 setTimeout("Wink(" + !show + ")", 500);
152
}
153
154
function GetRandomNum(max)
155
{
156
 return parseInt(Math.random() * max + 1);
157
}
158
159
window.onload = function()
160
{
161
 win.document.body.innerHTML = "<div id="Frame" onselectstart="return false;"></div>";
162
 win.document.appendChild(win.document.createElement("STYLE"));
163
 win.document.styleSheets[0].addRule("body", "padding: 0px; margin: 0px;");
164
 win.document.styleSheets[0].addRule("#Frame", "width: 100%; height: 100%; background: #3A6EA5;");
165
 win.document.styleSheets[0].addRule(".Cmd", "background: #fff; position: absolute; width: 670px; height: 440px; font-size: 10pt; color: #fff; cursor: default;");
166
 win.document.styleSheets[0].addRule(".Title", "filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#6B79B8,endColorStr=#8C9ADB,GradientType=1); height: 24px; font-weight: bold;");
167
 win.document.styleSheets[0].addRule(".Title span", "float: left; line-height: 20px;");
168
 win.document.styleSheets[0].addRule(".Title button", "width: 18px; height: 18px; float: right; font: 9pt; font-weight: bold; text-algin: center; margin: 2px 1px 0px 0px; border: outset 2px #fff;");
169
 win.document.styleSheets[0].addRule(".Content", "background: #000; height: 100%; overflow-y: scroll; scrollbar-face-color: #ece9d8; scrollbar-highlight-color: #ffffff; scrollbar-shadow-color: #ccc; scrollbar-arrow-color: #000000; scrollbar-track-color: #eeeeee; scrollbar-darkshadow-color: #666; scrollbar-base-color: #ece9d8;");
170
 win.document.styleSheets[0].addRule(".Content p", "margin: 0px; line-height: 16px;");
171
 win.document.styleSheets[0].addRule(".Content .Adorn", "height: 4000px;");
172
 OpenCmdWindow(0);
173
}
174
</script>
175
</head>
176
<body style="display: none;"></body>
177
</html>
本文标题:Javascript模拟的DOS窗口
文章作者:夜火
发布时间:2007-05-13