Ai
1 Star 1 Fork 1

草鞋没号/test-http-proxy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
extra.js 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
草鞋没号 提交于 2020-12-08 15:39 +08:00 . first commit
/**
* 外部插入 JS
*/
; (function () {
/** docoment 加载完成 */
function domReady() {
const condition = arguments.length ? Array.from(arguments) : ['complete', 'interactive'];
return new Promise(resolve => {
if (condition.includes(document.readyState)) {
resolve(true);
} else {
document.addEventListener('readystatechange', () => {
if (condition.includes(document.readyState)) {
resolve(true);
}
});
}
});
}
/** element 选择器 */
function el(selector = '') {
const els = document.querySelectorAll(selector);
if (!els.length) {
return null;
} else if (els.length === 1) {
return els[0];
} else {
return els;
}
}
/** 创建 DOM */
function creDom(arg0) {
arg0 = arg0 || {};
const dom = document.createElement(arg0.tag || 'div');
if (typeof arg0.style === 'object') {
creDom.prototype.setDomStyle(dom, arg0.style);
} else if (typeof arg0.cssText === 'string') {
dom.style.cssText += arg0.cssText;
}
if (typeof arg0.className !== 'undefined') {
creDom.prototype.setDomClassName(dom, arg0.className);
}
dom.setStyle = creDom.prototype.setDomStyle;
dom.setClassName = creDom.prototype.setDomClassName;
return dom;
}
creDom.prototype.setDomStyle = (dom, style) => {
for (const [k, v] of Object.entries(style)) dom.style[k] = v;
};
creDom.prototype.setDomClassName = (dom, className) => {
if (typeof className === 'string') {
dom.classList.add(className);
} else if (Array.isArray(className)) {
dom.classList.add.apply(null, className);
}
};
// 插入 Button
const oButton = creDom({ tag: 'button' });
oButton.innerHTML = '==== 自定义按钮 ====';
el('body').appendChild(oButton);
}());
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cxmh/test-http-proxy.git
git@gitee.com:cxmh/test-http-proxy.git
cxmh
test-http-proxy
test-http-proxy
master

搜索帮助