From 23635f7e32f0a6996292cf946fef317a2929666a Mon Sep 17 00:00:00 2001 From: tackchen Date: Wed, 21 Oct 2020 18:09:34 +0800 Subject: [PATCH] feat: initial --- .babelrc | 15 +++ .eslintignore | 4 + .eslintrc.js | 61 +++++++++++++ .gitignore | 1 + .vscode/settings.json | 29 ++++++ LICENSE | 21 +++++ README.cn.md | 0 README.md | 63 +++++++++++++ commitlint.config.js | 10 ++ helper/copy-to-npm.js | 30 ++++++ helper/util.js | 21 +++++ npm/LICENSE | 21 +++++ npm/README.cn.md | 0 npm/README.md | 67 ++++++++++++++ npm/ebuild.min.js | 1 + npm/index.d.ts | 0 npm/package.json | 28 ++++++ package.json | 60 ++++++++++++ public/bundle.js | 0 public/index.html | 12 +++ public/main.js | 3 + src/config.js | 16 ++++ src/index.d.ts | 0 src/index.js | 65 +++++++++++++ src/interval.js | 16 ++++ src/key-menu.js | 12 +++ src/md5.js | 198 ++++++++++++++++++++++++++++++++++++++++ src/util.js | 26 ++++++ webpack-config/build.js | 23 +++++ webpack-config/dev.js | 32 +++++++ 30 files changed, 835 insertions(+) create mode 100644 .babelrc create mode 100644 .eslintignore create mode 100644 .eslintrc.js create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 LICENSE create mode 100644 README.cn.md create mode 100644 README.md create mode 100644 commitlint.config.js create mode 100644 helper/copy-to-npm.js create mode 100644 helper/util.js create mode 100644 npm/LICENSE create mode 100644 npm/README.cn.md create mode 100644 npm/README.md create mode 100644 npm/ebuild.min.js create mode 100644 npm/index.d.ts create mode 100644 npm/package.json create mode 100644 package.json create mode 100644 public/bundle.js create mode 100644 public/index.html create mode 100644 public/main.js create mode 100644 src/config.js create mode 100644 src/index.d.ts create mode 100644 src/index.js create mode 100644 src/interval.js create mode 100644 src/key-menu.js create mode 100644 src/md5.js create mode 100644 src/util.js create mode 100644 webpack-config/build.js create mode 100644 webpack-config/dev.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..10c0a41 --- /dev/null +++ b/.babelrc @@ -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" + ] +} \ No newline at end of file diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..827029e --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +/public/bundle.js +/public/index.html +/npm +/cdn \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..3d5732d --- /dev/null +++ b/.eslintrc.js @@ -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" + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..30bc162 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/node_modules \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f9f9228 --- /dev/null +++ b/.vscode/settings.json @@ -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 + } + } + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..06f6ebb --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/README.cn.md b/README.cn.md new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..d179dc7 --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..2d2ccae --- /dev/null +++ b/commitlint.config.js @@ -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'] + } +}; diff --git a/helper/copy-to-npm.js b/helper/copy-to-npm.js new file mode 100644 index 0000000..784676a --- /dev/null +++ b/helper/copy-to-npm.js @@ -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(); \ No newline at end of file diff --git a/helper/util.js b/helper/util.js new file mode 100644 index 0000000..344890f --- /dev/null +++ b/helper/util.js @@ -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; + } +}; \ No newline at end of file diff --git a/npm/LICENSE b/npm/LICENSE new file mode 100644 index 0000000..06f6ebb --- /dev/null +++ b/npm/LICENSE @@ -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. \ No newline at end of file diff --git a/npm/README.cn.md b/npm/README.cn.md new file mode 100644 index 0000000..e69de29 diff --git a/npm/README.md b/npm/README.md new file mode 100644 index 0000000..9b9c7e8 --- /dev/null +++ b/npm/README.md @@ -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 \ No newline at end of file diff --git a/npm/ebuild.min.js b/npm/ebuild.min.js new file mode 100644 index 0000000..f05e754 --- /dev/null +++ b/npm/ebuild.min.js @@ -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!")}])})); \ No newline at end of file diff --git a/npm/index.d.ts b/npm/index.d.ts new file mode 100644 index 0000000..e69de29 diff --git a/npm/package.json b/npm/package.json new file mode 100644 index 0000000..a0b1749 --- /dev/null +++ b/npm/package.json @@ -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": "" +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..72cf6b8 --- /dev/null +++ b/package.json @@ -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" + } + } +} diff --git a/public/bundle.js b/public/bundle.js new file mode 100644 index 0000000..e69de29 diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..a7ac11e --- /dev/null +++ b/public/index.html @@ -0,0 +1,12 @@ + + + + + + + A project build with EBuild-Cli + + + + + \ No newline at end of file diff --git a/public/main.js b/public/main.js new file mode 100644 index 0000000..c79b51c --- /dev/null +++ b/public/main.js @@ -0,0 +1,3 @@ +import {disableDevtool} from '../src'; + +disableDevtool(); \ No newline at end of file diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..fbe856f --- /dev/null +++ b/src/config.js @@ -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]; + } + } +} \ No newline at end of file diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..7284e4c --- /dev/null +++ b/src/index.js @@ -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(); + }); +} \ No newline at end of file diff --git a/src/interval.js b/src/interval.js new file mode 100644 index 0000000..35f4b38 --- /dev/null +++ b/src/interval.js @@ -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); +} \ No newline at end of file diff --git a/src/key-menu.js b/src/key-menu.js new file mode 100644 index 0000000..7144244 --- /dev/null +++ b/src/key-menu.js @@ -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; + }); +} \ No newline at end of file diff --git a/src/md5.js b/src/md5.js new file mode 100644 index 0000000..a8b862e --- /dev/null +++ b/src/md5.js @@ -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; \ No newline at end of file diff --git a/src/util.js b/src/util.js new file mode 100644 index 0000000..db78086 --- /dev/null +++ b/src/util.js @@ -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 ''; +} \ No newline at end of file diff --git a/webpack-config/build.js b/webpack-config/build.js new file mode 100644 index 0000000..e2b5670 --- /dev/null +++ b/webpack-config/build.js @@ -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', + }] + }] + } +}; \ No newline at end of file diff --git a/webpack-config/dev.js b/webpack-config/dev.js new file mode 100644 index 0000000..15551d0 --- /dev/null +++ b/webpack-config/dev.js @@ -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' + } + }] + } +}; \ No newline at end of file