-
Notifications
You must be signed in to change notification settings - Fork 0
/
JavaScript.html
executable file
·551 lines (472 loc) · 18.7 KB
/
JavaScript.html
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript.htm</title>
</head>
<body>
<p id="demo">段落</p>
<p id="demop">我的第一个段落</p>
<button onclick="myFunction()">点我</button>
<button id="myBtn" onclick="myFunction2(this)">点我2</button>
<button onclick='this.innerHTML=Date()'>现在的时间是?</button>∫∫
<button onclick="getElementById('demop').innerHTML=Date()">现在的时间是?</button>
<div id="div1"></div>
<p id="p1"></p>
<script>
//$('div.ie-fix').text()
// document.body.contentEditable='true';
// // 开启右键菜单
// document.oncontextmenu = function () { return true; };
// // 开启文字选择
// document.onselectstart = function () { return true; };
// // 开启复制
// document.oncopy = function () { return true; };
// // 开启剪切
// document.oncut = function () { return true; };
// // 开启粘贴
// document.onpaste = function () { return true; };
// // 开启F12键
// document.onkeydown = function () {
// if (window.event && window.event.keyCode == 123) {
// event.keyCode = 0;
// event.returnValue = true;
// return true;
// }
// };
document.write("<h1>这是一个标题</h1>");
//此处可使用 window.carName
//全局变量是 window 对象: 所有数据变量都属于 window 对象。
common()
function common(){
myboolean = false //将声明一个全局变量,即使它在函数内执行。
console.log(myboolean)
var mychar = 'x';
console.log(mychar);
console.log(mychar.charCodeAt(0));
console.log(String.fromCharCode(98));
let mystring = "bx23,4fgbt52dvg,e3"; ////用 let 来代替 var 来声明变量,就可以把变量限制在当前代码块中
console.log(mystring.charAt(1),mystring[0],mystring.length);
console.log(mystring.charCodeAt(1));
console.log(+mystring.replace(/[^0-9]/ig,""));
var intstring = "23";
console.log(JSON.parse(intstring),parseInt(intstring));//parseInt(mystring.toString())
var str = '123sdfsdf456sdffs789'
var numArr = str.match(/\d+/g)
// numArr = str.match(/\d+(\.\d+)*/g) //兼容
console.log(numArr) // => ["123", "456", "789"]
// console.log(+numArr.join('')) // => 123456789 // 也可以把拼接起来
var str = '123.456sdfsdf456.789'
// var y = new String("He is called \"Johnny\"");//不要创建 String 对象。它会拖慢执行速度,并可能产生其他副作用:
var numArr = str.match(/\d+\.\d+/g)
console.log(numArr) //=> ["123.456", "456.789"]// 这个就没法拼接了
my = 5; int = 6; myint = my + int;
console.log(myint);
varAll64=(5 + 6) * 10
console.log(varAll64);
console.log("Number.MAX_VALUE "+Number.MAX_VALUE);
double=3.14
doublee=123e-5
console.log(double,doublee);
console.log(parseInt(5/2)) //丢弃小数部分,保留整数部分
console.log(Math.round(5/2),Math.round(-5/2),0.0-Math.round(Math.abs(-5/2))) //四舍1234五入56789
console.log(Math.ceil(5/2)) //向上取整,有小数就整数部分加1
console.log(Math.floor(5/2)) //向下取整
//length
myarray = [40, 100, 1, 5, 25, 10]
console.log(myarray.length);
mystringfromarray = myarray.join("-");
myarrayfromString = mystring.split(",");// \\. \\|
var newLength = myarray.push('Orange');
console.log(newLength);
var last = myarray.pop();
console.log(last);
newLength = myarray.unshift('Banana') // add to the front
myarray.forEach(function (item, index, array) {
console.log(index,item);
});
var pos = myarray.indexOf('Banana');
var myarraycopy = myarray.slice();
var removedItem = myarray.splice(pos, 2); // this is how to remove 2* item
console.log(myarray,removedItem);
console.log(myarraycopy);
array = new Array(0, 1, 2, 3, 4);
array.sort(
function (v1, v2) {
return v1 - v2;
}
);
var cars = new Array;
var cars = new Object;
var cars = new Array();
cars[0] = "Saab";
cars[1] = "Volvo";
cars[2] = "BMW";
for (x in cars) {
document.write(cars[x] + "<br />")
}
var mymap = {
1 : "test",
"2" : myarray,
'x' : "delete"
}
console.log(mymap[1]);
delete mymap['x'];
// console.log(mymap['x']);
if(!mymap['x']) mymap['x'] = "add";
console.log(mymap['x']);
for(var key in mymap){
console.log(key+":"+mymap[key]);
}
//size
var m = new Map();
m.set(1, "black");
m.set(2, "red");
m.set("colors", 2);
m.forEach(function (item) {
console.log(item.toString());
});
for (var [key, value] of m) {
console.log(key + ' = ' + value);
}
console.log(m.get("colors"))
m.delete("colors")
console.log(m.size)
const set = new Set([1, 2, 3, 44, 5]);
set.add(7);
console.log(set.has(Math.sqrt(25)));
set.delete(44);
set.forEach(function (currentValue, key, array) {
console.log(currentValue+" "+array.size);
});
console.log(set.size);
var json = '{"employees":[' +
'{"firstName":"John","lastName":"Doe" },' +
'{"firstName":"Anna","lastName":"Smith" },' +
'{"firstName":"Peter","lastName":"Jones" }]}';
obj = JSON.parse(json);
document.getElementById("demo").innerHTML =
obj.employees[1].firstName + " " + obj.employees[1].lastName;
}
// function myFunction()
// {
// carName = "Volvo";
// document.write(Date());
// }
function myFunction2(call)
{
if(call.innerHTML == "this"){
call.innerHTML="点我2";
}else{
call.innerHTML="this";
}
}
//window.alert(5 + 6);
document.getElementById("demop").innerHTML = "段落已修改。";
// delete a[2];
//stack queue
//a.push(4) a.unshift
///a.pop(a) a.shift
//a.splice(绝对索引值3,删除该索引次数 0即为插入f否则为替换,array...)
var person={
firstname : "John",
lastname : "Doe",
id : 5566
};//Object
name=person.lastname;
name=person["lastname"];
var x, y, z;
x = 5
y = 6;
z = (x + y) * 10;
var carname="Volvo";
var carname;//变量 carname 的值依然是 "Volvo"
var carname=null;
// 我不会执行
document.write("你好 \
W3Cschool!");//折行
var x=5;
document.getElementById("demo").innerHTML=x===5;//true绝对等于
//==和!=操作符会进行类型强制转换
var x=5;
document.getElementById("demo").innerHTML=x!=="5";//true不绝对等于
//JavaScript逻辑运算符的优先级是:!、&& 、||。
typeof NaN // 返回 number
"John".constructor // 返回函数 String() { [native code] }
myarray.constructor.toString().indexOf("Array") > -1;//判断是否数组
// String(x) // 将变量 x 转换为字符串并返回
(123).toString();false.toString()
Number("3.14") // 返回 3.14
var y = "5"; // y 是一个字符串
var x = + y; // x 是一个数字
str = "this is w3cschool"
var n = str.search("w3cschool");
var res = str.replace(/microsoft/i, "w3cschool");//正则表达式
var patt = /e/;
var patt1=new RegExp("e");
patt.test("The best things in life are free!");//true 字符串中含有 "e"
/e/.exec("The best things in life are free!");
patt1.compile("d");//二次检索
var x = function (a, b) {return a * b};
var z = x(4, 3);
(function () {
return arguments.length; //调用自己,返回参数个数arguments[0] [1]...
})();
function myFunction(x, y) {
// if (y === undefined) {
// y = 0;
// }
y = y || 0;//undefined 为false
return x * y;
}
var myObject;
myFunction.call(myObject, 10, 2); // 返回 20
myArray = [10,2];
myFunction.apply(myObject, myArray); // 返回 20
var add = (function () {
var counter = 0;
return function () {return counter += 1;}
})();//闭包
var x=document.getElementById("demo");
var y=x.getElementsByTagName("p");
var z=document.getElementsByClassName("intro");
document.getElementById("demo").style.color="blue";
document.getElementById("myBtn").onclick=function(){displayDate()};
document.getElementById("myBtn").addEventListener("click", function(){
alert("Hello World!");
});//注意不是onclick
document.getElementById("myBtn").removeEventListener("mousemove", myFunctionmove);
window.addEventListener("resize", function(){
document.getElementById("demo").innerHTML = Math.random();
});
document.getElementById("myBtn").addEventListener("click", function() {
myFunction(p1, p2);
});
// function myFunction(a, b) {
// var result = a * b;
// document.getElementById("demo").innerHTML = result;
// }
////
var para=document.createElement("p");
var node=document.createTextNode("This is new.");
para.appendChild(node);
var element=document.getElementById("div1");
element.appendChild(para);
////
var child=document.getElementById("p1");
// var parent=document.getElementById("div1");
// parent.removeChild(child);
child.parentNode.removeChild(child);
////
var myNumber=128;
myNumber.toString(16); // returns 80 //16进制
myNumber.toString(8); // returns 200
myNumber.toString(2); // returns 10000000
isNaN("apple"); // returns true Not_a_Number
var x = 123;
var y = new Number(123);
(x === y) // is false because x is a number and y is an object.
Array.prototype.ucase=function()
{
for (i=0;i<this.length;i++)
{this[i]=this[i].toUpperCase();}
}
// debugger;
// document.execCommand(sCommand[,交互方式, 动态参数])
// javascript:alert(navigator.userAgent) //or appVersion
function myFunctionmove(){
var x;
var r=confirm("按下按钮!");//window.
if (r==true){
x="你按下了\"确定\"按钮!";
}
else{
x="你按下了\"取消\"按钮!";
}
document.getElementById("demo").innerHTML=x;
}
function myFunctionread(){
var x;
var person=prompt("请输入\n你的名字","Harry Potter");
if (person!=null && person!=""){
x="你好 " + person + "!今天感觉如何?";
document.getElementById("demo").innerHTML=x;
}
}
var myVar=setInterval(function(){myTimer()},1000);
function myTimer(){
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("demo").innerHTML=t;
}
function myStopFunction(){
clearInterval(myVar);
}//间隔指定的毫秒数不停地执行指定的代码。
//JS的几种跳转方式:
//window.open(”url“)
function openWin(tag,obj)
{
obj.target="_blank";
obj.href = "Web/Substation/Substation.aspx?stationno="+tag;
obj.click();
}
//window.location.href='';
//setTimeout('startTime()',500)
// t=setTimeout(function(){startTime()},500);//暂停指定的毫秒数后执行指定的代码
// document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
function owlRedirector(url) {
// if(url.indexOf("http%3A%2F%2F") == -1 && url.indexOf("https%3A%2F%2F") == -1) return url;
if (url.indexOf("https%3A%2F%2F") != -1){
index = url.indexOf("%3A%2F%2F");
return decodeURIComponent("https"+url.substr(index));
}else if (url.indexOf("http%3A%2F%2F") != -1) {
index = url.indexOf("%3A%2F%2F");
return decodeURIComponent("http" + url.substr(index));
}
return url;
}
function owlRedirector2(url) {
if (url.indexOf("http%3A") != -1 || url.indexOf("https%3A") != -1) {
url = decodeURIComponent(url);
url = url.replace(/.*url=/, "")
}
return url;
}
// encodeURI
// encodeURIComponent
// decodeURI
</script>
<a href="javascript:alert('Warning!!!')">点我!</a>
<!-- <a href="javascript:void(alert('Warning!!!'))">点我!</a> -->
<a href="#" onclick="subgo()">点我</a><!--刷新到顶部-->
<a href="####" >test</a> <!--不让刷新方法1-->
<a href="javascript:;" onclick="doSomething()">test</a>
<a href="#" onclick="doSomething();return false;">什么问题都解决了,包括浏览器不兼容问题</a> //或者直接使用href=""
<a href="#" onclick="alert();event.returnValue=false;">test</a>
<a href="javascript:void(0)" title="关闭" onclick="delbook();return false;">关闭</a>
<a href="javascript:void(0)" target="_self" title="关闭" onclick="delbook();">关闭</a>
<a href="javascript:void(0)" onclick="subgo()">点我</a>
<!-- #包含了一个位置信息,默认的锚是#top 也就是网页的上端。
而javascript:void(0), 仅仅表示一个死链接。
-->
<p>
您只能在 HTML 输出流中使用 <strong>document.write</strong>。
如果您在文档已加载后使用它(比如在函数中),会覆盖整个文档。
</p>
<!-- <script src="myscript.js"> -->
</body>
<script>
console.log(owlRedirectorFilter("http%3A%2F%2Fwww.google.com/search%3Fq%3Dcache:%27%2Bescape(document.location.href)%20%7D)()%3B"))
console.log(owlRedirectorFilter("https://link.zhihu.com/?target=https%3A//link.jianshu.com/%3Ft%3Dhttps%3A//twitter.com/timberners_lee"))
console.log(owlRedirectorFilter("https://mijisou.com/url_proxy?proxyurl=http%3A//www.so.com/link%3Furl%3Dhttp%253A%252F%252Fwww.360kuai.com%252Fpc%252F989bbf71b2a9abcb8%253Fcota%253D3%2526kuai_so%253D1%2526sign%253D360_7bc3b157%2526refer_scene%253Dso_55%26q%3D%25E6%2596%25B0%25E9%2597%25BB%26ts%3D1569510529%26t%3D53fdd6417c9d84a4c745a17b8841fb9&token=27af8d927f81aeba45c0ebfba4174e638cb622d7151fc29974b1a8d346a86e34"))
console.log(owlRedirectorFilter("https://www.jianshu.com/go-wild?ac=2&url=http%3A%2F%2Fmaven.apache.org%2Fref%2F3.2.2%2Fmaven-repository-metadata%2Frepository-metadata.html"))
// http:https://maven.apache.org/ref/3.2.2/maven-repository-metadata/repository-metadata.html
// /^https?:\/\/www\.jianshu\.com\/.*https?%3A%2F%2F/
//https://link.zhihu.com/?target=https%3A//link.jianshu.com/%3Ft%3Dhttps%3A//twitter.com/timberners_lee
// /^https?:\/\/.*https?%3A%2F%2F/
///^http.*\.(htm|html|jsp|asp|aspx|.*(http)+.*\..*)$/
///^http.*\.(htm|html|jsp|asp|aspx|[^\.]{8,})$/
///^http.*\.(htm|html|jsp|asp|aspx|.*\/[^\.]*)$/
///^http.*(.[^(htm|html|jsp|asp|aspx)]|\.[a-z]*(htm|html|jsp|asp|aspx))$/
///^http.*([^\.\w]|\.[a-z]*(htm|html|jsp|asp|aspx))$/
//copy start-----------------------------------------------------------------------------------------------
//copy start-----------------------------------------------------------------------------------------------
function owlRedirectorFilter(url) {
// 1. 返回 undefined,不跳转:
// return
// 2. 返回字符串,跳转到字符串所指的URL:
// return 'http:https://b.example.com/'
// 3. 返回''或者false,请求被阻止:
// return ''
// return false
var addUrlvideolist = [
//http:https://app.baiyug.cn:2019/vip/?url=">百域学院</a>
//http:https://qqe2.com/Video/default.html
"https://www.administratorw.com/admin.php?url=",
"https://www.sounm.com/?url=",//https://www.sounm.com/
"https://www.administratorw.com/video.php?url=",
"http:https://api.baiyug.vip/index.php?url=",//ad
"https://jx.618g.com/?url=",//ad
"http:https://www.zhmdy.top/index.php?zhm_jx=",
"https://jiexi.071811.cc/jx.php?url=",
"https://660e.com/?url=",
// https://www.socarchina.com/vip.htm
];
var addUrlvoicelist = [
//http:https://moresound.tk/music/
"https://www.socarchina.com/vipmusic/?url=",
"https://user.qzone.qq.com/NaN"
]
var _3A2F2F = [
"mail.qq.com/cgi-bin/mail_spam",//https://mail.qq.com/cgi-bin/mail_spam?action=check_link&url=https://github.com/&mailid=Gg4Gb3cLBggAFV9eXENuT2VMVFBfVUxZYXAHcAB2fw5U&spam=0
"mijisou.com",//"https://mijisou.com/url_proxy?proxyurl=http",
"zhihu.com",//"https://link.zhihu.com/?target=http",
"jianshu.com"//"https://www.jianshu.com/go-wild?ac=2&url="
]
//.replace("https://http//", "http:https://").replace("https//", "").replace("https://chrome//", "chrome:https://")
// url = url.replace('https://mijisou.com/url_proxy?proxyurl=http', 'http').replace('https://link.zhihu.com/?target=http', 'http')
if (url.indexOf("https%3A") != -1) {
_3A2F2F.forEach(function (item, index, array) {
if (url.indexOf(item) != -1) {
var pos = url.indexOf("https%3A");
if (url.indexOf("mail.qq") != -1) {
url = url.substr(pos);
var and = url.indexOf("&");
if (and != -1) url = url.substring(0, and);
} else url = url.substr(pos);
}
});
}else if (url.indexOf("http%3A") != -1) {
_3A2F2F.forEach(function (item, index, array) {
if (url.indexOf(item) != -1) {
var pos = url.indexOf("http%3A");
if (url.indexOf("mail.qq") != -1) {
url = url.substr(pos);
var and = url.indexOf("&");
if (and != -1) url = url.substring(0, and);
} else url = url.substr(pos);
}
});
}
if (url.indexOf("//v.youku.com") != -1 || url.indexOf("//v.qq.com") != -1 || url.indexOf("iqiyi.com") != -1) {
if (url.indexOf(addUrlvideolist[0]) != -1) return url;
return addUrlvideolist[0] + url;
} else if (url.indexOf("//www.1ting.com") != -1 || url.indexOf("//music.migu.c") != -1 || url.indexOf("//y.qq.com") != -1 || url.indexOf("//www.qingting.fm") != -1) {
if (url.indexOf(addUrlvoicelist[0]) != -1) return url;
return addUrlvoicelist[0] + encodeURIComponent(url);
// || url.indexOf("http:https://www.kugou.com") != -1 || url.indexOf("http:https://www.kuwo.c") != -1 || url.indexOf("http:https://www.xiami.com") != -1 || url.indexOf("http:https://music.baidu.com") != -1 || url.indexOf("http:https://www.lizhi.fm") != -1 || url.indexOf("http:https://www.ximalaya.com") != -1 || url.indexOf("kg.qq.com") != -1 || url.indexOf("http:https://5sing.kugou.com") != -1
/*
一听:http:https://www.1ting.com/player/b6/player_357838.html
咪咕:http:https://music.migu.cn/v2/music/song/477803
QQ:https://y.qq.com/n/yqq/song/002B2EAA3brD5b.html
蜻蜓:http:https://www.qingting.fm/channels/158696/programs/5266259
网易:http:https://music.163.com/#/song?id=25906124
酷狗:http:https://www.kugou.com/song/#hash=08228af3cb404e8a4e7e9871bf543ff6
酷我:http:https://www.kuwo.cn/yinyue/382425/
虾米:http:https://www.xiami.com/song/2113248
百度:http:https://music.baidu.com/song/266069
荔枝:http:https://www.lizhi.fm/1947925/2498707770886461446
喜马拉雅:http:https://www.ximalaya.com/51701370/sound/24755731
全民K歌(shareuid):http:https://kg.qq.com/node/personal?uid=619a958c25283e88
全民K歌(shareid):https://kg.qq.com/node/play?s=FA3h1gFhd6Vk7Ft4
5sing原创:http:https://5sing.kugou.com/yc/3082899.html
5sing翻唱:http:https://5sing.kugou.com/fc/14369766.html
*/
} else if (url.indexOf("https%3A%2F%2F") == 0) {
index = url.indexOf("%3A%2F%2F");
return decodeURIComponent("https" + url.substr(index));
} else if (url.indexOf("http%3A%2F%2F") == 0) {
index = url.indexOf("%3A%2F%2F");
return decodeURIComponent("http" + url.substr(index));
} else if (url.indexOf("https%3A") == 0) {
index = url.indexOf("https%3A");
return decodeURIComponent(url.substr(index));
} else if (url.indexOf("http%3A") == 0) {
index = url.indexOf("http%3A");
return decodeURIComponent(url.substr(index));
}
console.log(url)
return url;
}
</script>
</html>