feat: initial

This commit is contained in:
tackchen 2020-10-21 18:09:34 +08:00
commit 23635f7e32
30 changed files with 835 additions and 0 deletions

15
.babelrc Normal file
View File

@ -0,0 +1,15 @@
{
"presets": [[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"targets": {
"esmodules": true
}
}
]],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-object-rest-spread"
]
}

4
.eslintignore Normal file
View File

@ -0,0 +1,4 @@
/public/bundle.js
/public/index.html
/npm
/cdn

61
.eslintrc.js Normal file
View File

@ -0,0 +1,61 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true,
"commonjs": true
},
"parserOptions": {
"parser": "babel-eslint",
"ecmaVersion": 2018,
"ecmaFeatures": {
"arrowFunctions": true,
"classes": true,
"modules": true,
"defaultParams": true,
"experimentalObjectRestSpread": true
},
"sourceType": "module",
"parserOptions": {
"allowImportExportEverywhere": true
}
},
"globals": {
"window": true,
},
"rules": {
"no-extend-native": 0,
"no-new": 0,
"no-useless-escape": 0,
"no-useless-constructor": 0,
"no-trailing-spaces": ["error", { "skipBlankLines": true }],
"indent": ["error", 4, {
"SwitchCase": 1
}],
"space-infix-ops": ["error", {"int32Hint": false}],
"space-before-function-paren": ["error", {
"anonymous": "always",
"named": "always",
"asyncArrow": "always"
}],
"semi": ["error", "always"],
"comma-dangle": 0,
"no-console": 0,
"no-debugger": 0,
"id-length": 0,
"eol-last": 0,
"object-curly-spacing": ["error", "never"],
"arrow-spacing": "error",
"no-multiple-empty-lines": "error",
"no-unused-vars": "error",
"spaced-comment": "error",
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"no-unreachable": "error",
"keyword-spacing": "error",
"space-before-blocks": "error",
"semi-spacing": "error",
"comma-spacing": "error",
"key-spacing": "error",
"no-undef": "error"
}
}

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules

29
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"editor.formatOnSave": false, // eslint
"eslint.validate": [
//.vue
"javascript",
"javascriptreact",
"html",
"vue",
{
"language": "html",
"autoFix": true
},
{
"language": "vue",
"autoFix": true
}
],
"search.exclude": {
"**/node_modules": true,
"**/cdn": true,
"**/npm": true
},
"eslint.autoFixOnSave": true,
"typescript.validate.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 - present
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

0
README.cn.md Normal file
View File

63
README.md Normal file
View File

@ -0,0 +1,63 @@
### This is a project build with [EBuild-Cli](https://github.com/theajack/ebuild-cli)
### Install dependencies
```
npm install
```
use taobao repository
```
npm install --registry https://registry.npm.taobao.org
```
### Init git repository
```
git init
git add README.md
git commit -m "first commit"
git remote add origin {Your remote git repository address}
git push -u origin master
```
### Commond
```
npm run dev
npm run build
npm run publish
npm run lint
```
### ebuild.config.js
```js
module.exports = {
'tranToEs5InNpm': true, // wether use babel
'packageFiles': [
'./package.json'
// config which package.json files need to modify version
// '../npm/package.json', // this is an example
],
'versioJsEs6Module': true, // use es6(export default) or require(module.exports=)
'versioJsFiles': [
// config which version.js files need to modify version
// '../npm/version.js', // this is an example
],
'name': '',
'version': '0.0.1',
'npmExternals': {
// example
// 'md5': 'md5'
},
'npmPaths': [
'npm'
]
};
```
### Vscode plugin
Install 'ESLint' plugin

10
commitlint.config.js Normal file
View File

@ -0,0 +1,10 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', [
'feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert'
]],
'subject-full-stop': [0, 'never'],
'subject-case': [0, 'never']
}
};

30
helper/copy-to-npm.js Normal file
View File

@ -0,0 +1,30 @@
const gulp = require('gulp');
const pkg = require('../package.json');
const util = require('./util');
function main () {
copyPkg();
copyFiles();
}
function copyPkg () {
let npmPkg = util.pick({
target: pkg,
attrs: [
'name', 'version', 'description', 'main', 'scripts', 'unpkg', 'jsdelivr',
'typings', 'repository', 'keywords', 'author', 'license', 'bugs', 'homepage'
]
});
util.write('npm/package.json', JSON.stringify(npmPkg, null, 4));
}
function copyFiles () {
gulp.src(['README.md', 'README.cn.md', 'LICENSE', 'src/index.d.ts'], {
allowEmpty: true
})
.pipe(gulp.dest('npm'));
}
main();

21
helper/util.js Normal file
View File

@ -0,0 +1,21 @@
let fs = require('fs');
module.exports = {
write: function (file, txt, cb) {
fs.writeFile(file, txt, 'utf8', (err) => {
if (err) throw err;
if (cb)cb();
});
},
pick: function ({data = {}, target, attrs}) {
if (!attrs) {
attrs = Object.keys(target);
}
attrs.forEach(name => {
if (typeof target[name] !== 'undefined')
data[name] = target[name];
});
return data;
}
};

21
npm/LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 - present
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

0
npm/README.cn.md Normal file
View File

67
npm/README.md Normal file
View File

@ -0,0 +1,67 @@
### This is a project build with [EBuild-Cli](https://github.com/theajack/ebuild-cli)
### Install dependencies
```
npm install
```
use taobao repository
```
npm install --registry https://registry.npm.taobao.org
```
### Init git repository
```
git init
git add README.md
git commit -m "first commit"
git remote add origin {Your remote git repository address}
git push -u origin master
```
### Commond
```
npm run dev
npm run build
npm run build:npm
npm run publish
npm run lint
npm run copy-latest
npm run modify-version
npm run copy-npm
```
### ebuild.config.js
```js
module.exports = {
'tranToEs5InNpm': true, // wether use babel
'packageFiles': [
'./package.json'
// config which package.json files need to modify version
// '../npm/package.json', // this is an example
],
'versioJsEs6Module': true, // use es6(export default) or require(module.exports=)
'versioJsFiles': [
// config which version.js files need to modify version
// '../npm/version.js', // this is an example
],
'name': '',
'version': '0.0.1',
'npmExternals': {
// example
// 'md5': 'md5'
},
'npmPaths': [
'npm'
]
};
```
### Vscode plugin
Install 'ESLint' plugin

1
npm/ebuild.min.js vendored Normal file
View File

@ -0,0 +1 @@
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("ebuild",[],t):"object"==typeof exports?exports.ebuild=t():e.ebuild=t()}(this,(function(){return function(e){var t={};function o(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=e,o.c=t,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=0)}([function(e,t){console.log("Hello world!"),alert("Hello world!")}])}));

0
npm/index.d.ts vendored Normal file
View File

28
npm/package.json Normal file
View File

@ -0,0 +1,28 @@
{
"name": "disable-devtool",
"version": "0.0.1",
"description": "Ebuild project",
"main": "ebuild.min.js",
"scripts": {
"build": "webpack --config webpack-config/build.js",
"publish": "npm publish npm",
"dev": "webpack-dev-server --open --config webpack-config/dev.js",
"lint": "eslint src --ext js"
},
"unpkg": "ebuild.min.js",
"jsdelivr": "ebuild.min.js",
"typings": "index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/theajack/ebuild-cli"
},
"keywords": [
"ebuild-cli"
],
"author": "theajack",
"license": "MIT",
"bugs": {
"url": ""
},
"homepage": ""
}

60
package.json Normal file
View File

@ -0,0 +1,60 @@
{
"name": "disable-devtool",
"version": "0.0.1",
"description": "Ebuild project",
"main": "ebuild.min.js",
"unpkg": "ebuild.min.js",
"jsdelivr": "ebuild.min.js",
"typings": "index.d.ts",
"bugs": {
"url": ""
},
"homepage": "",
"scripts": {
"dev": "webpack-dev-server --open --config webpack-config/dev.js",
"start": "npm run dev",
"build": "webpack --config webpack-config/build.js",
"publish": "npm publish npm",
"lint": "eslint src --ext js"
},
"author": "theajack",
"repository": {
"type": "git",
"url": "https://github.com/theajack/ebuild-cli"
},
"keywords": [
"ebuild-cli"
],
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.6.4",
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.6.3",
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"eslint": "^6.5.1",
"eslint-config-standard": "^14.1.0",
"eslint-loader": "^3.0.2",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-rename": "^2.0.0",
"husky": "^3.0.9",
"lint-staged": "^9.4.2",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.2"
},
"dependencies": {},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}

0
public/bundle.js Normal file
View File

12
public/index.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>A project build with EBuild-Cli</title>
</head>
<body>
<script src="./bundle.js"></script>
</body>
</html>

3
public/main.js Normal file
View File

@ -0,0 +1,3 @@
import {disableDevtool} from '../src';
disableDevtool();

16
src/config.js Normal file
View File

@ -0,0 +1,16 @@
import {closeWindow} from './util';
export let config = {
md5: '',
ondevtoolopen: closeWindow,
homeUrl: 'http://localhost',
tkName: 'ddtk',
};
export function mergeConfig (opts = {}) {
for (let k in config) {
if (opts[k] && typeof config[k] === typeof opts[k]) {
config[k] = opts[k];
}
}
}

0
src/index.d.ts vendored Normal file
View File

65
src/index.js Normal file
View File

@ -0,0 +1,65 @@
import {disableKeyAndMenu} from './key-menu';
import {initInterval, registInterval} from './interval';
import {closeWindow, getNowTime, getUrlParam} from './util';
import {mergeConfig, config} from './config';
import md5 from './md5';
let _onDevToolOpen = closeWindow;
export function disableDevtool (opts) {
mergeConfig(opts);
if (checkTk()) {
return;
}
initInterval();
disableKeyAndMenu();
initDebugger();
initDevTool();
}
export function onDevToolOpen () {
_onDevToolOpen();
}
function checkTk () {
if (config.md5) { // 启用了 md5
let tk = getUrlParam(config.tkName);
if (md5(tk) === config.md5) { // 命中tk
return true;
}
}
return false;
}
function initDebugger () {
let last = getNowTime();
registInterval(() => {
eval('debugger');
let now = getNowTime();
if (now - last > 1200) {
onDevToolOpen();
} else {
last = now;
}
});
}
function initDevTool () {
const isFF = ~navigator.userAgent.indexOf('Firefox');
let toTest = '';
if (isFF) {
toTest = /./;
toTest.toString = function () {
onDevToolOpen();
};
} else {
toTest = new Image();
toTest.__defineGetter__('id', function () {
onDevToolOpen();
});
}
registInterval(() => {
console.log(toTest);
console.clear && console.clear();
});
}

16
src/interval.js Normal file
View File

@ -0,0 +1,16 @@
let interval = null;
let calls = [];
export function initInterval (time = 1000) {
interval = window.setInterval(() => {
calls.forEach(fn => {fn();});
}, time);
}
export function registInterval (fn) {
calls.push(fn);
}
export function clearInterval () {
window.clearInterval(interval);
}

12
src/key-menu.js Normal file
View File

@ -0,0 +1,12 @@
export function disableKeyAndMenu () {
window.addEventListener('keydown', (e) => {
if (e.keyCode === 123 || (e.shiftKey && e.ctrlKey && e.keyCode === 73)) {
e.returnValue = false;
return false;
}
});
window.addEventListener('contextmenu', (e) => {
e.returnValue = false;
return false;
});
}

198
src/md5.js Normal file
View File

@ -0,0 +1,198 @@
/*
* Configurable variables. You may need to tweak these to be compatible with
* the server-side, but the defaults work in most cases.
*/
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
/*
* These are the functions you'll usually want to call
* They take string arguments and return either hex or base-64 encoded strings
*/
function hex_md5 (s) { return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
/*
* Calculate the MD5 of an array of little-endian words, and a bit length
*/
function core_md5 (x, len)
{
/* append padding */
x[len >> 5] |= 0x80 << ((len) % 32);
x[(((len + 64) >>> 9) << 4) + 14] = len;
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
for (var i = 0; i < x.length; i += 16)
{
var olda = a;
var oldb = b;
var oldc = c;
var oldd = d;
a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
a = safe_add(a, olda);
b = safe_add(b, oldb);
c = safe_add(c, oldc);
d = safe_add(d, oldd);
}
return Array(a, b, c, d);
}
/*
* These functions implement the four basic operations the algorithm uses.
*/
function md5_cmn (q, a, b, x, s, t)
{
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
}
function md5_ff (a, b, c, d, x, s, t)
{
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg (a, b, c, d, x, s, t)
{
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh (a, b, c, d, x, s, t)
{
return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii (a, b, c, d, x, s, t)
{
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
function safe_add (x, y)
{
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
/*
* Bitwise rotate a 32-bit number to the left.
*/
function bit_rol (num, cnt)
{
return (num << cnt) | (num >>> (32 - cnt));
}
/*
* Convert a string to an array of little-endian words
* If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
*/
function str2binl (str)
{
var bin = Array();
var mask = (1 << chrsz) - 1;
for (var i = 0; i < str.length * chrsz; i += chrsz)
bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (i % 32);
return bin;
}
/*
* Convert an array of little-endian words to a hex string.
*/
function binl2hex (binarray)
{
var hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef';
var str = '';
for (var i = 0; i < binarray.length * 4; i++)
{
str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) +
hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 )) & 0xF);
}
return str;
}
export default hex_md5;

26
src/util.js Normal file
View File

@ -0,0 +1,26 @@
export function isPC () {
return !/(iphone|ipad|ipod|ios|android)/i.test(navigator.userAgent.toLowerCase());
}
export function closeWindow (url = 'https://localhost') {
window.opener = null;
window.open('', '_self');
window.close();
window.location.href = url;
}
export function getNowTime () {
return new Date().getTime();
}
export function getUrlParam (name) {
let search = window.location.search;
if (search !== '') {
let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
let r = search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
}
return '';
}

23
webpack-config/build.js Normal file
View File

@ -0,0 +1,23 @@
const path = require('path');
require('../helper/copy-to-npm');
module.exports = {
mode: 'production',
entry: path.resolve('./', 'src/index.js'),
output: {
path: path.resolve('./', 'npm'),
filename: 'ebuild.min.js',
library: 'ebuild',
libraryTarget: 'umd',
umdNamedDefine: true,
globalObject: 'this'
},
module: {
rules: [{
test: /(.js)$/,
use: [{
loader: 'babel-loader',
}]
}]
}
};

32
webpack-config/dev.js Normal file
View File

@ -0,0 +1,32 @@
const path = require('path');
module.exports = {
entry: path.resolve('./', 'public/main.js'),
output: {
path: path.resolve('./', 'public'),
filename: 'bundle.js'
},
devtool: 'eval-source-map',
devServer: {
contentBase: path.resolve('./', 'public'),
historyApiFallback: true,
inline: true,
host: 'localhost'// '0.0.0.0' //
},
module: {
rules: [{
test: /(.js)$/,
use: [{
loader: 'babel-loader',
}]
}, {
test: /(.js)$/,
loader: 'eslint-loader',
enforce: 'pre',
exclude: /node_modules/,
options: {
configFile: './.eslintrc.js'
}
}]
}
};