(function () { const isMobile = window.location.pathname.startsWith('/m') class MyFeedback extends HTMLElement { constructor () { super() const shadowRoot = this.attachShadow({ mode: 'open' }) const divEle = document.createElement('div') divEle.setAttribute('id', 'wrapper') divEle.setAttribute('class', 'wrapper') divEle.innerHTML= `
` const style = document.createElement('style') style.textContent = ` .wrapper { padding: 8px; } .content { display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 100%; background-color: #fff; box-shadow: 0 0 8px rgba(0,0,0,0.2); cursor: pointer; } .content > svg { width: 18px; height: 18px; fill: #4a90e2; } ` shadowRoot.appendChild(style) shadowRoot.appendChild(divEle) this.triggerJump = this.triggerJump.bind(this) } connectedCallback () { const wrapper = this.shadowRoot.querySelector('#wrapper') wrapper && wrapper.addEventListener('click', this.triggerJump) } disconnectedCallback () { const wrapper = this.shadowRoot.querySelector('#wrapper') wrapper && wrapper.removeEventListener('click', this.triggerJump) } triggerJump () { const [ loginid, userid, pgid ] = [ this.getAttribute('loginid'), this.getAttribute('userid'), this.getAttribute('pgid') ] window.open(`https://www.baidu.com?userId=${userid}&loginId=${loginid}&pgId=${pgid}`) } } class MyFeedbackMobile extends HTMLElement { constructor () { super() const shadowRoot = this.attachShadow({ mode: 'open' }) const divEle = document.createElement('div') divEle.setAttribute('id', 'wrapper') divEle.setAttribute('class', 'wrapper') divEle.innerHTML= ` 反馈 ` const style = document.createElement('style') style.textContent = ` .wrapper { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%; cursor: pointer; } .wrapper > svg { width: 12px; height: 12px; margin-bottom: 4px; } .wrapper > span { font-size: 12px; } ` shadowRoot.appendChild(style) shadowRoot.appendChild(divEle) this.triggerJump = this.triggerJump.bind(this) } connectedCallback () { const wrapper = this.shadowRoot.querySelector('#wrapper') wrapper && wrapper.addEventListener('click', this.triggerJump) } disconnectedCallback () { const wrapper = this.shadowRoot.querySelector('#wrapper') wrapper && wrapper.removeEventListener('click', this.triggerJump) } triggerJump () { const [ loginid, userid, pgid ] = [ this.getAttribute('loginid'), this.getAttribute('userid'), this.getAttribute('pgid') ] window.open(`https://www.jd.com?userId=${userid}&loginId=${loginid}&pgId=${pgid}`) } } window.customElements.define('page-feedback', isMobile ? MyFeedbackMobile : MyFeedback) })()