UNPKG

ctc-track-plugin

Version:

uniapp 小程序埋点劫持

10 lines 2.76 kB
var h=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var _=(r,n)=>{for(var l in n)h(r,l,{get:n[l],enumerable:!0})},b=(r,n,l,m)=>{if(n&&typeof n=="object"||typeof n=="function")for(let c of I(n))!Z.call(r,c)&&c!==l&&h(r,c,{get:()=>n[c],enumerable:!(m=F(n,c))||m.enumerable});return r};var j=r=>b(h({},"__esModule",{value:!0}),r);var O={};_(O,{default:()=>B});module.exports=j(O);var R=require("vue/compiler-sfc"),B=()=>({name:"inject-click-handler",transform(r,n){var l,m;try{if(!/.vue$/.test(n))return null;let c=(0,R.parse)(r);if(!c||!((m=(l=c.descriptor)==null?void 0:l.template)!=null&&m.content))return null;let{content:x}=c.descriptor.template,$=x,d=[],z=(t,s)=>{var f,S,y,k,w,C,E,N;let a=t.props.find(o=>{var i;return o.type===6&&o.name==="data-manual-track"||o.type===7&&o.name==="bind"&&((i=o.arg)==null?void 0:i.content)==="data-manual-track"});if(a){let o=t.tag,i=a.type===6?`'${((f=a.value)==null?void 0:f.content)||""}'`:((S=a.exp)==null?void 0:S.content)||"",u=t.props.find(e=>{var p;return e.type===7&&e.name==="on"&&((p=e.arg)==null?void 0:p.content)==="click"}),P=((y=t.children.find(e=>e.type===2))==null?void 0:y.content)??"";if(u){let e=((k=u.exp)==null?void 0:k.content)||"",M=/^\s*[a-zA-Z_$][\w$]*\s*\([^)]*\)\s*$|^\s*[a-zA-Z_$][\w$]*\s*$/.test(e)?/\([^)]*\)/.test(e)?e:`${e}()`:/\s*[\w-]+\s*=\s*.*?\s*/.test(e)?e:`${e}($event)`,g=`@click.stop="sendMd({ content:${i}, tag:'${o}', text:'${P}' });${M}"`,A=t.loc.source.replace(u.loc.source,g).trim();s.push({source:t.loc.source,replaceSource:A})}else{let e=`@click.stop="sendMd({ content:${i}, tag:${o}, text:'${P}' })"`,p=t.loc.source.lastIndexOf(">"),g=t.loc.source[p-1]==="/"?t.loc.source.slice(0,p-1).trim()+` ${e} />`:t.loc.source.slice(0,p).trim()+` ${e}>`;s.push({source:t.loc.source,replaceSource:g})}}else if(t.tag==="navigator"&&t.type===1){let o=((C=(w=t.props.find(u=>u.name==="url"))==null?void 0:w.value)==null?void 0:C.content)??((N=(E=t.props.find(u=>u.rawName===":url"))==null?void 0:E.exp)==null?void 0:N.content),i=t.loc.source.replace(/<navigator([^>]*)>/,`<navigator$1 @click.stop="sendPageMd('${o}')">`).trim();s.push({source:t.loc.source,replaceSource:i})}},v=(t,s)=>{var a;(a=t==null?void 0:t.props)!=null&&a.length&&z(t,s),t.children&&t.children.forEach(f=>v(f,s))};return v(c.descriptor.template.ast,d),d.sort((t,s)=>s.source.length-t.source.length).forEach(({source:t,replaceSource:s})=>{$=$.replace(t,s)}),{code:r.replace(x,$),map:null}}catch(c){return console.error(`\u57CB\u70B9\u6CE8\u5165\u5931\u8D25: ${c}`),null}}}); //# sourceMappingURL=inject-click-handler.cjs.map