Py学习  »  chatgpt

用ChatGPT写一个数据采集程序

Python编程 • 2 年前 • 544 次点击  
来自公众号:Crossin的编程教室

上次我们讨论了ChatGPT在辅助编程学习上的一些用法:

如何用ChatGPT学Python

既然ChatGPT可以理解并生成代码,那么自然而然,它的作用不仅仅是帮助学习代码,同样也可以直接用在实际的软件开发当中。

对于网页上的数据采集及处理是Python的常见应用场景之一。我们来看下ChatGPT是不是也能完成这样的任务。

假设我们现在需要抓取并整理某个网页上的表格数据:

https://python666.cn/static/score.html

我们直接来问问ChatGPT,能不能给个抓取的代码:

ChatGPT给了我们一份代码,但很遗憾,把这个代码复制到编辑器中运行后,生成的Excel是空的。

简单调试后发现,原来是因为页面上的表头元素用的是

标签

而ChatGPT因为没有获知具体的页面代码信息,直接当做

标签来处理,所以没采集到表头信息。

这种情况下,我们可以手动对代码做一些修改。

或者,我们点击回答下方的“Regenerate response”,让它重新回答一次试试:

这次ChatGPT给出的代码比之前简洁:

import pandas as pd
# 读取网页上的表格url = 'https://python666.cn/static/score.html'tables = pd.read_html(url)
# 假设目标表格是第一个表格table = tables[0]
# 将表格保存为Excel文件output_file = 'table.xlsx'table.to_excel(output_file, index=False)
print(f"表格已保存为 {output_file}")

运行后,成功得到了我们要的结果:

顺利拿到数据后,我们再进一步,让ChatGPT来对数据进行排序。当然,在排序前,我们需要告诉它关于表格内容的必要信息:

代码:

import pandas as pd
# 读取网页上的表格url = 'https://python666.cn/static/score.html'tables = pd.read_html(url)
# 假设目标表格是第一个表格table = tables[0]
# 将缺失值替换为0table.fillna(0, inplace=True)
# 计算每个学生的均分table['均分'] = table.mean(axis=1)
# 按均分降序排序table.sort_values(by='均分', ascending=False, inplace=True)
# 将表格保存为Excel文件output_file = 'sorted_table.xlsx'table.to_excel(output_file, index=False)
print(f"按均分排序后的表格已保存为 {output_file}")

这次,ChatGPT完美实现了我们提出的需求:

可以看出,虽然ChatGPT很强大,但并不能保证每次生成的代码都是完美,仍然可能需要引导它修正或人工干预。

但即便如此,它也已经算得上一个十分得力的编程助手,可以大大提高开发效率。尤其像数据处理这种场景,以往开发时常常需要查找各种函数及其参数的使用方法。现在有了ChatGPT,只要准确描述数据格式及需求,就可以立刻得到相应的处理代码,非常的方便。

我现在做数据分析已经快离不开它了。

---END---

继续滑动看下一个
var __INLINE_SCRIPT__ = (function () { 'use strict'; var __setPubTime = function __setPubTime(svrTime, oriCreateTime, createTime, dom) { var oriTimestamp = oriCreateTime * 1; var dateObj = new Date(oriTimestamp * 1000); var padStart = function padStart(v) { return "0".concat(v).slice(-2); }; var year = dateObj.getFullYear(); var month = padStart(dateObj.getMonth() + 1); var date = padStart(dateObj.getDate()); var hour = padStart(dateObj.getHours()); var minute = padStart(dateObj.getMinutes()); var showDate = year + '-' + month + '-' + date + ' ' + hour + ':' + minute; if (dom) { dom.innerText = showDate; } }; if (!window.__second_open__) { var svrDate = '1699845442'; var oriCreateTime = '1699844824'; var createTime = '2023-11-13 11:07'; __setPubTime(svrDate, oriCreateTime, createTime, document.getElementById('publish_time')); window.__setPubTime = __setPubTime; } return __setPubTime; })(); '; 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 + ')'; } } }, error: function (xhr) { } }); })(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 = ""; } } } } })(); })(); 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-sticker', genId: function genId(opt) { return opt.node.getAttribute('data-md5') || ''; }, calW: function calW() { return 120; }, calH: function calH() { return 120; }, 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: '
' } ] }; 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 ajax(obj) { var url = obj.url; var xhr = new XMLHttpRequest(); var data = null; if (_typeof(obj.data) === 'object') { var d = obj.data; data = []; for (var k in d) { if (d.hasOwnProperty(k)) { data.push(k + '=' + encodeURIComponent(d[k])); } } data = data.join('&'); } else { data = typeof obj.data === 'string' ? obj.data : null; } xhr.open('POST', url, true); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { if (xhr.status >= 200 && xhr.status < 400) { obj.success && obj.success(xhr.responseText); } else { obj.error && obj.error(xhr); } obj.complete && obj.complete(); obj.complete = null; } }; xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.send(data); } 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 "break"; } if (window.__second_open__ && videos[vi].getAttribute('__sec_open_place_holder__')) { return "continue"; } 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 "continue"; } 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); a.parentNode; var index = vi; var mid = window.dataaaa.mid; var biz = window.dataaaa.bizuin; var idx = window.dataaaa.idx; ajax({ url: "/mp/videoplayer?vid=".concat(vid, "&mid=").concat(mid, "&idx=").concat(idx, "&__biz=").concat(biz, "&f=json"), type: 'GET', dataType: 'json', success: function success() { var json = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var ret = JSON.parse(json); var ori = ret.ori_status; var hitBizHeadimg = ret.hit_biz_headimg + '/64'; var hitNickname = ret.hit_nickname; var hitUsername = ret.hit_username; if (ori === 2 && hitUsername !== data.user_name) { var videoBar = document.createElement('div'); videoBar.innerHTML = "
") + '
以下视频来源于
' + '' + '
' + ''; 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(vid + index); var avatorSrc = avatorEle.dataset.src; console.log('avatorSrc' + avatorSrc); if (ret.hit_biz_headimg) { avatorEle.style.backgroundImage = "url(".concat(avatorSrc, ")"); } } }, error: function error(xhr) {} }); }; for (var vi = 0, viLen = videos.length; vi < viLen; vi++) { var _ret = _loop(); if (_ret === "break") break; if (_ret === "continue") 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; img.getAttribute('style'); 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(init_width); 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_4a5d9e4bb4ff"; var isCartoonCopyright = '0'; var is_care_mode = ''; var createTimestamp = '1699844824'; var picturePageInfoList = "[{'cdn_url':'http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/sz_mmbiz_png/icic13vic5h8JGHIwATmPick80whIAMzZ5ibGTgMbgXHKUK8GLIyoU51NUlsYxiambcwZahbLp5SZUBfiaE1aamjnHWxg/640?wx_fmt=png','width':'1080','height':'654'},{'cdn_url':'http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/sz_mmbiz_png/icic13vic5h8JGHIwATmPick80whIAMzZ5ibGy2biaSNOrib5w3KWxQ0fxaG9EUNG5LApWEBnnjsdE0RoTj1JOAicuTstA/640?wx_fmt=png','width':'1008','height':'1332'},{'cdn_url':'http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/sz_mmbiz_png/icic13vic5h8JGHIwATmPick80whIAMzZ5ibGicIF9Xibk3xV2Z6BYgCbkkcvMs01nwPmTpsS2icP0GhojZpWo6Ze9YYag/640?wx_fmt=png','width':'696','height':'164'},{'cdn_url':'http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/sz_mmbiz_png/icic13vic5h8JGHIwATmPick80whIAMzZ5ibGCtv9MB5BibjxK0ibDXKF5unToiaf01fMwznutuvk36D5QnnIJbls1CK6w/640?wx_fmt=png','width':'1080','height':'681'},{'cdn_url':'http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/sz_mmbiz_png/icic13vic5h8JGHIwATmPick80whIAMzZ5ibGo7lDpNMdwbWnfKuBrkv2dgPHSjdMcziamkS5YibInGAYRXicXtr7ItBpQ/640?wx_fmt=png','width':'1010','height':'956'},{'cdn_url':'http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/sz_mmbiz_png/icic13vic5h8JGHIwATmPick80whIAMzZ5ibG5mF6fYABticds7HcWPpP4PvYQibGhFIhUWboB59NFVXCLh4fCZs0KaLg/640?wx_fmt=png','width':'1080','height':'894'},{'cdn_url':'http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/sz_mmbiz_png/icic13vic5h8JGHIwATmPick80whIAMzZ5ibGwMhOGGcWme2lOiaRuP6jjkkjY9yH3JlibrfoCBK4Ix9LIzrRG4J1rEEw/640?wx_fmt=png','width':'978','height':'1258'},{'cdn_url':'http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/sz_mmbiz_png/icic13vic5h8JGHIwATmPick80whIAMzZ5ibGG7EVpPC9XhkDPIDBlYkfTFjaMLlwRWUKicCcGwnAemtFPgjQxl5VicRg/640?wx_fmt=png','width':'1080','height':'825'},]"; 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); })(); 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-sticker', genId: function genId(opt) { return opt.node.getAttribute('data-md5') || ''; }, calW: function calW() { return 120; }, calH: function calH() { return 120; }, 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: '
' } ] }; 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(); })(); ') .replace(/"/g, '"') .replace(/&/g, '&') .replace(/ /g, ' '); } var uin = ''; var key = ''; var pass_ticket = ''; var new_appmsg = 1; var item_show_type = "0"; var real_item_show_type = "0"; var can_see_complaint = "0"; var tid = ""; var aid = ""; var clientversion = ""; var appuin = "MzA5ODUzOTA0OQ==" || ""; var voiceid = ""; var create_time = "1699844824" * 1; var source = ""; var ascene = ""; var subscene = ""; var sessionid = "" || "svr_922ec8626aa"; var abtest_cookie = ""; var finder_biz_enter_id = "" * 1; var scene = 75; var itemidx = ""; var appmsg_token = "" || ""; var _copyright_stat = "2"; var _ori_article_type = ""; var is_follow = ""; var nickname = htmlDecode("Python编程"); var appmsg_type = "9"; var ct = "1699844824"; var user_name = "gh_4a5d9e4bb4ff"; var fakeid = ""; var version = ""; var is_limit_user = "0"; var cps_article_data = ""; var round_head_img = "http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/mmbiz_png/iciaMJDiaNTbG6iazJTODJDBuJTtqGzB0C6W53aw8Z1IKLqnO4icAEgvlQPXlS9xzKkXO12SfZFboQDQpwu1e6OuUSQ/0?wx_fmt=png"; var hd_head_img = "http://wx.qlogo.cn/mmhead/Q3auHgzwzM5MoJDiaiacco01g3lw4ZTQeQa6xrDN6ic5PxOU2JkU2Y7XQ/0" || ""; var ori_head_img_url = "http://wx.qlogo.cn/mmhead/Q3auHgzwzM5MoJDiaiacco01g3lw4ZTQeQa6xrDN6ic5PxOU2JkU2Y7XQ/132"; var msg_title = '用ChatGPT写一个数据采集程序'.html(false); var msg_desc = htmlDecode(""); var msg_cdn_url = "http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/mmbiz_jpg/iciaMJDiaNTbG72FIhq8EXzFmnuNQpRcCMJQInpiaYn3sdGD4z958onicoVbYM8gRxhYu8BOjx9YAeLHOsMhNpmVxLg/0?wx_fmt=jpeg"; var cdn_url_1_1 = "http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/mmbiz_jpg/iciaMJDiaNTbG72FIhq8EXzFmnuNQpRcCMJ100hAZrhX1RVjOYNGbfU4eELYrsgGIiauCho4jSicEAkbjj2UZ7cyNTA/0?wx_fmt=jpeg"; var cdn_url_235_1 = "http://img2.jintiankansha.me/get?src=http://mmbiz.qpic.cn/mmbiz_jpg/iciaMJDiaNTbG72FIhq8EXzFmnuNQpRcCMJQInpiaYn3sdGD4z958onicoVbYM8gRxhYu8BOjx9YAeLHOsMhNpmVxLg/0?wx_fmt=jpeg"; var msg_link = "http://mp.weixin.qq.com/s?__biz=MzA5ODUzOTA0OQ==&mid=2651705299&idx=1&sn=63d91d9c5af20a528c178af7f13fd40b&chksm=8b696c95bc1ee5834b4f578f7af899cc6445c2e539a8da98a069729f3c980924631fbe92af94#rd"; var user_uin = "" * 1; var msg_source_url = ''; var img_format = 'jpeg'; var srcid = ''; var req_id = '1311wdHxJ4TiojoHQIvkvOIB'; var networkType; var appmsgid = "" || '' || '2651705299'; var comment_id = "3191902962999083009" || "3191902962999083009" * 1; var comment_enabled = "" * 1; var open_fansmsg = "0" * 1; var is_https_res = ("" * 1) && (location.protocol == "https:"); var msg_daily_idx = "1" || ""; var profileReportInfo = "" || ""; var devicetype = ""; var source_encode_biz = "MjM5MDEyMDk4Mw=="; var source_username = "gh_5ffd8141d976"; var reprint_ticket = "PJWDru0au5eQppq0PhnUd%2FGu3c2EMg8ha423TF3XcEVJjv9IV44V6pV99eZlgO0t"; var source_mid = "2650190421"; var source_idx = "1"; var source_biz = "2390120983"; var author = "Crossin先生"; var author_id = "ofMoI4_qcot9V45SsDT2P4rNW544"; var author_cancel = "" * 1 || 0; var reward_wording = ""; var optimizing_flag = "0" * 1; var show_comment = ""; var __appmsgCgiData = { wxa_product: "" * 1, wxa_cps: "" * 1, show_msg_voice: "0" * 1, can_use_page: "" * 1, is_wxg_stuff_uin: "0" * 1, card_pos: "0", copyright_stat: "2", source_biz: "2390120983", hd_head_img: "http://wx.qlogo.cn/mmhead/Q3auHgzwzM5MoJDiaiacco01g3lw4ZTQeQa6xrDN6ic5PxOU2JkU2Y7XQ/0" || (window.location.protocol + "//" + window.location.host + "//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/pic/pic_rumor_link69de18.jpg"), has_red_packet_cover: "0" * 1 || 0, minishopCardData: "" }; var _empty_v = "//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/audios/empty69de18.mp3"; var appmsg_album_info = (function () { var curAlbumId = ''; var publicTagInfo = [ ]; for (var i = 0; i < publicTagInfo.length; i++) { if (curAlbumId) { if (curAlbumId === publicTagInfo[i].id) { return publicTagInfo[i]; } } else { if (publicTagInfo[i].continousReadOn) { return publicTagInfo[i]; } } } return {}; })(); var copyright_stat = "2" * 1; var hideSource = "0" * 1; var pay_fee = "" * 1; var pay_timestamp = ""; var need_pay = "" * 1; var is_pay_subscribe = "0" * 1; var need_report_cost = "0" * 1; var use_tx_video_player = "0" * 1; var appmsg_fe_filter = "contenteditable"; var friend_read_source = "" || ""; var friend_read_version = "" || ""; var friend_read_class_id = "" || ""; var is_only_read = "1" * 1; var read_num = "" * 1; var like_num = "" * 1; var liked = "" == 'true' ? true : false; var is_temp_url = "" ? 1 : 0; var tempkey = ""; var send_time = ""; var icon_emotion_switch = "//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/emotion/icon_emotion_switch69de18.svg"; var icon_emotion_switch_active = "//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/emotion/icon_emotion_switch_active69de18.svg"; var icon_emotion_switch_primary = "//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/emotion/icon_emotion_switch_primary69de18.svg"; var icon_emotion_switch_active_primary = "//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/emotion/icon_emotion_switch_active_primary69de18.svg"; var icon_loading_white = "//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/common/icon_loading_white69de18.gif"; var icon_audio_unread = "//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/audio/icon_audio_unread69de18.png"; var icon_qqmusic_default = "//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/audio/icon_qqmusic_default69de18.png"; var icon_qqmusic_source = "//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/audio/icon_qqmusic_source69de18.svg"; var icon_kugou_source = "//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/audio/icon_kugou_source69de18.png"; var topic_default_img = '//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/pic/pic_book_thumb69de18.png'; var comment_edit_icon = '//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/common/icon_edit69de18.png'; var comment_loading_img = '//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/common/icon_loading_white69de18.gif'; var comment_c2c_not_support_img = '//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/pic/pic_discuss_more69de18.png'; var tts_is_ban = '' * 1 || 0; var tts_is_show = '' * 1 || 0; var tts_heard_person_cnt = '' * 1 || 0; var voice_in_appmsg = { }; var voiceList = {}; voiceList={"voice_in_appmsg":[]} var reprint_style = '0' * 1; var reprint_type = '3' * 1; var wxa_img_alert = "" != 'false'; var weapp_sn_arr_json = "" || ""; var videoPageInfos = [ ]; window.__videoPageInfos = videoPageInfos; var video_snap_json = "" || ""; var mp_profile = [ ]; var ban_scene = "0" * 1; var ban_jump_link = { }; var svr_time = "1699845442" * 1; var is_transfer_msg = "" * 1 || 0; var malicious_title_reason_id = "0" * 1; var malicious_content_type = "0" * 1; var modify_time = "" * 1; var modify_detail = []; var isprofileblock = "0"; var jumpInfo = [ { title: '如何用ChatGPT学Python'.html(false), item_show_type: '0', url: 'http://mp.weixin.qq.com/s?__biz=MjM5MDEyMDk4Mw==&mid=2650190350&idx=1&sn=1ec30607f3f5609f9518ea1518386105&chksm=be4bbf76893c3660e16dd0e5fc5fb9a49e525d8a4ae6ce41acac30544b96c97d3cec880c196a&scene=21#wechat_redirect'.html(false).html(false), subject_name: 'Crossin的编程教室', link_type: 'LINK_TYPE_MP_APPMSG', } ]; window.service_type = '0' * 1; var hasRelatedArticleInfo = '0' * 1 || 0; var relatedArticleFlag = '' * 1 || 0; var canUseAutoTypeSetting; canUseAutoTypeSetting = '3' * 1 || 0; var styleType = '3'; var originTypeSetting = '3'; var originStyleType = '3'; var reprintEditable = '1'; var currentSvrStyleType, originSvrStyleType; if (!isNaN(parseInt(styleType)) && parseInt(styleType) > 0) { currentSvrStyleType = parseInt(styleType); } else if (!isNaN(parseInt(canUseAutoTypeSetting))) { currentSvrStyleType = parseInt(canUseAutoTypeSetting); } else { currentSvrStyleType = 0; } if (!isNaN(parseInt(originStyleType)) && parseInt(originStyleType) > 0) { originSvrStyleType = parseInt(originStyleType); } else if (!isNaN(parseInt(originTypeSetting))) { originSvrStyleType = parseInt(originTypeSetting); } else { originSvrStyleType = 0; } if (reprint_type > 0 && originSvrStyleType !== currentSvrStyleType && parseInt(reprintEditable) === 0) { var dc = document.getElementById('js_content').classList; dc.remove('autoTypeSetting'); dc.remove('autoTypeSetting24'); dc.remove('autoTypeSetting24psection'); var finalSetting = parseInt(originSvrStyleType); if (finalSetting === 1) { dc.add('autoTypeSetting'); } else if (finalSetting === 2) { dc.add('autoTypeSetting24'); } else if (finalSetting === 3) { dc.add('autoTypeSetting24psection'); } } window.wxtoken = "777"; window.is_login = '' * 1; window.__moon_initcallback = function () { if (!!window.__initCatch) { window.__initCatch({ idkey: 27611 + 2, startKey: 0, limit: 128, badjsId: 43, reportOpt: { uin: uin, biz: biz, mid: mid, idx: idx, sn: sn }, extInfo: { network_rate: 0.01, badjs_rate: 0.1 } }); } } var title = "Python编程"; var is_new_msg = true; var is_wash = '' * 1; var topbarEnable = false; var enterid = "" * 1 || "" * 1 || parseInt(Date.now() / 1000); var reloadid = '' * 1 || parseInt(Date.now() / 1000); var reloadseq = '' * 1 || 1; var miniprogram_appid = ""; var defaultAvatarUrl = '//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/icon/common/icon_avatar_default69de18.svg'; document.addEventListener('DOMContentLoaded', function () { window.domCompleteTime = Date.now(); }); var hasRecommendMsg = 0; ; var isPayTopic = '' * 1; var payTopicPrice = '' * 1; var isRemovedFromPayTopic = '' * 1; var isPaySubscribe = '0' * 1; var isPaid = '0' * 1; var isRefund = '' * 1; var payShowIAPPrice = 1; var payProductId = '' || ''; var previewPercent = '0' || ''; var payGiftsCount = '0' * 1 || 0; var payDesc = htmlDecode(''); var payFreeGift = '' * 1 || 0; var is_finished_preview = 0; var jump2pay = '' * 1; var isFans; var can_reward = '0' * 1 || 0; var is_need_reward = (isPaySubscribe && !isPaid) ? 0 : "0" * 1; var is_teenager = '' * 1 || 0; var is_care_mode = '' * 1 || 0; var anchor_tree_msg = ''; var colorScheme = ''; var iapPriceInfo = { }; var productPayPackage = { iap_price_info: iapPriceInfo }; var isCartoonCopyright = '0' * 1; var show_msg_voice = '' * 1; var qnaCardData = ''; var exptype = '' || ''; var expsessionid = '' || ''; var goContentId = ''; var goReplyId = ''; var show_related_article = '' * 1; var related_article_scene = '' * 1; var wwdistype = ''; window.cgiData = { appImg: '//res.wx.qq.com/mmbizappmsg/zh_CN/htmledition/js/images/pic/pic_tencent_video69de18.png', } window.ip_wording = { countryName: '中国', countryId: '156', provinceName: '福建', provinceId: '', cityName: '', cityId: '' }; window.show_ip_wording = '1' * 1; window.source_appid = 'wxcac20aa6eb1cbd61'; window.is_over_sea = '' * 1; window.showAdMark = "0" * 1; window.claim_source = { claim_source_type: '', claim_source: '', }; window.hideAdMarkOnCps = ("" || "0" * 1) ? 1 : 0; window.search_keywords = [ ]; window.s1s_keywords_exp_info = ''; var need_baike_preload = false; ; window.mmlisten_playlist_info_buffer = ''; = o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } var ua = navigator.userAgent; var is_ios = /(iPhone|iPad|iPod|iOS)/i.test(ua); var is_wp = /Windows\sPhone/i.test(ua); var is_android = /(Android)/i.test(ua); var is_wechat = /MicroMessenger\/([\d\.]+)/i.test(ua); var is_mac = /mac\sos/i.test(ua) && !is_ios; var is_windows = /windows\snt/i.test(ua) && !is_wp; var is_mpapp = /MPAPP\/([\d\.]+)/i.test(ua); var is_ipad = /iPad/i.test(ua); var is_windows_wechat = /WindowsWechat/i.test(ua); var is_mac_wechat = /MacWechat/i.test(ua) || /wechat.*mac os/i.test(ua); var is_prefetch = is_wechat && window.WeixinPrefecherJSBridge; var is_in_miniProgram = is_android && /miniprogram/.test(ua.toLowerCase()) || window.__wxjs_environment == 'miniprogram'; var is_wx_work = /wxwork/i.test(ua); function getUrlParams() { var vars = location.search.substring(1).split('&'); var params = {}; var _iterator = _createForOfIteratorHelper(vars), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var ele = _step.value; var pair = ele.split('='); var key = decodeURIComponent(pair[0]); if (typeof params[key] === 'undefined') { params[key] = decodeURIComponent(pair[1]); } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } return params; } function get() { var reg = /MicroMessenger\/([\d\.]+)/i; var ret = ua.match(reg); if (ret && ret[1]) { return ret[1]; } return false; } function getMac() { var reg = /MacWechat\/([\d\.]+)/i; var ret = ua.match(reg); if (ret && ret[1]) { return ret[1]; } return false; } function getMacOS() { var reg = /Mac OS X ([\d_]+)/i; var ret = ua.match(reg); if (ret && ret[1]) { return ret[1].replace(/_/g, '.'); } return false; } function getWindows() { var reg = /WindowsWechat\(0x(.+?)\)/i; var ret = ua.match(reg); if (ret && ret[1]) { return ret[1]; } return false; } function getWxWork() { var reg = /wxwork\/([\d\.]+)/i; var ret = ua.match(reg); if (ret && ret[1]) { return ret[1]; } return false; } function getMpApp() { var appVersion = [2, 4, 5]; var match = navigator.userAgent.match(/MPAPP\/(\d+(\.\d+)*)/); if (match) { appVersion = match[1].split('.').map(function (v) { return Number(v); }); } return appVersion.join('.'); } function getVersionNumber(hexStr) { return Number(Number('0x' + hexStr).toString(10)); } function getWindowsVersionFormat() { var versionInfo = navigator.userAgent.match(/WindowsWechat\(0x(\w+?)\)/); if (versionInfo && versionInfo.length === 2) { var version = versionInfo[1]; var mainVersion = getVersionNumber(version.slice(1, 2)); var subVersion = getVersionNumber(version.slice(2, 4)); var subVersion2 = getVersionNumber(version.slice(4, 6)); return [mainVersion, subVersion, subVersion2].join('.'); } return false; } function getInner() { var reg = /MicroMessenger\/[\d\.]+\(0x(.+?)\)/i; var ret = ua.match(reg); if (ret && ret[1] && ret[1] != null) { return ret[1]; } if (!ret && /MicroMessenger\/[\d\.]+/i.test(ua)) { var urlParams = getUrlParams(); if (urlParams.version) { return urlParams.version; } } return false; } var opfunc = { 'cp-1': function cp1(a, b) { return a < b; }, cp0: function cp0(a, b) { return a === b; }, cp1: function cp1(a, b) { return a > b; } }; function cpVersion(ver, op, canEq, type) { var mmver = false; switch (type) { case 'mac': mmver = getMac(); break; case 'windows': mmver = getWindowsVersionFormat(); break; case 'wxwork': mmver = getWxWork(); break; case 'mpapp': mmver = getMpApp(); break; default: mmver = get(); break; } if (!mmver) { return; } var mmversion = mmver.split('.'); var version = ver.split('.'); if (!/\d+/g.test(mmversion[mmversion.length - 1])) { mmversion.pop(); } for (var i = 0, len = Math.max(mmversion.length, version.length); i < len; ++i) { var mmv = mmversion[i] || ''; var v = version[i] || ''; var mmvn = parseInt(mmv, 10) || 0; var vn = parseInt(v, 10) || 0; var eq = opfunc.cp0(mmvn, vn); if (eq) { continue; } var cp = opfunc["cp".concat(op)]; return cp(mmvn, vn); } return canEq || op === 0; } function eqVersion(version) { return cpVersion(version, 0); } function gtVersion(version, canEq) { return cpVersion(version, 1, canEq); } function ltVersion(version, canEq) { return cpVersion(version, -1, canEq); } function getPlatform() { if (is_ios) { return 'ios'; } else if (is_android) { return 'android'; } else if (is_mac) { return 'mac_os'; } else if (is_windows) { return 'windows'; } return 'unknown'; } var is_google_play = false; var inner_ver_for_google_play_check = getInner(); if (is_android && inner_ver_for_google_play_check) { var v = '0x' + inner_ver_for_google_play_check.substr(-2); if (parseInt(v) >= 64 && parseInt(v) <= 79) { is_google_play = true; } } var mmversion = { get: get, getMac: getMac, getMacOS: getMacOS, getWindows: getWindows, getInner: getInner, getWxWork: getWxWork, getMpApp: getMpApp, cpVersion: cpVersion, eqVersion: eqVersion, gtVersion: gtVersion, ltVersion: ltVersion, getPlatform: getPlatform, isWp: is_wp, isIOS: is_ios, isAndroid: is_android, isInMiniProgram: is_in_miniProgram, isWechat: is_wechat, isMac: is_mac, isWindows: is_windows, isMacWechat: is_mac_wechat, isWindowsWechat: is_windows_wechat, isWxWork: is_wx_work, isOnlyWechat: is_wechat && !is_wx_work, isMpapp: is_mpapp, isNewMpApp: is_mpapp && cpVersion('3.0.0', 1, true, 'mpapp'), isIPad: is_ipad, isGooglePlay: is_google_play, isPrefetch: is_prefetch }; var initJsBridge = false; var JSAPIEventCallbackMap$1 = {}; function connectWebViewJavascriptBridge(callback) { if (window.WebViewMPapp || window.WebViewJavascriptBridge) { return callback(window.WebViewMPapp || window.WebViewJavascriptBridge); } if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); } window.WVJBCallbacks = [callback]; if (!initJsBridge) { initJsBridge = true; var WVJBIframe = document.createElement('iframe'); WVJBIframe.style.display = 'none'; WVJBIframe.src = 'https://__bridge_loaded__'; document.body.appendChild(WVJBIframe); setTimeout(function () { initJsBridge = false; document.body.removeChild(WVJBIframe); }, 0); } return false; } function invoke$1(jsapiName, opt, callback) { connectWebViewJavascriptBridge(function (bridge) { try { if (typeof opt === 'function') { callback = opt; } if (_typeof(opt) !== 'object') { opt = {}; } bridge.callHandler(jsapiName, opt, function (res) { try { var ret = _typeof(res) === 'object' ? res : JSON.parse(res); var errMsg = ret.err_msg || ret.errMsg; console.info("[mpapp jsapi] invoke->".concat(jsapiName, " ").concat(opt.action || '', " ").concat(errMsg)); typeof callback === 'function' && callback(ret); } catch (e) { window.WX_BJ_REPORT.BadJs.report('invoke', "callback ".concat(jsapiName, " error:"), { mid: 'mmbizwebapp:js_brridge', _info: e }); console.error("[mpapp jsapi] ".concat(jsapiName, " ").concat(opt.action || ''), e, res); } }); } catch (e) { window.WX_BJ_REPORT.BadJs.report('invoke', 'callback error:', { mid: 'mmbizwebapp:js_brridge', _info: e }); console.error('[mpapp jsapi]', e); } }); } function on$1(eventName, callback) { connectWebViewJavascriptBridge(function (bridge) { if (!JSAPIEventCallbackMap$1[eventName]) { JSAPIEventCallbackMap$1[eventName] = []; } JSAPIEventCallbackMap$1[eventName].push(callback); if (JSAPIEventCallbackMap$1[eventName].length 1) { return false; } try { bridge.registerHandler(eventName, function () { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } try { var data = typeof args[0] === 'string' ? JSON.parse(args[0]) : args[0]; console.info('[mpapp jsapi] event->' + eventName + ' ' + data.err_msg); if (JSAPIEventCallbackMap1[eventName].length) { var result; for (var i = 0; i < JSAPIEventCallbackMap$1[eventName].length; i++) { result = JSAPIEventCallbackMap$1[eventName][i].apply(window, [data].concat(args.slice(1))); } return result; } } catch (e) { window.WX_BJ_REPORT.BadJs.report('on', "callback ".concat(eventName, " error:"), { mid: 'mmbizwebapp:js_brridge', _info: e }); console.error('[mpapp jsapi] ' + eventName, e, args[0]); } }); } catch (e) { window.WX_BJ_REPORT.BadJs.report('on', 'callback error:', { mid: 'mmbizwebapp:js_brridge', _info: e }); console.error('[mpapp jsapi]', e); } }); } function remove$1(eventName, callback) { connectWebViewJavascriptBridge(function () { if (!JSAPIEventCallbackMap$1[eventName]) { return false; } var result = false; for (var i = JSAPIEventCallbackMap$1[eventName].length - 1; i >= 0; i--) { if (JSAPIEventCallbackMap$1[eventName][i] === callback) { JSAPIEventCallbackMap$1[eventName].splice(i, 1); result = true; } } return result; }); } var doc = {}; var isAcrossOrigin = false; var __moon_report = window.__moon_report || function () {}; var MOON_JSAPI_KEY_OFFSET = 8; try { doc = top.window.document; } catch (e) { isAcrossOrigin = true; } var JSAPIEventCallbackMap = {}; function ready(onBridgeReady) { var bridgeReady = function bridgeReady() { try { if (onBridgeReady) { window.onBridgeReadyTime = window.onBridgeReadyTime || Date.now(); onBridgeReady(); } } catch (e) { __moon_report([{ offset: MOON_JSAPI_KEY_OFFSET, log: 'ready', e: e }]); throw e; } window.jsapiReadyTime = Date.now(); }; if (!isAcrossOrigin && (typeof top.window.WeixinJSBridge === 'undefined' || !top.window.WeixinJSBridge.invoke)) { if (doc.addEventListener) { doc.addEventListener('WeixinJSBridgeReady', bridgeReady, false); } else if (doc.attachEvent) { doc.attachEvent('WeixinJSBridgeReady', bridgeReady); doc.attachEvent('onWeixinJSBridgeReady', bridgeReady); } } else { bridgeReady(); } } function invoke(methodName, args, callback) { ready(function () { if (isAcrossOrigin) return false; if (_typeof(top.window.WeixinJSBridge) !== 'object') { alert('请在微信中打开此链接'); return false; } top.window.WeixinJSBridge.invoke(methodName, args, function () { try { for (var _len = arguments.length, rets = new Array(_len), _key = 0; _key < _len; _key++) { rets[_key] = arguments[_key]; } var ret = rets[0]; var errMsg = ret && ret.err_msg ? ', err_msg-> ' + ret.err_msg : ''; console.info('[jsapi] invoke->' + methodName + errMsg); if (callback) { callback.apply(window, rets); } } catch (e) { __moon_report([{ offset: MOON_JSAPI_KEY_OFFSET, log: 'invoke;methodName:' + methodName, e: e }]); throw e; } }); }); } function call(methodName) { ready(function () { if (isAcrossOrigin) return false; if (_typeof(top.window.WeixinJSBridge) !== 'object') { return false; } try { top.window.WeixinJSBridge.call(methodName); } catch (e) { __moon_report([{ offset: MOON_JSAPI_KEY_OFFSET, log: 'call;methodName:' + methodName, e: e }]); throw e; } }); } function on(eventName, callback) { ready(function () { if (isAcrossOrigin) return false; if (_typeof(top.window.WeixinJSBridge) !== 'object' || !top.window.WeixinJSBridge.on) { return false; } if (!JSAPIEventCallbackMap[eventName]) { JSAPIEventCallbackMap[eventName] = []; } JSAPIEventCallbackMap[eventName].push(callback); if (JSAPIEventCallbackMap[eventName].length > 1) { return false; } top.window.WeixinJSBridge.on(eventName, function () { try { for (var _len2 = arguments.length, rets = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { rets[_key2] = arguments[_key2]; } var ret = rets[0]; var errMsg = ret && ret.err_msg ? ', err_msg-> ' + ret.err_msg : ''; console.info('[jsapi] event->' + eventName + errMsg); if (JSAPIEventCallbackMap[eventName] && JSAPIEventCallbackMap[eventName].length) { var result; for (var i = 0; i < JSAPIEventCallbackMap[eventName].length; i++) { result = JSAPIEventCallbackMap[eventName][i].apply(window, rets); } return result; } } catch (e) { __moon_report([{ offset: MOON_JSAPI_KEY_OFFSET, log: 'on;eventName:' + eventName, e: e }]); throw e; } }); }); } function remove(eventName, callback) { ready(function () { if (!JSAPIEventCallbackMap[eventName]) { return false; } var result = false; for (var i = JSAPIEventCallbackMap[eventName].length - 1; i >= 0; i--) { if (JSAPIEventCallbackMap[eventName][i] === callback) { JSAPIEventCallbackMap[eventName].splice(i, 1); result = true; } } return result; }); } var JSAPI = mmversion.isNewMpApp ? { ready: connectWebViewJavascriptBridge, invoke: invoke$1, call: invoke$1, on: on$1, remove: remove$1 } : { ready: ready, invoke: invoke, call: call, on: on, remove: remove }; var setImmersiveMode = function setImmersiveMode(itemShowType) { var envStr = window.__wxWebEnv && typeof window.__wxWebEnv.getEnv === 'function' && window.__wxWebEnv.getEnv(); if (!envStr) return; var envObj = {}; try { envObj = JSON.parse(envStr); } catch (err) { console.error(err); } var immersiveListMode = envObj.immersiveListMode || 0; window.__immersiveListMode = immersiveListMode; window.__test_immersive_list = 0; if (window.__test_immersive_list) { window.__immersiveListMode = 1; } var wxExpandArticleEle = document.getElementById('wx_expand_article'); document.getElementById('js_article'); var bottomLoadingTip = document.getElementById('js_network_msg_wrp'); if (!itemShowType && itemShowType !== 0) { itemShowType = window.item_show_type; } itemShowType = Number(itemShowType); if (window.__immersiveListMode && wxExpandArticleEle) { wxExpandArticleEle.style.display = 'block'; if (bottomLoadingTip) { bottomLoadingTip.style.display = 'none'; } if (itemShowType === 10 || itemShowType === 7) { document.body.classList.add('ellapse_short_content'); } else { document.body.classList.add('ellapse_stream_article'); } if (itemShowType === 0) { document.body.classList.add('article_extensive_background'); } var interactionPlaceholderEle = document.getElementById('js_interaction_placeholder'); if (interactionPlaceholderEle) { interactionPlaceholderEle.style.display = 'block'; } } var expandButton = document.getElementById('wx_expand_article_button'); if (expandButton) { expandButton.addEventListener('click', function () { wxExpandArticleEle.style.display = 'none'; if (itemShowType === 10 || itemShowType === 7) { document.body.classList.remove('ellapse_short_content'); } else { document.body.classList.remove('ellapse_stream_article'); } JSAPI.invoke('immerseReadFullArticle', function (res) { console.log("immerseReadFullArticle", res); }); }); } }; if (!window.__second_open__) { setImmersiveMode(); } return setImmersiveMode; })(); var __INLINE_SCRIPT__ = (function () { 'use strict'; var dealLikeReadShow_en = function dealLikeReadShow_en(realNum) { if (typeof LANG === 'undefined' || !LANG) { return parseInt(realNum) === 0 ? '' : realNum; } if (LANG == 'en') { var showHTML = ''; if (parseInt(realNum) > 100000) { showHTML = 100 + 'k+'; } else if (parseInt(realNum) > 10000 && parseInt(realNum) <= 100000) { var num = '' + parseInt(realNum) / 1000; var dotIndex = num.indexOf('.'); if (dotIndex === -1) { showHTML = num + 'k'; } else { showHTML = num.substring(0, dotIndex) + '.' + num.charAt(dotIndex + 1) + 'k'; } } else if (parseInt(realNum) === 0) { showHTML = ''; } else { showHTML = realNum; } return showHTML; } return ''; }; var i18n = { dealLikeReadShow_en: dealLikeReadShow_en }; function getWordCount (dom) { if (!dom) return 0; var textContet = dom.textContent || ''; var fillCharReg = new RegExp("\u200B", 'g'); var bookmarkFillCharReg = new RegExp("\u200D", 'g'); return textContet.replace(fillCharReg, '') .replace(bookmarkFillCharReg, '') .replace(/(\b|^)\w+(\b|$)/g, '#') .replace(/\s/g, '') .length; } function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } var ua = navigator.userAgent; var is_ios = /(iPhone|iPad|iPod|iOS)/i.test(ua); var is_wp = /Windows\sPhone/i.test(ua); var is_android = /(Android)/i.test(ua); var is_wechat = /MicroMessenger\/([\d\.]+)/i.test(ua); var is_mac = /mac\sos/i.test(ua) && !is_ios; var is_windows = /windows\snt/i.test(ua) && !is_wp; var is_mpapp = /MPAPP\/([\d\.]+)/i.test(ua); var is_ipad = /iPad/i.test(ua); var is_windows_wechat = /WindowsWechat/i.test(ua); var is_mac_wechat = /MacWechat/i.test(ua) || /wechat.*mac os/i.test(ua); var is_prefetch = is_wechat && window.WeixinPrefecherJSBridge; var is_in_miniProgram = is_android && /miniprogram/.test(ua.toLowerCase()) || window.__wxjs_environment == 'miniprogram'; var is_wx_work = /wxwork/i.test(ua); function getUrlParams() { var vars = location.search.substring(1).split('&'); var params = {}; var _iterator = _createForOfIteratorHelper(vars), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var ele = _step.value; var pair = ele.split('='); var key = decodeURIComponent(pair[0]); if (typeof params[key] === 'undefined') { params[key] = decodeURIComponent(pair[1]); } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } return params; } function get() { var reg = /MicroMessenger\/([\d\.]+)/i; var ret = ua.match(reg); if (ret && ret[1]) { return ret[1]; } return false; } function getMac() { var reg = /MacWechat\/([\d\.]+)/i; var ret = ua.match(reg); if (ret && ret[1]) { return ret[1]; } return false; } function getMacOS() { var reg = /Mac OS X ([\d_]+)/i; var ret = ua.match(reg); if (ret && ret[1]) { return ret[1].replace(/_/g, '.'); } return false; } function getWindows() { var reg = /WindowsWechat\(0x(.+?)\)/i; var ret = ua.match(reg); if (ret && ret[1]) { return ret[1]; } return false; } function getWxWork() { var reg = /wxwork\/([\d\.]+)/i; var ret = ua.match(reg); if (ret && ret[1]) { return ret[1]; } return false; } function getMpApp() { var appVersion = [2, 4, 5]; var match = navigator.userAgent.match(/MPAPP\/(\d+(\.\d+)*)/); if (match) { appVersion = match[1].split('.').map(function (v) { return Number(v); }); } return appVersion.join('.'); } function getVersionNumber(hexStr) { return Number(Number('0x' + hexStr).toString(10)); } function getWindowsVersionFormat() { var versionInfo = navigator.userAgent.match(/WindowsWechat\(0x(\w+?)\)/); if (versionInfo && versionInfo.length === 2) { var version = versionInfo[1]; var mainVersion = getVersionNumber(version.slice(1, 2)); var subVersion = getVersionNumber(version.slice(2, 4)); var subVersion2 = getVersionNumber(version.slice(4, 6)); return [mainVersion, subVersion, subVersion2].join('.'); } return false; } function getInner$1() { var reg = /MicroMessenger\/[\d\.]+\(0x(.+?)\)/i; var ret = ua.match(reg); if (ret && ret[1] && ret[1] != null) { return ret[1]; } if (!ret && /MicroMessenger\/[\d\.]+/i.test(ua)) { var urlParams = getUrlParams(); if (urlParams.version) { return urlParams.version; } } return false; } var opfunc = { 'cp-1': function cp1(a, b) { return a < b; }, cp0: function cp0(a, b) { return a === b; }, cp1: function cp1(a, b) { return a > b; } }; function cpVersion(ver, op, canEq, type) { var mmver = false; switch (type) { case 'mac': mmver = getMac(); break; case 'windows': mmver = getWindowsVersionFormat(); break; case 'wxwork': mmver = getWxWork(); break; case 'mpapp': mmver = getMpApp(); break; default: mmver = get(); break; } if (!mmver) { return; } var mmversion = mmver.split('.'); var version = ver.split('.'); if (!/\d+/g.test(mmversion[mmversion.length - 1])) { mmversion.pop(); } for (var i = 0, len = Math.max(mmversion.length, version.length); i < len; ++i) { var mmv = mmversion[i] || ''; var v = version[i] || ''; var mmvn = parseInt(mmv, 10) || 0; var vn = parseInt(v, 10) || 0; var eq = opfunc.cp0(mmvn, vn); if (eq) { continue; } var cp = opfunc["cp".concat(op)]; return cp(mmvn, vn); } return canEq || op === 0; } function eqVersion(version) { return cpVersion(version, 0); } function gtVersion(version, canEq) { return cpVersion(version, 1, canEq); } function ltVersion(version, canEq) { return cpVersion(version, -1, canEq); } function getPlatform() { if (is_ios) { return 'ios'; } else if (is_android) { return 'android'; } else if (is_mac) { return 'mac_os'; } else if (is_windows) { return 'windows'; } return 'unknown'; } var is_google_play = false; var inner_ver_for_google_play_check = getInner$1(); if (is_android && inner_ver_for_google_play_check) { var v = '0x' + inner_ver_for_google_play_check.substr(-2); if (parseInt(v) >= 64 && parseInt(v) <= 79) { is_google_play = true; } } var mmVersion = { get: get, getMac: getMac, getMacOS: getMacOS, getWindows: getWindows, getInner: getInner$1, getWxWork: getWxWork, getMpApp: getMpApp, cpVersion: cpVersion, eqVersion: eqVersion, gtVersion: gtVersion, ltVersion: ltVersion, getPlatform: getPlatform, isWp: is_wp, isIOS: is_ios, isAndroid: is_android, isInMiniProgram: is_in_miniProgram, isWechat: is_wechat, isMac: is_mac, isWindows: is_windows, isMacWechat: is_mac_wechat, isWindowsWechat: is_windows_wechat, isWxWork: is_wx_work, isOnlyWechat: is_wechat && !is_wx_work, isMpapp: is_mpapp, isNewMpApp: is_mpapp && cpVersion('3.0.0', 1, true, 'mpapp'), isIPad: is_ipad, isGooglePlay: is_google_play, isPrefetch: is_prefetch }; var isIOS = mmVersion.isIOS, getInner = mmVersion.getInner, isAndroid = mmVersion.isAndroid; var formatReadNum = function formatReadNum(value) { if (window.LANG === 'en') { return i18n.dealLikeReadShow_en(value); } var result = ''; if (parseInt(value, 10) > 100000) { result = '10万+'; } else if (parseInt(value, 10) 10000 && parseInt(value, 10) <= 100000) { var num = '' + parseInt(value, 10) / 10000; var dotIndex = num.indexOf('.'); if (dotIndex === -1) { result = num + '万'; } else { result = num.substr(0, dotIndex) + '.' + num.charAt(dotIndex + 1) + '万'; } } else if (parseInt(value, 10) === 0) { result = ''; } else { result = value || ''; } return result; }; var __setTingHeard = function __setTingHeard(container, dom, cnt, isTempUrl) { var articleWordCnt = getWordCount(container || document.querySelector('#js_content')); window.article_word_cnt = articleWordCnt; if (!dom || articleWordCnt <= 300 || isTempUrl) return; if (isIOS && getInner() >= '18002622' || isAndroid && getInner() >= '2800253A') { if (cnt > 100000) dom.innerText = "".concat(formatReadNum(cnt), "听过");else if (cnt > 0) dom.innerText = "".concat(formatReadNum(cnt), "人听过"); dom.style.removeProperty('display'); } }; if (!window.__second_open__) { var tempkey = window.tempkey || ''; var tingHeardDom = document.querySelector('#js_ting_heard'); var tingIsShow = window.tts_is_show || ''; var tingHeardCnt = window.tts_heard_person_cnt || ''; console.log('tingIsShow, tingHeardCnt', tingIsShow, tingHeardCnt); !!(tingIsShow * 1) && __setTingHeard(document.querySelector('#js_content'), tingHeardDom, tingHeardCnt * 1, !!tempkey); window.__setTingHeard = __setTingHeard; } return __setTingHeard; })(); (function () { 'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var classWhiteList = ['rich_pages', 'blockquote_info', 'blockquote_biz', 'blockquote_other', 'blockquote_article', 'h5_image_link', 'img_loading', 'list-paddingleft-1', 'list-paddingleft-2', 'list-paddingleft-3', 'selectTdClass', 'noBorderTable', 'ue-table-interlace-color-single', 'ue-table-interlace-color-double', '__bg_gif', 'weapp_text_link', 'weapp_image_link', 'qqmusic_area', 'tc', 'tips_global', 'unsupport_tips', 'qqmusic_wrp', 'appmsg_card_context', 'appmsg_card_active', 'qqmusic_bd', 'play_area', 'icon_qqmusic_switch', 'pic_qqmusic_default', 'qqmusic_thumb', 'access_area', 'qqmusic_songname', 'qqmusic_singername', 'qqmusic_source', 'share_audio_context', 'flex_context', 'pages_reset', 'share_audio_switch', 'icon_share_audio_switch', 'share_audio_info', 'flex_bd', 'share_audio_title', 'share_audio_tips', 'share_audio_progress_wrp', 'share_audio_progress', 'share_audio_progress_inner', 'share_audio_progress_buffer', 'share_audio_progress_loading', 'share_audio_progress_loading_inner', 'share_audio_progress_handle', 'share_audio_desc', 'share_audio_length_current', 'share_audio_length_total', 'video_iframe', 'vote_iframe', 'res_iframe', 'card_iframe', 'weapp_display_element', 'weapp_card', 'app_context', 'weapp_card_bd', 'weapp_card_profile', 'radius_avatar', 'weapp_card_avatar', 'weapp_card_nickname', 'weapp_card_info', 'weapp_card_title', 'weapp_card_thumb_wrp', 'weapp_card_ft', 'weapp_card_logo', 'pay', 'pay__mask', 'ct_geography_loc_tip', 'subsc_context', 'subsc_btn', 'reset_btn', 'icon_subsc', 'weui-primary-loading', 'weui-primary-loading__dot', 'wxw-img', 'mp-caret', 'appmsg_poi_iframe', 'cpc_iframe', 'channels_iframe_wrp', 'channels_iframe', 'videosnap_video_iframe', 'videosnap_live_iframe', 'videosnap_image_iframe', 'channels_live_iframe', 'minishop_iframe_wrp', 'minishop_iframe', 'mp_profile_iframe', 'mp_profile_iframe_wrp', 'mp_search_iframe_wrp', 'appmsg_search_iframe_wrp', 'appmsg_search_iframe', 'vote_area', 'vote_iframe', 'mp_vote_iframe_wrp', 'mp_vote_iframe', 'qqmusic_iframe', 'blockquote_iframe', 'blockquote_tips_iframe', 'video_iframe', 'shopcard_iframe', 'topic_iframe', 'weapp_app_iframe', 'img_fail_iframe', 'mp_miniprogram_iframe', 'appmsg_cpslink_iframe', 'js_editor_mpcpslink', 'mp-cpslink-iframe-wrp', 'mp_common_sticker_iframe', 'mp_common_sticker_iframe_wrp', 'mp_common_product_iframe', 'mp_common_product_iframe_wrp', 'new_cps_iframe']; var classWhiteListReg = [new RegExp('^editor__content__'), new RegExp('^wxw'), new RegExp('^js_'), new RegExp('^cps_inner'), new RegExp('^bizsvr_'), new RegExp('^code-snippet'), new RegExp('^wx_'), new RegExp('^wx-'), new RegExp('^icon_emoji_'), new RegExp('^custom_select_card') ]; var contentStyle = { classWhiteList: classWhiteList, classWhiteListReg: classWhiteListReg }; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function DomFilter (cgiOptData) { return function (Plugin) { var isMMVersionSetted = false; var contentDom = document.getElementById('js_content'); var classWhiteList = contentStyle.classWhiteList, classWhiteListReg = contentStyle.classWhiteListReg; var removeClassByWhiteList = function removeClassByWhiteList(node) { var classAttr = node.getAttribute('class'); if (classAttr) { var classList = classAttr.split(/\s+/); var newClassList = []; for (var i = 0, len = classList.length; i < len; ++i) { var className = classList[i]; if (className && classWhiteList.indexOf(className) != -1) { newClassList.push(className); } else { for (var j = 0, jl = classWhiteListReg.length; j < jl; j++) { if (classWhiteListReg[j].test(className)) { newClassList.push(className); break; } } } } node.setAttribute('class', newClassList.join(' ')); } }; var langBlackList = ['zh-cn', 'en-us']; var removeLangByBlackList = function removeLangByBlackList(node) { var langAttr = node.getAttribute('lang'); if (langAttr) { var lang = langAttr.toLowerCase(); for (var i = 0; i < langBlackList.length; i++) { if (lang === langBlackList[i]) { node.removeAttribute('lang'); return; } } } }; var isAccessMode = window.localStorage.getItem('isMpUserAccessibility'); var isCarton = (cgiOptData === null || cgiOptData === void 0 ? void 0 : cgiOptData.copyright_info.is_cartoon_copyright) || (cgiOptData === null || cgiOptData === void 0 ? void 0 : cgiOptData.user_info.is_care_mode) || isAccessMode === '1'; var bgPlaceholder = 'url("data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==")'; var lazyloadBackgroundImage = function lazyloadBackgroundImage(node) { if (window.__second_open__ && !isCarton && node && node.style && typeof node.getAttribute === 'function' && !node.getAttribute('data-lazy-bgimg')) { var bgImg = node.style.backgroundImage; var bgImgUrl = bgImg && bgImg.match(/url\(['"]?(.*?)['"]?\)/); if (bgImgUrl && bgImgUrl[1]) { node.style.backgroundImage = bgImg.replace(/url\(['"]?.*?['"]?\)/, bgPlaceholder); node.setAttribute('data-lazy-bgimg', bgImgUrl[1]); node.classList.add('wx_imgbc_placeholder'); } } }; return function (_Plugin) { _inherits(_class, _Plugin); var _super = _createSuper(_class); function _class() { _classCallCheck(this, _class); return _super.apply(this, arguments); } _createClass(_class, [{ key: "beforeConvertNode", value: function beforeConvertNode(el) { if (el && el.tagName) { var tagName = el.tagName.toLowerCase(); if (tagName !== 'iframe') { removeClassByWhiteList(el); removeLangByBlackList(el); lazyloadBackgroundImage(el); } else { if (el.getAttribute('class') === 'video_ad_iframe') { el.setAttribute('class', ''); } } } } }, { key: "afterConvertNode", value: function afterConvertNode(el) { if (!isMMVersionSetted) { var ua = navigator.userAgent; /(iPhone|iPad|iPod|iOS|mac\sos)/i.test(ua) ? contentDom.classList.add('fix_apple_default_style') : null; isMMVersionSetted = true; } if (el.style && el.style.webkitTextSizeAdjust !== '' && el.style.webkitTextSizeAdjust !== 'none') { el.style.webkitTextSizeAdjust = 'inherit'; } if (el.tagName === 'animate' && el.getAttribute('attributeName') === 'height') { var repeatCountVal = el.getAttribute('repeatCount'); if (repeatCountVal === 'indefinite' || repeatCountVal > '10') { if (el.getAttribute('begin') !== 'click' && el.getAttribute('end') !== 'click') { el.setAttribute('repeatCount', 'undefined'); el.setAttribute('attributeName', 'undefined'); new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=306525_1_1'; } } } if (el.tagName === 'OL') { if ((el.parentNode === document.getElementById('js_content') || el.parentNode.getAttribute('id') === 'js_secopen_content') && el.getAttribute('style') && el.getAttribute('style').indexOf('padding-left') < 0) { if (el.childNodes.length >= 10 && el.childNodes.length < 100) { el.classList.add('extra-list-padding-level1'); el.style.paddingLeft = '2.2em'; } else if (el.childNodes.length > 100) { el.classList.add('extra-list-padding-level2'); el.style.paddingLeft = '3.2em'; } } } } }]); return _class; }(Plugin); }; } if (!window.__second_open__ && window.Darkmode) { var cost = 0; window.Darkmode.extend([DomFilter()]); window.Darkmode.run(document.querySelectorAll('#js_content *'), { mode: '', defaultDarkBgColor: '', error: function error() { new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_0_1'; }, begin: function begin(isSwitch) { new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_2_1'; isSwitch && (new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_4_1'); cost = new Date() * 1; }, showFirstPage: function showFirstPage() { cost = new Date() * 1 - cost; var isTop = (document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop) === 0; if (cost <= 10) { new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_6_1'; isTop && (new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_13_1'); } else if (cost > 10 && cost <= 20) { new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_7_1'; isTop && (new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_14_1'); } else if (cost > 20 && cost <= 30) { new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_8_1'; isTop && (new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_15_1'); } else if (cost > 30 && cost <= 40) { new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_9_1'; isTop && (new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_16_1'); } else if (cost > 40 && cost <= 50) { new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_10_1'; isTop && (new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_17_1'); } else if (cost > 50 && cost <= 60) { new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_11_1'; isTop && (new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_18_1'); } else { new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_12_1'; isTop && (new Image().src = 'https://mp.weixin.qq.com/mp/jsmonitor?idkey=125617_19_1'); } } }); document.getElementById('js_content').style.visibility = 'visible'; } })(); = o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function updateProfileAttr(profiles, infos) { if (!profiles || !Array.isArray(profiles) || !infos || !Array.isArray(infos)) { return; } var _iterator = _createForOfIteratorHelper(profiles), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var profile = _step.value; var profileId = profile.getAttribute('data-id'); var profileInfo = findBizCardInfo(infos, profileId); if (profileInfo) { var is_biz_ban = profileInfo.is_biz_ban, original_num = profileInfo.original_num, biz_account_status = profileInfo.biz_account_status; profile.setAttribute('data-origin_num', original_num * 1); profile.setAttribute('data-is_biz_ban', is_biz_ban * 1); profile.setAttribute('data-isban', is_biz_ban * 1); profile.setAttribute('data-biz_account_status', biz_account_status * 1); } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } } function findBizCardInfo(infos, id) { return infos.find(function (info) { return info.fakeid === id; }); } function dealWithProfileData(data) { var _data$biz_card; if (!window.__second_open__) { return data; } var profileData = (data === null || data === void 0 ? void 0 : (_data$biz_card = data.biz_card) === null || _databiz_card.list) || []; profileData.map(function (item) { return item['original_num'] = item['orignal_num']; }); return profileData; } function updateCustomElementAttrs(dom, data) { if (!dom || !data) return; var profiles = dom.querySelectorAll('mp-common-profile'); updateProfileAttr(Array.from(profiles), dealWithProfileData(data)); } function preprocessMpAudios(dom, data) { var voiceList = window.__second_open__ ? data === null || data === void 0 ? void 0 : data.voice_in_appmsg_list_json : data.voiceList; if (typeof voiceList === 'string') { try { voiceList = JSON.parse(voiceList); } catch (e) { return; } } if (!dom || !voiceList) return; var albumlist = []; if (voiceList.voice_in_appmsg && voiceList.voice_in_appmsg.length > 0) { albumlist = voiceList.voice_in_appmsg; } var mpvoices = _toConsumableArray(dom.querySelectorAll('mpvoice')); mpvoices.forEach(function (mpvoice) { var mpaudio = document.createElement('mp-common-mpaudio'); var attrs = mpvoice.getAttributeNames().reduce(function (acc, name) { if (name === 'data-trans_state' || name === 'data-verify_state') return acc; return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, name, mpvoice.getAttribute(name))); }, {}); for (var key in attrs) { mpaudio.setAttribute(key, attrs[key]); } mpaudio.setAttribute('data-trans_state', 1); mpvoice.parentNode.replaceChild(mpaudio, mpvoice); }); var mpaudios = _toConsumableArray(dom.querySelectorAll('mp-common-mpaudio')); mpaudios.forEach(function (mpaudio) { mpaudio.setAttribute('author', data.nick_name || ''); var album = albumlist.find(function (a) { var voice_encode_fileid = mpaudio.getAttribute('voice_encode_fileid'); try { voice_encode_fileid = decodeURIComponent(voice_encode_fileid); } catch (e) {} return a.voice_id === voice_encode_fileid && a.appmsgalbuminfo; }); if (album) { mpaudio.setAttribute('data-topic_id', album.appmsgalbuminfo.album_id || 0); mpaudio.setAttribute('data-topic_name', album.appmsgalbuminfo.title || ''); mpaudio.setAttribute('data-topic_link', album.appmsgalbuminfo.link.html(false).replace('#wechat_redirect', '') + '#wechat_redirect'); mpaudio.setAttribute('data-topic_num', album.appmsgalbuminfo.tag_content_num || 0); } }); } function handleTagReplacement(ele, newTagName) { var newTag = document.createElement(newTagName); var _iterator2 = _createForOfIteratorHelper(ele.attributes), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var attr = _step2.value; newTag.setAttribute(attr.name, attr.value); } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } newTag.innerHTML = ele.innerHTML; ele.parentNode.replaceChild(newTag, ele); return newTag; } function preprocessMpMusic(root) { var qqmusicEles = _toConsumableArray(root.querySelectorAll('qqmusic')); qqmusicEles.forEach(function (ele) { return handleTagReplacement(ele, 'mp-common-qqmusic'); }); } if (!window.__second_open__) { updateCustomElementAttrs(window.document, window.mp_profile); preprocessMpAudios(window.document, { voiceList: window.voiceList, nick_name: window.nickname }); preprocessMpMusic(window.document); } exports.preprocessMpAudios = preprocessMpAudios; exports.preprocessMpMusic = preprocessMpMusic; exports.updateCustomElementAttrs = updateCustomElementAttrs; exports.updateProfileAttr = updateProfileAttr; Object.defineProperty(exports, '__esModule', { value: true }); return exports; })({});
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/164320