0%

todo

php get DOM

remove script tags

https://stackoverflow.com/questions/7130867/remove-script-tag-from-html-content/7131085

美剧网 《爱,死亡和机器人 第一季》

https://91mjw.com/video/1295.htm

压缩 css

uglifycss –convert-urls test lib/font-awesome-4.7.0/css/font-awesome.min.css lib/ionicons-2.0.0/css/ionicons.min.css lib/mwa/mwa.css lib/animation.min.css \

css/ok.css

插件兼容AMD, CMD ,CommonJS和 原生 JS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
;(function(){
function MyModule() {
// ...
}
var moduleName = MyModule;
if (typeof module !== 'undefined' && typeof exports === 'object' && define.cmd) {
module.exports = moduleName;
} else if (typeof define === 'function' && define.amd) {
define(function() { return moduleName; });
} else {
this.moduleName = moduleName;
}
}).call(function() {
return this || (typeof window !== 'undefined' ? window : global);
});
1
2
3
4
5
6
7
8
9
if (typeof module != 'undefined' && module.exports) {  //CMD
module.exports = SB;
} else if (typeof define == 'function' && define.amd) { //AMD
define(function() {
return SB;
});
} else { //no AMD or CMD
window.SB= SB;
}
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
var root = (typeof self == 'object' && self.self == self && self) ||
(typeof global == 'object' && global.global == global && global)||
this || {};

//在浏览器中,除了window属性,我们也可以通过self属性直接访问到Window对象,同时self还可以支持Web Worker
//Node环境中全局变量为 global
//node vm(沙盒模型) 中不存在window,也不存在global变量,但我们却可以通过this访问到全局变量
//在微信小程序中,window和global都是undefined,加上强制使用严格模式,this为undefined,就多了{}

var _ = function(obj){

if(obj instanceof _){
return obj;
}

if(!(this instanceof _)){ // 此处为了实现面向对象风格调用,可以暂时不管
return new _(obj);
}
this._wrapped = obj;
};

//exports.nodeType 防止<div id="exports"></div>产生的window.exports全局变量。

if(typeof exports != 'undefined' && !exports.nodeType){
if((typeof module != 'undefined' && !module.nodeType && module.exports)){

//在nodeJs中,exports是module.exports 的一个引用,当你使用了module.exports = function(){}
//实际上覆盖了module.exports,但是exports并未发生改变,为了避免后面在修改exports而导致不能正确输出
//写成这样,将两者保持统一。

exports = module.exports = _;
}
exports._ = _;
}else{
//?不太懂部分,将_挂到全局属性_上
root._ = _;
}

via

array remove duplicated item

const arr = [22,33,22,44,22];

// 1
[…new Set(arr)];

// 2
arr.filter((k,j)=>arr.indexOf(k)=== j)

// 3
arr.reduce((tt,k)=>{
console.log(tt,k)
return tt.includes(k) ? tt: […tt,k]
},[])

via
https://medium.com/dailyjs/how-to-remove-array-duplicates-in-es6-5daa8789641c

uglifyjs 默认只能 es5

https://www.npmjs.com/package/uglify-es

需要安装

npm install uglify-es -g

uglifyjs gsmap.js -m -o gsmap.min.js

uglifyjs js/file1.js js/file2.js
-o foo.min.js -c -m
–source-map “root=’http://foo.com/src',url='foo.min.js.map'"

uglifyjs ../lib/axios.min.js gsmap.js
-c drop_console -m -o gsmap.min.js

压缩项目

uglifyjs main.js app.js pos.js
-c drop_console -m -o gs.min.js

let a = Array(14).fill().map((k,j)=>j+1);
a.reduce((tt,k)=>{
return tt+’curl https://i.jd.com/defaultImgs/'+k+'.jpg -o ‘+k+’.jpg\n’;
},’’)

n ES6 using Array from() and keys() methods.

Array.from(Array(10).keys())
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Shorter version using spread operator.

[…Array(10).keys()]
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

babel

https://blog.zfanw.com/babel-js/#babelcli

1231231314

abc

https://blog.zfanw.com/babel-js/#babel-套餐

const alertMe = (msg) => {
window.alert(msg)
}
class Robot {
constructor (msg) {
this.message = msg
}
say () {
alertMe(this.message)
}
}
const marvin = new Robot(‘hello babel’)

firebase-hosting-static-site

https://blog.zfanw.com/firebase-hosting-static-site/

iOS Safari 点击事件失效

这是移动端 Safari 至今仍存在的一个 bug 特性。

有几个解决办法:

最简单的,给 CSS 加上 cursor: pointer;
停止委托,直接给 #btn 绑定事件处理器;
给 div 元素加上 onclick=’void(0);’;
将 div 换成其它不受该 bug 特性影响的元素,比如 a、button 等。

有效 json

A comment first. The question was about not using try/catch.
If you do not mind to use it, read the answer below. Here we just check a JSON string using a regexp, and it will work in most cases, not all cases.

Have a look around the line 450 in https://github.com/douglascrockford/JSON-js/blob/master/json2.js

There is a regexp that check for a valid JSON, something like:

1
2
3
4
5
6
7
8
9
10
11
if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

//the json is ok

}else{

//the json is not ok

}

pan.baidu.com

davidguoshuang@gmail.com

mqtt

http://test.mosquitto.org/ws.html
http://louiszhai.github.io/2017/04/28/array/#keys-ES6
https://juejin.im/post/5d66b019f265da03a715e5d7
https://dev.to/saigowthamr/how-to-loop-through-object-in-javascript-es6-3d26