专栏名称: AI科技大本营
为AI领域从业者提供人工智能领域热点报道和海量重磅访谈;面向技术人员,提供AI技术领域前沿研究进展和技术成长路线;面向垂直企业,实现行业应用与技术创新的对接。全方位触及人工智能时代,连接AI技术的创造者和使用者。
目录
相关文章推荐
环球物理  ·  【物理笔记】学霸笔记力学篇全部汇总 ·  10 小时前  
铅笔道  ·  北京杀出超级独角兽:一把融资10亿 ·  2 天前  
中科院物理所  ·  出生日期覆盖1-9所有数字的概率很小吗?莫非 ... ·  2 天前  
51好读  ›  专栏  ›  AI科技大本营

Anthropic 公开人工智能“独家秘方”,深入揭秘 Claude AI 的系统提示

AI科技大本营  · 公众号  ·  · 2024-08-28 15:04

正文

文 | 王启隆
出品丨AI 科技大本营(ID:rgznai100)
本文由 CSDN 编辑整理,未经授权禁止转载,违者必究。

近日,由前 OpenAI 员工创立的人工智能公司 Anthropic 公开发布了其最新 Claude AI 模型的系统提示词。这一罕见举动让用户得以一窥其大语言模型(LLM)的内部运作机制, 使 Anthropic 成为世界上第一家公开了自己“独家秘方”的 AI 公司

系统提示词通常被视为专有信息,对塑造 AI 的行为和能力至关重要。 这次发布包含了 Claude 3.5 Sonnet、Claude 3 Opus 和 Claude 3 Haiku 模型的详细指令。这些提示词概述了模型行为的具体指南,包括禁止面部识别和访问链接,此外还要让 AI 模型以 Anthropic 认为客观的方式处理有争议的话题。

由于字数比较多,我们会在 文末 放出完整的提示词。

在国外的论坛上,网友们对这些 AI 透明化的工作都表示赞扬,但也有些眼尖的人吐槽系统提示词中存在着一些“废话”,比如下面这段提示词:

Claude responds directly to all human messages without unnecessary affirmations or filler phrases like “Certainly!”, “Of course!”, “Absolutely!”, “Great!”, “Sure!”, etc. Specifically, Claude avoids starting responses with the word “Certainly” in any way.

Claude 会直接回复所有人的消息,且不会使用诸如 “Certainly!”“Of Course!”“Absolutely!”“Great!”“Sure!” 等不必要的肯定表述或填充性短语。特别地,Claude 无论如何都避免以 “Certainly” 这个词开头进行回复。

由于笔者平时就使用 Claude,所以去看了下历史记录,发现这段系统提示词真的没生效。比如下图,我让 Claude 帮忙检查文稿中的错误,而 Claude 第一句就回答我:“Certainly!”(当然!)

无论如何,Anthropic 愿意公开他们“调教” AI 模型的方式,肯定是一件好事。他们与 OpenAI、xAI 甚至开源模型的 Meta 都不同,这些大公司都对其系统提示词保密。但在今年早些时候,曾有黑客泄露 ChatGPT 内部就有一个庞大的 1700 字提示词。

另外,就在今天,Anthropic 正式为所有 Claude.ai 用户(包括免费版、专业版和团队版计划)推出了 Artifacts 功能 。免费用户终于不会遇到 Artifacts 一会儿不出来的情况了,可喜可贺。

今年六月,Anthropic 在最新的 Claude 3.5 Sonnet 模型上推出了这项功能,简而言之就是在界面弹出一个额外的窗口,让你可以即时查看、迭代和构建 Claude 创作的文字作品或是代码。后面又推出了分享功能,让用户之间可以分享彼此创建的 Artifacts。根据官方透露,用户至今已创建了数千万个 Artifacts。

如果你还是不知道这个功能有啥用,可以看看官方发布的最新视频:

如何 编写 更好的提示词?

言归正传,继续聊一聊官方分享的这套系统提示词。早在今年 3 月的时候,Anthropic 的 AI 总监 Amanda Askell 就在社交平台 X(前身为 Twitter)上分享了 Claude 3 早期版本的系统提示词。她还解释了这种条件设置背后的原因:

为什么我们要使用系统提示词?首先,它们让我们能够给模型提供『实时』信息,比如日期。其次,它们让我们能够在训练后进行一些定制,并在下一次微调之前调整行为。 这个系统提示词实现了这两点。」她在 Twitter 上的一个帖子中说道。

Anthropic 系统提示词的公开不仅帮助用户了解聊天机器人的工作原理,还能帮助人们理解 LLM 的思考方式,以及用户如何通过更好的输入来引导它们的思考过程。LLM 的核心本质上是高度复杂的文本预测器,每个词都会影响后续内容的生成。

因此,更精心设计的提示词可以帮助用户增强模型的能力,从与 AI 模型的互动中获得更准确、更符合上下文和更有针对性的结果。

  • 上下文丰富至关重要

提供丰富的上下文对于引导 AI 模型生成更精确和相关的回应至关重要。Anthropic 的提示词就示范了 详细的上下文信息在塑造 AI 行为方面的重要性

以下节选自 Anthropic 公开的系统提示词:“ 助手 Claude 是由 Anthropic 公司开发的 AI。当前日期是 {}。Claude 的知识库最后更新于 2024 年 4 月。在回答 2024 年 4 月之前和之后的事件问题时,Claude 会像一个身处 2024 年 4 月的见多识广的人与上述日期的人交谈一样,并在适当的时候告知用户这一点。

Anthropic 很好地向 Claude 解释了它必须如何回答问题。因此,这套提示词的语言、语气和知识将模仿 2024 年现代人的正常写作方式,而不是像文言文或者戏剧一样掉书袋。

在明确的上下文中构建任务,包括相关的背景信息,有助于模型生成更符合特定用户需求的回应。这种方法避免了泛泛而谈或偏离目标的答案。通过提供丰富的上下文,用户使模型能够更好地理解任务要求,从而产生更好的结果。

例如,用户可以要求模型生成一个恐怖故事,那模型通常就会生成一个很简单的恐怖寓言故事。然而,如果进一步提供恐怖风格的详细特征,则可以显著提高输出质量。那些添加所需写作风格或内容类型示例的人,往往可以细化模型对指令的理解并改进生成的结果。

  • 分解复杂查询

Anthropic 的提示词还揭示了 系统地处理复杂任务 的重要性,将任务分解成可管理的部分,而不是像用户倾向于在与喜爱的聊天机器人互动时那样一次性解决所有部分。

以下节选自 Anthropic 公开的系统提示词:“ 遇到数学题、逻辑题或其他需要系统思考的问题时,Claude 会一步步思考后再给出最终答案。如果用户要求完成一个无法在单次回复中完成的长任务,Claude 会建议分步骤完成,并在完成每个部分后征求用户的反馈。

对于多方面的任务,指示模型逐步解决问题可以产生更集中和准确的回应。这种分段允许根据每个任务阶段的反馈进行改进。

然而,理想的方法是使用多步骤技术,如 思维链 思维骨架 ,引导 LLM 完成一系列相互关联的任务。这种方法通过调节任务之间的思考过程来降低产生幻觉的概率。

笔者在翻译文章的时候,很喜欢使用宝玉(@dotey)老师分享的思维链实践,即将翻译任务拆成三步:直译 - 反思 - 意译,该模式和吴恩达提出的「 多智能体 」有异曲同工之妙。当前的大语言模型,本就有相当不错的直译能力,如果再让它自己审查一遍直译的结果,随后加入一步意译的过程,便能在三步之内生成一段文采飞扬的译文。 这种多轮技术涉及用户与模型进行不同提示词的互动,引导过程朝着令人满意的最终输出。

然而,没有时间或耐心处理多次互动的用户,则可以采取次优方案,提示模型在提供最终答案之前阐明其推理过程。这可以提高输出质量,模型自身的推理输出会影响其最终回应的质量。 虽然不如直接让用户指导模型有效,但这种方法作为提高回应质量的折衷方案是很好的。

  • 使用直接和有主旨的语言

Anthropic 的提示词是一个很好的例子,说明在 AI 互动中使用 清晰、明确 的语言有多重要。

以下节选自 Anthropic 公开的系统提示词:“ Claude 会在结束回应时提醒用户:尽管它试图表达准确,但在回答这类问题时可能会产生幻觉。它使用'产生幻觉'这个术语来描述这一点,因为用户会理解这个意思。

Claude 会直接回复所有人的消息,且不会使用诸如 “Certainly!”“Of Course!”“Absolutely!”“Great!”“Sure!” 等不必要的肯定表述或填充性短语。特别地,Claude 无论如何都避免以 “Certainly” 这个词开头进行回复。

虽然第二点没能完全实行,但道理肯定是对的: 使用直接、明确的语言有助于避免误解,确保模型的回应直截了当且有目的性。 这种方法消除了 AI 输出中不必要的复杂性或模糊性。 这些提示词通过提供明确的指南来解决潜在的模糊性,指导模型如何处理特定情况。指定所需的语气和风格确保回应符合预期的沟通方式。

就像 Stable Diffusion 曾依赖负面提示词来不生成图像中的元素一样,AI LLM 如果被用户告知不要做什么和避免做什么,也可以工作得更好。

通过指示模型保持特定的语气并避免不必要的短语,用户可以增强 AI 回应的清晰度和专业性。这个指令引导模型专注于提供实质性内容,而不使用多余的语言。

如果负面指令阻止模型采取特定的推理路径,它也可以帮助模型更好地推理。

  • 用标签分隔你的指令

在官方展示的系统提示词里,Anthropic 频繁使用了 XML 标签 ——例如,以 开始,以 结束。这看起来可能感觉很奇怪,难道是程序员在炫技吗?普通人也能用到这个技巧吗?

但其实这真的很有用, 它能帮助 AI 模型理解更长的提示词,并使聊天机器人更能理解它正在分析提示词的哪个部分

XML(可扩展标记语言)标签为内容提供了清晰的层次结构,允许更精确地控制 AI 如何解释和利用提示词的不同部分。Anthropic 使用 XML 标签在提示词中建立不同的“模块”,每个模块在引导 Claude 的行为和回应方面都有特定的目的。

将一些指令包裹在标签内有助于模型分离特定的文本块,并理解它是关于什么的。例如,你可以使用像 '; showTitle = showTitle.replace(/——/g, replaceHtml); } if (dom) { dom.innerHTML = dom.innerHTML.replace(title, showTitle); } }; if (!window.__second_open__) { var title = 'Anthropic 公开人工智能“独家秘方”,深入揭秘 Claude AI 的系统提示'; __setTitle(title, document.getElementById('activity-name')); window.__setTitle = __setTitle; } return __setTitle; })(); '; videoPlaceHolderSpan.style.cssText = "width: " + obj.w + "px !important;"; insertAfter(videoPlaceHolderSpan, a); var mid = "2247581877" || "" || ""; var biz = "Mzg4NDQwNTI0OQ==" || ""; var sessionid = "" || "svr_f90e4c3bf8b"; var idx = "1" || ""; var hitInfos = [ { video_id: 'wxv_3611027825483956231' || '', ori_status: '3' * 1 || 0, source_bizuin: '' || '', source_nickname: '' || '', source_link: '' || '', is_mp_video: '1' * 1 || 0, is_mp_video_delete: '0' * 1 || 0, is_mp_video_forbid: '0' * 1 || 0, hit_bizuin: '' * 1 || 0, hit_vid: '' || '', hit_nickname: '' || '', hit_username: '' || '', hit_biz_headimg: '' || '', is_mp_video_urgent_state: '0' * 1 || 0, is_appmsg_unauthorized: '0' * 1 || 0, videoid_uploadtime: '' * 1 || 0, videoid_bizuin: '' * 1 || 0, }, ]; (function setHitStyle(parentNode, copyIframe, index, vid) { var ret = (hitInfos || []).find(function (info) { return info.video_id === vid; } ); if (!ret) return; var ori = ret.ori_status; var hit_biz_headimg = ret.hit_biz_headimg + '/64'; var hit_nickname = ret.hit_nickname; var hit_username = ret.hit_username; var sourceBiz = ret.hit_bizuin; var selfUserName = "gh_c7f65dd80906"; if (ori === 2 && selfUserName !== hit_username) { var videoBar = document.createElement('div'); var videoBarHtml = ''; videoBar.innerHTML = videoBarHtml; var spanContainer = document.getElementById('js_mp_video_container_' + index); if (spanContainer) { spanContainer.parentNode.insertBefore(videoBar, spanContainer); } else if (parentNode.contains && parentNode.contains(copyIframe)) { parentNode.insertBefore(videoBar, copyIframe); } else { parentNode.insertBefore(videoBar, parentNode.firstElementChild); } var avatorEle = document.getElementById(hit_biz_headimg + index); var avatorSrc = avatorEle.dataset.src; console.log('avatorSrc' + avatorSrc); if (ret.hit_biz_headimg) { avatorEle.style.backgroundImage = 'url(' + avatorSrc + ')'; } } })(a.parentNode, a, i, vid); a.style.cssText += ";width: " + obj.w + "px !important;"; a.setAttribute("width", obj.w); if (window.__zoom != 1) { a.style.display = "block"; videoPlaceHolderSpan.style.display = "none"; a.setAttribute("_ratio", obj.ratio); a.setAttribute("_vid", vid); } else { videoPlaceHolderSpan.style.cssText += "height: " + (obj.h - obj.sdh) + "px !important;margin-bottom: " + obj.sdh + "px !important;"; a.style.cssText += "height: " + obj.h + "px !important;"; a.setAttribute("height", obj.h); } a.setAttribute("data-vh", obj.vh); a.setAttribute("data-vw", obj.vw); if (a.getAttribute("data-mpvid")) { a.setAttribute("data-src", location.protocol + "//mp.weixin.qq.com/mp/readtemplate?t=pages/video_player_tmpl&auto=0&vid=" + vid); } else { a.setAttribute("data-src", location.protocol + "//v.qq.com/iframe/player.html?vid=" + vid + "&width=" + obj.vw + "&height=" + obj.vh + "&auto=0"); } } })(); (function () { if (window.__zoom != 1) { if (!window.__second_open__) { document.getElementById('page-content').style.zoom = window.__zoom; var a = document.getElementById('activity-name'); var b = document.getElementById('meta_content'); if (!!a) { a.style.zoom = 1 / window.__zoom; } if (!!b) { b.style.zoom = 1 / window.__zoom; } } var images = document.getElementsByTagName('img'); for (var i = 0, il = images.length; i < il; i++) { if (window.__second_open__ && images[i].getAttribute('__sec_open_place_holder__')) { continue; } images[i].style.zoom = 1 / window.__zoom; } var iframe = document.getElementsByTagName('iframe'); for (var i = 0, il = iframe.length; i < il; i++) { if (window.__second_open__ && iframe[i].getAttribute('__sec_open_place_holder__')) { continue; } var a = iframe[i]; a.style.zoom = 1 / window.__zoom; var src_ = a.getAttribute('data-src') || ""; if (!/^http(s)*\:\/\/v\.qq\.com\/iframe\/(preview|player)\.html\?/.test(src_) && !/^http(s)*\:\/\/mp\.weixin\.qq\.com\/mp\/readtemplate\?t=pages\/video_player_tmpl/.test(src_) ) { continue; } var ratio = a.getAttribute("_ratio"); var vid = a.getAttribute("_vid"); a.removeAttribute("_ratio"); a.removeAttribute("_vid"); var vw = a.offsetWidth - (getOuterW(a) || 0); var vh = vw / ratio; var h = vh + (getOuterH(a) || 0) a.style.cssText += "height: " + h + "px !important;" a.setAttribute("height", h); if (/^http(s)*\:\/\/v\.qq\.com\/iframe\/(preview|player)\.html\?/.test(src_)) { a.setAttribute("data-src", location.protocol + "//v.qq.com/iframe/player.html?vid=" + vid + "&width=" + vw + "&height=" + vh + "&auto=0"); } a.style.display = "none"; var parent = a.parentNode; if (!parent) { continue; } for (var j = 0, jl = parent.children.length; j < jl; j++) { var child = parent.children[j]; if (child.className.indexOf("js_img_placeholder") >= 0 && child.getAttribute("data-vid") == vid) { child.style.cssText += "height: " + h + "px !important;"; child.style.display = ""; } } } } })(); })(); var anchor_tree_msg = ''; ', config: [{ querySelector: 'redpacketcover', genId: function genId() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return decodeURIComponent(opt.node.getAttribute('data-coveruri') || ''); }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 0.7854; }, calH: function calH() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return this.calW({ parentWidth: opt.parentWidth }) / 0.73346 + 27 + 37; }, replaceContentCssText: '', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mppoi', genId: function genId() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.node.getAttribute('data-id') || ''; }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 1; }, calH: function calH() { return 219; }, replaceContentCssText: '', appendContentCssText: 'diplay:block;', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mpsearch', genId: function genId() { return decodeURIComponent('mp-common-search'); }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 1; }, calH: function calH() { return 100; }, replaceContentCssText: '', appendContentCssText: 'diplay:block;', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mpvideosnap', genId: function genId() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var type = opt.node.getAttribute('data-type') || 'video'; if (type === 'live') { return decodeURIComponent(opt.node.getAttribute('data-noticeid') || ''); } return decodeURIComponent(opt.node.getAttribute('data-id') || ''); }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var type = opt.node.getAttribute('data-type') || 'video'; var width = opt.node.getAttribute('data-width') || ''; var height = opt.node.getAttribute('data-height') || ''; if (type === 'live' || type === 'topic') { return opt.parentWidth; } var ratio = 1; ratio = width / height; var computedHeight = 0; var computedWidth = 0; var isHorizontal = false; if (ratio === 1 || ratio === 3 / 4) ; else if (ratio === 4 / 3 || ratio === 16 / 9) { isHorizontal = true; } else if (ratio < 3 / 4) { ratio = 3 / 4; } else if (ratio > 1 && ratio < 4 / 3) { ratio = 1; } else if (ratio > 4 / 3) { isHorizontal = true; } else if (typeof ratio === 'number' && !Object.is(ratio, NaN)) ; else { ratio = 1; } opt.node.setAttribute('data-ratio', ratio); opt.node.setAttribute('data-isHorizontal', isHorizontal); if (isHorizontal === true) { computedWidth = opt.parentWidth; } else { if (window.innerWidth < 1024) { computedWidth = window.innerWidth * 0.65; } else { computedWidth = opt.parentWidth * 0.65; } } computedHeight = computedWidth / ratio; computedHeight = Math.round(computedHeight); computedWidth = Math.round(computedWidth); opt.node.setAttribute('data-computedWidth', computedWidth); opt.node.setAttribute('data-computedHeight', computedHeight); return computedWidth; }, calH: function calH() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var desc = opt.node.getAttribute('data-desc') || ''; var type = opt.node.getAttribute('data-type') || 'video'; var computedHeight = opt.node.getAttribute('data-computedHeight') || ''; switch (type) { case 'live': return desc ? 152 : 116; case 'topic': return 201; case 'image': case 'video': return parseFloat(computedHeight); } }, getBorderRadius: function getBorderRadius() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var type = opt.node.getAttribute('data-type') || 'video'; if (type === 'video') { return 4; } return 8; }, replaceContentCssText: '', appendContentCssText: 'display:flex;margin:0px auto;', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mp-wxaproduct', genId: function genId() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return decodeURIComponent(opt.node.getAttribute('data-wxaproduct-productid') || ''); }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 1 || '100%'; }, calH: function calH() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var cardtype = opt.node.getAttribute('data-wxaproduct-cardtype') || ''; return cardtype === 'mini' ? 124 : 466; }, replaceContentCssText: '', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mpprofile', genId: function genId(opt) { return opt.node.getAttribute('data-id') || ''; }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 1; }, calH: function calH() { return 143; }, replaceContentCssText: '', appendContentCssText: 'diplay:block;', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mp-common-product', genId: function genId(opt) { return opt.node.getAttribute('data-windowproduct') || ''; }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 1 || '100%'; }, calH: function calH(opt) { var customstyle = opt.node.getAttribute('data-customstyle') || '{}'; if (customstyle) { try { var _JSON$parse = JSON.parse(customstyle), display = _JSON$parse.display, height = _JSON$parse.height; if (display !== 'none') { var customHeight = height.split('px')[0]; var ratio = opt.parentWidth / 350.0 || 1; customHeight = Math.round(customHeight * ratio); return customHeight; } return 0; } catch (err) { console.error(err); } } return 0; }, replaceContentCssText: '', appendContentCssText: 'diplay:block;', outerContainerLeft: '
', outerContainerRight: '
' }, { querySelector: 'mpcps:not([data-templateid="video-play"]),mp-common-cpsad:not([data-templateid="video-play"])', genId: function genId(opt) { var node = opt.node; var planId = node.getAttribute('data-planid'); var goodId = node.getAttribute('data-pid'); var traceId = node.getAttribute('data-traceid'); return goodId || planId || traceId || ''; }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var node = opt.node; var templateId = node.getAttribute('data-templateid'); var adType = node.getAttribute('data-adtype'); var width = 0; if (templateId === 'list') { width = '100%'; } else if (templateId === 'card') { if (adType === AD_CONFIG.CPS_GOODS_TYPE.SHORT_PLAY || adType === AD_CONFIG.CPS_GOODS_TYPE.MINI_GAME) { width = opt.parentWidth ? opt.parentWidth * 0.65 : '100%'; } else { width = '100%'; } } return width; }, calH: function calH(opt) { var node = opt.node; var templateId = node.getAttribute('data-templateid'); var adType = node.getAttribute('data-adtype'); var height = 0; if (templateId === 'list') { if (adType === AD_CONFIG.CPS_GOODS_TYPE.MINI_GAME) { height = 79; } else { height = 120; } } else if (templateId === 'card') { if (adType === AD_CONFIG.CPS_GOODS_TYPE.SHORT_PLAY) { var width = opt.parentWidth * 0.65; height = Math.ceil(width * (4 / 3)) + 68; } else if (adType === AD_CONFIG.CPS_GOODS_TYPE.MINI_GAME) { var _width = opt.parentWidth * 0.65; height = Math.ceil(_width * (4 / 3)) + 64; } else { height = Math.ceil(opt.parentWidth + 111); } } return height; }, replaceContentCssText: '', appendContentCssText: 'diplay:block;', outerContainerLeft: '
', outerContainerRight: '
' } ] }; function preloadingInit() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (typeof document.querySelectorAll !== 'function') { return; } var g = { maxWith: document.getElementById('img-content').getBoundingClientRect().width, idAttr: 'data-preloadingid' }; for (var i = 0, il = opt.config.length; i < il; i++) { var a = opt.config[i]; var list = document.querySelectorAll(a.querySelector); for (var j = 0, jl = list.length; j < jl; j++) { var node = list[j]; var parentWidth = node.parentNode.getBoundingClientRect().width; parentWidth = Math.min(parentWidth, g.maxWith); if (node.getAttribute('has-insert-preloading')) { continue; } var nodeW = a.calW({ parentWidth: parentWidth, node: node }); var nodeH = a.calH({ parentWidth: parentWidth, node: node }); var nodeId = a.genId({ index: j, node: node }); var nodeBorderRadius = typeof a.getBorderRadius === 'function' ? a.getBorderRadius({ index: j, node: node }) : 8; if (typeof nodeW === 'number') { nodeW += 'px'; } var imgHtml = opt.defaultContentTpl.replace(/#height#/g, nodeH).replace(/#width#/g, nodeW).replace(/#borderRadius#/g, nodeBorderRadius); var tmpNode = document.createElement('div'); tmpNode.innerHTML = imgHtml; if (a.replaceContentCssText) { var replaceContentCssText = a.replaceContentCssText.replace(/#height#/g, nodeH).replace(/#width#/g, nodeW); tmpNode.firstChild.style.cssText = replaceContentCssText; } else if (a.appendContentCssText) { tmpNode.firstChild.style.cssText += a.appendContentCssText; } var html = (a.outerContainerLeft || '') + tmpNode.innerHTML + (a.outerContainerRight || ''); tmpNode.innerHTML = html; tmpNode.firstChild.setAttribute(g.idAttr, nodeId); node.parentNode.insertBefore(tmpNode.firstChild, node.nextSibling); node.setAttribute('has-insert-preloading', '1'); } } } function init() { preloadingInit(g); } function decode(str) { var replace = ["`", "`", "'", "'", """, '"', " ", " ", ">", ">", "<", "<", "¥", "¥", "&", "&"]; for (var i = 0; i < replace.length; i += 2) { str = str.replace(new RegExp(replace[i], 'g'), replace[i + 1]); } return str; } function getQuery(url) { url = url || 'http://qq.com/s?a=b#rd'; var tmp = url.split('?'), query = (tmp[1] || '').split('#')[0].split('&'), params = {}; for (var i = 0; i < query.length; i++) { var eqIndex = query[i].indexOf('='); if (eqIndex > -1) { var arg = query[i].substring(0, eqIndex); params[arg] = query[i].substring(eqIndex + 1); } } if (params['pass_ticket']) { params['pass_ticket'] = encodeURIComponent(decode(params['pass_ticket']).replace(/\s/g, '+')); } return params; } function insertAfter(dom, afterDom) { var _p = afterDom.parentNode; if (!_p) { return; } if (_p.lastChild === afterDom) { _p.appendChild(dom); } else { _p.insertBefore(dom, afterDom.nextSibling); } } if (typeof getComputedStyle === 'undefined') { if (document.body.currentStyle) { window.getComputedStyle = function (el) { return el.currentStyle; }; } else { window.getComputedStyle = {}; } } function getMaxWith() { var container = document.getElementById('img-content'); var max_width = container.offsetWidth; var container_padding = 0; var container_style = getComputedStyle(container); container_padding = parseFloat(container_style.paddingLeft) + parseFloat(container_style.paddingRight); max_width -= container_padding; if (!max_width) { max_width = window.innerWidth - 32; } return max_width; } function getParentWidth(dom) { var parent_width = 0; var parent = dom.parentNode; var outerWidth = 0; while (true) { if (!parent || parent.nodeType !== 1) break; var parent_style = getComputedStyle(parent); if (!parent_style) break; parent_width = parent.clientWidth - parseFloat(parent_style.paddingLeft) - parseFloat(parent_style.paddingRight) - outerWidth; if (parent_width > 16) break; outerWidth += parseFloat(parent_style.paddingLeft) + parseFloat(parent_style.paddingRight) + parseFloat(parent_style.marginLeft) + parseFloat(parent_style.marginRight) + parseFloat(parent_style.borderLeftWidth) + parseFloat(parent_style.borderRightWidth); parent = parent.parentNode; } if (parent_width < 0) { return 0; } return parent_width; } function getOuterW(dom) { var style = getComputedStyle(dom), w = 0; if (!!style) { w = parseFloat(style.paddingLeft) + parseFloat(style.paddingRight) + parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth); } return w; } function getOuterH(dom) { var style = getComputedStyle(dom), h = 0; if (!!style) { h = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom) + parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth); } return h; } function getVideoWh(dom) { var max_width = getMaxWith(), width = max_width, ratio_ = dom.getAttribute('data-ratio') * 1 || 4 / 3, arr = [4 / 3, 16 / 9], ret = arr[0], abs = Math.abs(ret - ratio_); for (var j = 1, jl = arr.length; j < jl; j++) { var _abs = Math.abs(arr[j] - ratio_); if (_abs < abs) { abs = _abs; ret = arr[j]; } } ratio_ = ret; var parent_width = getParentWidth(dom) || max_width, rwidth = width > parent_width ? parent_width : width, outerW = getOuterW(dom) || 0, outerH = getOuterH(dom) || 0, videoW = rwidth - outerW, videoH = videoW / ratio_, speedDotH = 12, rheight = videoH + outerH + speedDotH; return { w: Math.ceil(rwidth), h: Math.ceil(rheight), vh: videoH, vw: videoW, ratio: ratio_, sdh: speedDotH }; } function setImgSize(item, widthNum, widthUnit, ratio, breakParentWidth) { var imgPaddingBorder = getOuterW(item) || 0; var imgPaddingBorderTopBottom = getOuterH(item) || 0; if (widthNum > getParentWidth(item) && !breakParentWidth) { widthNum = getParentWidth(item); } var heightNum = (widthNum - imgPaddingBorder) * ratio + imgPaddingBorderTopBottom; widthNum !== 'auto' && (item.style.cssText += ";width: ".concat(widthNum).concat(widthUnit, " !important;")); widthNum !== 'auto' && (item.style.cssText += ";height: ".concat(heightNum).concat(widthUnit, " !important;")); } var isAccessibilityKey = 'isMpUserAccessibility'; var imgPlaceholderClass = 'js_img_placeholder'; var isAccessMode = window.localStorage.getItem(isAccessibilityKey); var imgSizeData; var validArr = ',' + [0.875, 1, 1.125, 1.25, 1.375].join(',') + ','; var match = window.location.href.match(/winzoom=(\d+(?:\.\d+)?)/); if (match && match[1]) { var winzoom = parseFloat(match[1]); if (validArr.indexOf(',' + winzoom + ',') >= 0) ; } function getImgSrcMainInfo(src) { var pathName = new URL(src).pathname; var lastIndex = pathName.lastIndexOf('/'); return lastIndex > 0 ? pathName.slice(0, lastIndex) : pathName; } function setSize(images, videos, data) { var noWidth = !document.body.clientWidth || !document.getElementById('img-content') || !document.getElementById('img-content').offsetWidth; var _loop = function _loop() { if (noWidth) { return 0; } if (window.__second_open__ && videos[vi].getAttribute('__sec_open_place_holder__')) { return 1; } var a = videos[vi]; var src_ = a.getAttribute('src') || a.getAttribute('data-src') || ''; var vid = getQuery(src_).vid || a.getAttribute('data-mpvid'); if (!vid) { return 1; } vid = vid.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); a.removeAttribute('src'); a.style.display = 'none'; var obj = getVideoWh(a); var videoPlaceHolderSpan = document.createElement('span'); videoPlaceHolderSpan.className = "".concat(imgPlaceholderClass, " wx_widget_placeholder"); videoPlaceHolderSpan.setAttribute('data-vid', vid); videoPlaceHolderSpan.innerHTML = ' '; videoPlaceHolderSpan.style.cssText = "width: " + obj.w + "px !important;"; insertAfter(videoPlaceHolderSpan, a); a.style.cssText += ';width: ' + obj.w + 'px !important;'; a.setAttribute('width', obj.w); { videoPlaceHolderSpan.style.cssText += 'height: ' + (obj.h - obj.sdh) + 'px !important;margin-bottom: ' + obj.sdh + 'px !important;'; a.style.cssText += 'height: ' + obj.h + 'px !important;'; a.setAttribute('height', obj.h); } a.setAttribute('data-vh', obj.vh); a.setAttribute('data-vw', obj.vw); a.setAttribute('data-src', 'https://v.qq.com/iframe/player.html?vid=' + vid + '&width=' + obj.vw + '&height=' + obj.vh + '&auto=0'); a.setAttribute('__sec_open_place_holder__', true); var index = vi; (function setHitStyle() { var hitInfos = data.video_page_infos; var ret = (hitInfos || []).find(function (info) { return info.video_id === vid; }); if (!ret) return; var ori = ret.ori_status; var hit_biz_headimg = ret.hit_biz_headimg, hit_nickname = ret.hit_nickname, hit_username = ret.hit_username; var sourceBiz = ret.hit_bizuin; var selfUserName = data.user_name; if (ori === 2 && selfUserName !== hit_username) { var videoBar = document.createElement('div'); var videoBarHtml = "\n "); videoBar.innerHTML = videoBarHtml; document.querySelectorAll('.video_iframe').forEach(function (item) { if (item.getAttribute('data-mpvid') === vid && item.getAttribute('data-hasSource') !== '1') { item.setAttribute('data-hasSource', 1); item.parentNode.insertBefore(videoBar, item); } }); var avatorEle = document.getElementById(hit_biz_headimg + index); var avatorSrc = avatorEle.dataset.src; if (ret.hit_biz_headimg) avatorEle.style.backgroundImage = "url(".concat(avatorSrc, ")"); } })(); }, _ret; for (var vi = 0, viLen = videos.length; vi < viLen; vi++) { _ret = _loop(); if (_ret === 0) break; if (_ret === 1) continue; } var isCarton = data.copyright_info.is_cartoon_copyright * 1 || data.user_info.is_care_mode * 1 || isAccessMode === '1'; var max_width = getMaxWith(); if (!imgSizeData) { imgSizeData = {}; data.picture_page_info_list = data.picture_page_info_list || []; var noWidthHeightCount = 0; var hasWidthHeightCount = 0; data.picture_page_info_list.forEach(function (imgData) { try { var width = Number(imgData.width); var height = Number(imgData.height); if (width && height) { imgSizeData[getImgSrcMainInfo(imgData.cdn_url)] = { ratio: height / width, width: width }; hasWidthHeightCount++; } else { noWidthHeightCount++; } } catch (err) { console.error(err); } }); if (Math.random() < 0.01 && Number(data.create_timestamp) > 1682352000) { hasWidthHeightCount && (new Image().src = "//mp.weixin.qq.com/mp/jsmonitor?idkey=330742_20_".concat(hasWidthHeightCount, "&r=").concat(Math.random())); noWidthHeightCount && (new Image().src = "//mp.weixin.qq.com/mp/jsmonitor?idkey=330742_21_".concat(noWidthHeightCount, "&r=").concat(Math.random())); if (!data.picture_page_info_list.length) { setTimeout(function () { noWidthHeightCount = document.querySelectorAll('#js_content img').length; noWidthHeightCount && (new Image().src = "//mp.weixin.qq.com/mp/jsmonitor?idkey=330742_21_".concat(noWidthHeightCount, "&r=").concat(Math.random())); }, 300); } } } for (var im = 0, imLen = images.length; im < imLen; im++) { if (window.__second_open__ && images[im].getAttribute('__sec_open_place_holder__')) { continue; } var img = images[im]; var imgDataSrc = img.getAttribute('data-src'); var realSrc = img.getAttribute('src'); if (!imgDataSrc || realSrc) continue; var imgStyle = img.getAttribute('style'); img.setAttribute('data-original-style', imgStyle); var width_ = img.dataset.w; var imgRatio = 1 * img.dataset.ratio; img.setAttribute('data-index', im); var width_num = 0; var width_unit = 'px'; try { var imgSizeFromBackend = imgSizeData[getImgSrcMainInfo(imgDataSrc)]; if (imgSizeFromBackend) { if (imgSizeFromBackend.ratio) { imgRatio = imgSizeFromBackend.ratio; img.setAttribute('data-ratio', imgSizeFromBackend.ratio); } if (imgSizeFromBackend.width) { width_ = imgSizeFromBackend.width; img.setAttribute('data-w', imgSizeFromBackend.width); } } } catch (err) { console.error(err); } if (imgRatio && imgRatio > 0) { if (!isCarton) { img.src = "data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='1px' height='1px' viewBox='0 0 1 1' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Ctitle%3E%3C/title%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd' fill-opacity='0'%3E%3Cg transform='translate(-249.000000, -126.000000)' fill='%23FFFFFF'%3E%3Crect x='249' y='126' width='1' height='1'%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E"; if (noWidth) { var fallbackWidth = img.style.width || img.getAttribute('width') || width_; var fallbackMaxWidth = 360; fallbackWidth = parseFloat(fallbackWidth, 10) > fallbackMaxWidth ? fallbackMaxWidth : fallbackWidth; if (fallbackWidth === 'inherit') { fallbackWidth = fallbackMaxWidth; } if (fallbackWidth) { img.setAttribute('_width', !isNaN(fallbackWidth * 1) ? fallbackWidth + 'px' : fallbackWidth); } if (typeof fallbackWidth === 'string' && fallbackWidth.indexOf('%') !== -1) { fallbackWidth = parseFloat(fallbackWidth.replace('%', ''), 10) / 100 * fallbackMaxWidth; } if (fallbackWidth === 'auto') { fallbackWidth = width_; if (width_ === 'auto' || !width_) { fallbackWidth = fallbackMaxWidth; } else { fallbackWidth = width_; } } var fallbackRes = /^(\d+(?:\.\d+)?)([a-zA-Z%]+)?$/.exec(fallbackWidth); var fallbackLastWidth = fallbackRes && fallbackRes.length >= 2 ? fallbackRes[1] : 0; var fallbackUnit = fallbackRes && fallbackRes.length >= 3 && fallbackRes[2] ? fallbackRes[2] : 'px'; setImgSize(img, fallbackLastWidth, fallbackUnit, imgRatio, true); img.classList.add(imgPlaceholderClass, "wx_img_placeholder"); continue; } img.classList.add(imgPlaceholderClass, "wx_img_placeholder"); } var parent_width = getParentWidth(img) || max_width; var init_width = img.style.width || img.getAttribute('width') || width_ || parent_width; init_width = parseFloat(init_width, 10) > max_width ? max_width : init_width; if (init_width === 'inherit') { init_width = parent_width; } if (init_width) { img.setAttribute('_width', !isNaN(init_width * 1) ? init_width + 'px' : init_width); } if (typeof init_width === 'string' && init_width.indexOf('%') !== -1) { init_width = parseFloat(init_width.replace('%', ''), 10) / 100 * parent_width; } if (init_width === 'auto') { init_width = width_; if (width_ === 'auto' || !width_) { init_width = parent_width; } else { init_width = width_; } } var res = /^(\d+(?:\.\d+)?)([a-zA-Z%]+)?$/.exec(init_width); width_num = res && res.length >= 2 ? res[1] : 0; width_unit = res && res.length >= 3 && res[2] ? res[2] : 'px'; var imgWidth = width_num; if (isCarton) { img.src = imgDataSrc; img.style.height = 'auto'; } else { setImgSize(img, imgWidth, width_unit, imgRatio, true); setImgSize(img, imgWidth, width_unit, imgRatio, false); } } if (!data.is_h5_render) { img.setAttribute('__sec_open_place_holder__', true); } } init(); } var ua = navigator.userAgent; /mac\sos/i.test(ua) && !/(iPhone|iPad|iPod|iOS)/i.test(ua) || /windows\snt/i.test(ua); var images = document.getElementsByTagName('img'); var videos = []; var user_name = "gh_c7f65dd80906"; var isCartoonCopyright = '0'; var is_care_mode = ''; var createTimestamp = '1724828693'; var picturePageInfoList = "[{'cdn_url':'https://mmbiz.qpic.cn/mmbiz_gif/VeJKXItpwPVibOSMQeyaGwgUuVlcQvxkGXXWJd5ibVobOMbl2fuGGsbm5Ric4aJjgUiahJfqib9xbibDticDldfIziaT8g/640?wx_fmt=gif','width':'680','height':'120'},{'cdn_url':'https://mmbiz.qpic.cn/mmbiz_png/VeJKXItpwPVKdoeHyKQmKLrotc9boKiaPoU1KfTOtGcaWHQlZZdkgPQpusXfgXvNPvAlk4ojqGwI9XTrDQqk0eA/640?wx_fmt=png\x26amp;amp;from=appmsg','width':'1024','height':'388'},{'cdn_url':'https://mmbiz.qpic.cn/mmbiz_png/VeJKXItpwPVKdoeHyKQmKLrotc9boKiaPOQxd4msk31JtaLk8qW7WUvBOVUkVM91cXYSk7tNTOttsF7oWc8uHIw/640?wx_fmt=png\x26amp;amp;from=appmsg','width':'892','height':'252'},{'cdn_url':'https://mmbiz.qpic.cn/mmbiz_png/VeJKXItpwPWf7XS3tqT5j3m4RicVvkJia4XjmL6ia6KVBR47uURbwHDpWkv1ibp6CXXozABLFick1tbg4JT0zVt1yqA/640?wx_fmt=png','width':'1080','height':'115'},{'cdn_url':'https://mmbiz.qpic.cn/mmbiz_png/VeJKXItpwPWf7XS3tqT5j3m4RicVvkJia40Ym3H9gfAiceSjtJ7gsq8GIet75GweOJ0Z4QZwlLrsXgtPB0VRapEibQ/640?wx_fmt=png','width':'1080','height':'115'},{'cdn_url':'https://mmbiz.qpic.cn/mmbiz_gif/VeJKXItpwPVibOSMQeyaGwgUuVlcQvxkGpJiaozYcoDqdicBtIND9d4IpGGEDk1TYx9khYV1lE1EZMEXiaGxnr1Gkw/640?wx_fmt=gif','width':'750','height':'150'},{'cdn_url':'https://mmbiz.qpic.cn/mmbiz_png/VeJKXItpwPXvK4CBPVfXqDxjdh7LFbQ3ia5vh4R3wIcjpdsOzPW1tia1icnGpOaDibukurOrroMvEaicYX1Ut4w9VdA/640?wx_fmt=png\x26amp;amp;from=appmsg','width':'1080','height':'1920'},]"; picturePageInfoList = picturePageInfoList.includes(',]') ? picturePageInfoList.replace(',]', ']') : picturePageInfoList; try { picturePageInfoList = JSON.parse(picturePageInfoList.replace(/'/g, '"')); } catch (err) { picturePageInfoList = []; console.error(err); } var data = { is_h5_render: true, user_name: user_name, copyright_info: { is_cartoon_copyright: isCartoonCopyright }, picture_page_info_list: picturePageInfoList, create_timestamp: createTimestamp, user_info: { is_care_mode: is_care_mode } }; setSize(images, videos, data); })(); ', config: [{ querySelector: 'redpacketcover', genId: function genId() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return decodeURIComponent(opt.node.getAttribute('data-coveruri') || ''); }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 0.7854; }, calH: function calH() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return this.calW({ parentWidth: opt.parentWidth }) / 0.73346 + 27 + 37; }, replaceContentCssText: '', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mppoi', genId: function genId() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.node.getAttribute('data-id') || ''; }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 1; }, calH: function calH() { return 219; }, replaceContentCssText: '', appendContentCssText: 'diplay:block;', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mpsearch', genId: function genId() { return decodeURIComponent('mp-common-search'); }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 1; }, calH: function calH() { return 100; }, replaceContentCssText: '', appendContentCssText: 'diplay:block;', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mpvideosnap', genId: function genId() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var type = opt.node.getAttribute('data-type') || 'video'; if (type === 'live') { return decodeURIComponent(opt.node.getAttribute('data-noticeid') || ''); } return decodeURIComponent(opt.node.getAttribute('data-id') || ''); }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var type = opt.node.getAttribute('data-type') || 'video'; var width = opt.node.getAttribute('data-width') || ''; var height = opt.node.getAttribute('data-height') || ''; if (type === 'live' || type === 'topic') { return opt.parentWidth; } var ratio = 1; ratio = width / height; var computedHeight = 0; var computedWidth = 0; var isHorizontal = false; if (ratio === 1 || ratio === 3 / 4) ; else if (ratio === 4 / 3 || ratio === 16 / 9) { isHorizontal = true; } else if (ratio < 3 / 4) { ratio = 3 / 4; } else if (ratio > 1 && ratio < 4 / 3) { ratio = 1; } else if (ratio > 4 / 3) { isHorizontal = true; } else if (typeof ratio === 'number' && !Object.is(ratio, NaN)) ; else { ratio = 1; } opt.node.setAttribute('data-ratio', ratio); opt.node.setAttribute('data-isHorizontal', isHorizontal); if (isHorizontal === true) { computedWidth = opt.parentWidth; } else { if (window.innerWidth < 1024) { computedWidth = window.innerWidth * 0.65; } else { computedWidth = opt.parentWidth * 0.65; } } computedHeight = computedWidth / ratio; computedHeight = Math.round(computedHeight); computedWidth = Math.round(computedWidth); opt.node.setAttribute('data-computedWidth', computedWidth); opt.node.setAttribute('data-computedHeight', computedHeight); return computedWidth; }, calH: function calH() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var desc = opt.node.getAttribute('data-desc') || ''; var type = opt.node.getAttribute('data-type') || 'video'; var computedHeight = opt.node.getAttribute('data-computedHeight') || ''; switch (type) { case 'live': return desc ? 152 : 116; case 'topic': return 201; case 'image': case 'video': return parseFloat(computedHeight); } }, getBorderRadius: function getBorderRadius() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var type = opt.node.getAttribute('data-type') || 'video'; if (type === 'video') { return 4; } return 8; }, replaceContentCssText: '', appendContentCssText: 'display:flex;margin:0px auto;', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mp-wxaproduct', genId: function genId() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return decodeURIComponent(opt.node.getAttribute('data-wxaproduct-productid') || ''); }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 1 || '100%'; }, calH: function calH() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var cardtype = opt.node.getAttribute('data-wxaproduct-cardtype') || ''; return cardtype === 'mini' ? 124 : 466; }, replaceContentCssText: '', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mpprofile', genId: function genId(opt) { return opt.node.getAttribute('data-id') || ''; }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 1; }, calH: function calH() { return 143; }, replaceContentCssText: '', appendContentCssText: 'diplay:block;', outerContainerLeft: '', outerContainerRight: '' }, { querySelector: 'mp-common-product', genId: function genId(opt) { return opt.node.getAttribute('data-windowproduct') || ''; }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return opt.parentWidth * 1 || '100%'; }, calH: function calH(opt) { var customstyle = opt.node.getAttribute('data-customstyle') || '{}'; if (customstyle) { try { var _JSON$parse = JSON.parse(customstyle), display = _JSON$parse.display, height = _JSON$parse.height; if (display !== 'none') { var customHeight = height.split('px')[0]; var ratio = opt.parentWidth / 350.0 || 1; customHeight = Math.round(customHeight * ratio); return customHeight; } return 0; } catch (err) { console.error(err); } } return 0; }, replaceContentCssText: '', appendContentCssText: 'diplay:block;', outerContainerLeft: '
', outerContainerRight: '
' }, { querySelector: 'mpcps:not([data-templateid="video-play"]),mp-common-cpsad:not([data-templateid="video-play"])', genId: function genId(opt) { var node = opt.node; var planId = node.getAttribute('data-planid'); var goodId = node.getAttribute('data-pid'); var traceId = node.getAttribute('data-traceid'); return goodId || planId || traceId || ''; }, calW: function calW() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var node = opt.node; var templateId = node.getAttribute('data-templateid'); var adType = node.getAttribute('data-adtype'); var width = 0; if (templateId === 'list') { width = '100%'; } else if (templateId === 'card') { if (adType === AD_CONFIG.CPS_GOODS_TYPE.SHORT_PLAY || adType === AD_CONFIG.CPS_GOODS_TYPE.MINI_GAME) { width = opt.parentWidth ? opt.parentWidth * 0.65 : '100%'; } else { width = '100%'; } } return width; }, calH: function calH(opt) { var node = opt.node; var templateId = node.getAttribute('data-templateid'); var adType = node.getAttribute('data-adtype'); var height = 0; if (templateId === 'list') { if (adType === AD_CONFIG.CPS_GOODS_TYPE.MINI_GAME) { height = 79; } else { height = 120; } } else if (templateId === 'card') { if (adType === AD_CONFIG.CPS_GOODS_TYPE.SHORT_PLAY) { var width = opt.parentWidth * 0.65; height = Math.ceil(width * (4 / 3)) + 68; } else if (adType === AD_CONFIG.CPS_GOODS_TYPE.MINI_GAME) { var _width = opt.parentWidth * 0.65; height = Math.ceil(_width * (4 / 3)) + 64; } else { height = Math.ceil(opt.parentWidth + 111); } } return height; }, replaceContentCssText: '', appendContentCssText: 'diplay:block;', outerContainerLeft: '
', outerContainerRight: '
' } ] }; function preloadingInit() { var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; if (typeof document.querySelectorAll !== 'function') { return; } var g = { maxWith: document.getElementById('img-content').getBoundingClientRect().width, idAttr: 'data-preloadingid' }; for (var i = 0, il = opt.config.length; i < il; i++) { var a = opt.config[i]; var list = document.querySelectorAll(a.querySelector); for (var j = 0, jl = list.length; j < jl; j++) { var node = list[j]; var parentWidth = node.parentNode.getBoundingClientRect().width; parentWidth = Math.min(parentWidth, g.maxWith); if (node.getAttribute('has-insert-preloading')) { continue; } var nodeW = a.calW({ parentWidth: parentWidth, node: node }); var nodeH = a.calH({ parentWidth: parentWidth, node: node }); var nodeId = a.genId({ index: j, node: node }); var nodeBorderRadius = typeof a.getBorderRadius === 'function' ? a.getBorderRadius({ index: j, node: node }) : 8; if (typeof nodeW === 'number') { nodeW += 'px'; } var imgHtml = opt.defaultContentTpl.replace(/#height#/g, nodeH).replace(/#width#/g, nodeW).replace(/#borderRadius#/g, nodeBorderRadius); var tmpNode = document.createElement('div'); tmpNode.innerHTML = imgHtml; if (a.replaceContentCssText) { var replaceContentCssText = a.replaceContentCssText.replace(/#height#/g, nodeH).replace(/#width#/g, nodeW); tmpNode.firstChild.style.cssText = replaceContentCssText; } else if (a.appendContentCssText) { tmpNode.firstChild.style.cssText += a.appendContentCssText; } var html = (a.outerContainerLeft || '') + tmpNode.innerHTML + (a.outerContainerRight || ''); tmpNode.innerHTML = html; tmpNode.firstChild.setAttribute(g.idAttr, nodeId); node.parentNode.insertBefore(tmpNode.firstChild, node.nextSibling); node.setAttribute('has-insert-preloading', '1'); } } } function init() { preloadingInit(g); } init(); })();






请到「今天看啥」查看全文