const url = window.location.href; /** * 判断是否文章和问答页 * @param {*} url * @returns */ function isNewsOrAsk(url = window.location.href) { // 创建正则表达式模式 const pattern = /\/(news|ask)\//; // 判断链接是否匹配正则表达式 if (pattern.test(url)) { return true } else { return false } } /** * 判断是否包含指定ClassName,插入对应html */ function isClass() { const gptRightHtml = `

chatGPT,一个应用广泛的超级生产工具

  • 扫码优先体验

    chatGPT小程序版

    酷音公众号
  • 关注公众号

    了解相关最新动态

    酷音公众号
  • 商务合作

    GPT程序应用集成开发

    酷音公众号
  • ` const gptTopHtml = `
    chatGPT
    chatGPT在线试用

    新一代对话式人工智能,历史上增长最快的消费者应用程序

    ` const gptBottomHtml = `

    新一代对话式人工智能
    一个超级内容生产力工具

    基于OpenAI开放平台,使用最新的CHATGPT数据模型,欢迎前往体验

  • 酷音公众号 扫码关注公众号
  • 酷音公众号 扫码体验小程序版
  • chatGPT
    ` // 定义需要插入位置的className和对应参数 const classGpt = [ { classNmae: 'summary', html: gptTopHtml, htmlId: '#chatgpt-top', position: 'before' }, { classNmae: 'statement', html: gptBottomHtml, htmlId: '#chatgpt-bottom', position: 'after' }, { classNmae: 'shopUrl-skin1', html: gptRightHtml, htmlId: '#chatgpt-rigth', position: 'before' }, { classNmae: 'askA-skin1', html: gptTopHtml, htmlId: '#chatgpt-top', position: 'before' }, { classNmae: 'askA-skin1', html: gptBottomHtml, htmlId: '#chatgpt-bottom', position: 'after' }, { classNmae: 'askA-skin2', html: gptTopHtml, htmlId: '#chatgpt-top', position: 'before' }, { classNmae: 'askA-skin2', html: gptBottomHtml, htmlId: '#chatgpt-bottom', position: 'after' }, { classNmae: 'newsDetail-skin1', html: gptBottomHtml, htmlId: '#chatgpt-bottom', position: 'after' }, { classNmae: 'newsDetail-skin2', html: gptBottomHtml, htmlId: '#chatgpt-bottom', position: 'after' }, { classNmae: 'newsDetail-skin3', html: gptBottomHtml, htmlId: '#chatgpt-bottom', position: 'after' } ] // 遍历插入 classGpt.map(item => { const demoMain = $('.' + item.classNmae) if (demoMain.hasClass(item.classNmae)) { // 避免重复插入 if ($(item.htmlId).length === 0) { item.position === 'before' ? demoMain.before(item.html) :demoMain.after(item.html); } } }) } /** * 插入样式 */ function appStyle() { const styleContent = `.media { display: -webkit-flex; display: -moz-box; display: -ms-flexbox; display: flex; -webkit-align-items: flex-start; -moz-box-align: start; -ms-flex-align: start; align-items: flex-start; } .text-white{ color: #fff } .text-white p{color:#FFF;} .media-body { -webkit-flex: 1; -moz-box-flex: 1; -ms-flex: 1; flex: 1; } .chatgpt-top{ margin-bottom: 20px; } .chatgpt-top .row{ display: flex; align-items: center; } .chatgpt-bottom{ margin-top: 20px; margin-bottom: 20px; } .chatgpt-bottom .row{ display: flex; align-items: center; justify-content: baseline; } .chatgpt-bottom .boxsize-112{ width: 112px; height: 112px; } .chatgpt-rigth{ width: 100%; margin-bottom: 20px; padding: 20px; } .chatgpt-rigth .title{ font-size: 14px; color: #333; text-align: center; } .list-unstyled .media{ display: flex; padding: 16px 0; border-top: 1px solid #f0f0f0 !important; border-color: rgba(255, 255, 255, 0.4) !important; } .list-unstyled .media .media-body{ flex: 1; } .list-unstyled .media .boxsize-80{ width: 80px; height: 80px; } .d-none{ display:none; } @media (min-width: 992px){ .d-lg-none { display: none !important; } .d-lg-inline-block { display: inline-block !important; } .d-lg-block { display: block !important; } } ` if ($('#gptclass').length === 0) { $('head').append(``); } } // 关闭 // if(isNewsOrAsk(url)){ // appStyle() // isClass() // }