diff --git a/plugins/babel-plugin-canyon/package.json b/plugins/babel-plugin-canyon/package.json index ceeed079..cc643dd6 100644 --- a/plugins/babel-plugin-canyon/package.json +++ b/plugins/babel-plugin-canyon/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-canyon", - "version": "1.8.78", + "version": "1.8.78-alpha.1", "description": "", "main": "lib/index.js", "files": [ diff --git a/plugins/babel-plugin-canyon/src/index.js b/plugins/babel-plugin-canyon/src/index.js index fa36692d..d89e351e 100644 --- a/plugins/babel-plugin-canyon/src/index.js +++ b/plugins/babel-plugin-canyon/src/index.js @@ -6,6 +6,7 @@ import {generateInitialCoverage} from "./helpers/generate-initial-coverage"; import {generateCanyon} from "./helpers/generate-canyon"; const canyonTemplate = template(tep["templates/canyon.template.js"]); const writeCanyonToLocalTemplate = template(tep["templates/write-canyon-to-local-template.js"]) +const injectInPagePopupTemplate = template(tep["templates/inject-in-page-popup.js"]) import packageJson from '../package.json' // 转换配置,优先级:babel配置 > 环境变量 @@ -71,9 +72,11 @@ export default declare((api,config) => { const writeCanyonToLocal = writeCanyonToLocalTemplate({ JSON: 'JSON' }) + const injectInPagePopup = injectInPagePopupTemplate() path.node.body.unshift(canyon) // TODO: 需要删除writeCanyonToLocal path.node.body.unshift(writeCanyonToLocal) + path.node.body.unshift(injectInPagePopup) // 必须校验数据完整性 diff --git a/plugins/babel-plugin-canyon/templates/inject-in-page-popup.js b/plugins/babel-plugin-canyon/templates/inject-in-page-popup.js new file mode 100644 index 00000000..dfdc72f3 --- /dev/null +++ b/plugins/babel-plugin-canyon/templates/inject-in-page-popup.js @@ -0,0 +1,102 @@ +(function () { + var globalObj = undefined; + try { + globalObj = new Function('return this')(); + } catch (e) { + if (typeof window !== "undefined") { + globalObj = window; + } else if (typeof global !== "undefined") { + globalObj = global; + } else { + // do nothing + } + } + if (globalObj){ + + // ***start*** + + if (globalObj.ssssssssssssss) { + } else { + globalObj.ssssssssssssss = true + if (globalObj.document && globalObj.document.addEventListener) { + + + // 逻辑 + + + + + // 点击它打开一个全屏弹窗 + + // 插入一个div + const modal = document.createElement('div'); + modal.innerHTML = '全屏弹窗'; + document.body.appendChild(modal); + // 添加样式 + modal.style.display = 'none'; + modal.style.position = 'fixed'; + modal.style.top = 0; + modal.style.left = 0; + modal.style.width = '100%'; + modal.style.height = '100%'; + modal.style.backgroundColor = 'rgba(0, 0, 0, 0.8)'; + modal.style.color = 'white'; + modal.style.display = 'flex'; + modal.style.justifyContent = 'center'; + modal.style.alignItems = 'center'; + modal.style.zIndex = 9998; + + // 点击关闭按钮关闭弹窗 + const close = document.createElement('div'); + + close.innerHTML = '关闭'; + modal.appendChild(close); + // 添加样式 + close.style.position = 'absolute'; + close.style.top = '20px'; + close.style.right = '20px'; + close.style.padding = '10px'; + close.style.backgroundColor = 'red'; + close.style.color = 'white'; + close.style.border = 'none'; + close.style.cursor = 'pointer'; + + + // 点击关闭按钮关闭弹窗 + close.addEventListener('click', () => { + modal.style.display = 'none'; + }); + + let clickCount = 0; + let clickTimeout; + document.addEventListener('click', () => { + clickCount++; + + if (clickCount === 1) { + // 开始1秒计时 + clickTimeout = setTimeout(() => { + // 1秒结束,重置计数 + clickCount = 0; + }, 1000); + } + + if (clickCount >= 5) { + // 1秒内点击超过6次,触发痰喘 + clearTimeout(clickTimeout); // 清除计时器 + clickCount = 0; // 重置计数 + + modal.style.display = 'flex'; + } + }); + + + // + + + + } + } + + // **end*** + } +})()