From 3274a095ed711e2466317bd5c467664214a2bfdb Mon Sep 17 00:00:00 2001 From: mip-platform Date: Wed, 28 Jun 2017 09:58:24 +0800 Subject: [PATCH] update extensions --- mip-233-tongji/README.md | 7 +- mip-233-tongji/mip-233-tongji.js | 3 +- mip-qqtn-cnzz/mip-qqtn-cnzz.js | 124 ++++--------------------------- 3 files changed, 18 insertions(+), 116 deletions(-) diff --git a/mip-233-tongji/README.md b/mip-233-tongji/README.md index 8b06d300..3eefdb33 100644 --- a/mip-233-tongji/README.md +++ b/mip-233-tongji/README.md @@ -12,9 +12,6 @@ ```html - - -\``` - - + +``` diff --git a/mip-233-tongji/mip-233-tongji.js b/mip-233-tongji/mip-233-tongji.js index 2aa4330e..8cd8081d 100644 --- a/mip-233-tongji/mip-233-tongji.js +++ b/mip-233-tongji/mip-233-tongji.js @@ -8,8 +8,9 @@ define(function (require) { // build 方法,元素插入到文档时执行,仅会执行一次 customElem.prototype.build = function () { var element = this.element; + var src = $(element).attr('data-host') + $(element).attr('data-query'); var s = document.createElement('script'); - s.src = 'https://s95.cnzz.com/stat.php?id=1254966436&web_id=1254966436'; + s.src = src; s.style.display = 'none'; s.language = 'JavaScript'; element.appendChild(s); diff --git a/mip-qqtn-cnzz/mip-qqtn-cnzz.js b/mip-qqtn-cnzz/mip-qqtn-cnzz.js index 665c7d56..906dfcdf 100644 --- a/mip-qqtn-cnzz/mip-qqtn-cnzz.js +++ b/mip-qqtn-cnzz/mip-qqtn-cnzz.js @@ -5,119 +5,23 @@ * @version 1.0 * @copyright 2016 Baidu.com, Inc. All Rights Reserved */ - define(function (require) { - var $ = require('zepto'); - var czc = require(''); var customElement = require('customElement').create(); + function mipcnzz() { + var cnzzprotocol = 'https://'; + var cnzzid; + var cnzzsite; + var jsStr = '%3Cspan id=\'cnzz_stat_icon_5932461'; + jsStr += cnzzid + '\'%3E%3C/span%3E%3Cscript src=\''; + jsStr += cnzzprotocol; + jsStr += cnzzsite; + jsStr += 's12.cnzz.com/stat.php%3Fid%3D593246'; + jsStr += cnzzid; + jsStr += '%26show%3Dpic1\' type=\'text/javascript\'%3E%3C/script%3E'; + document.write(unescape(jsStr)); + } customElement.prototype.build = function () { - var element = this.element; - var $element = $(element); - var token = element.getAttribute('token'); - var setConfig = element.getAttribute('setconfig'); - if (token) { - window.czc = window.czc || []; - czc.push([ - '_setAccount', - token - ]); - - // 检测setconfig是否存在 - if (setConfig) { - var setCustom = buildArry(decodeURIComponent(setConfig)); - czc.push(setCustom); - } - - var cnzzScript = document.createElement('script'); - var src = 'https://s12.cnzz.com/z_stat.php?id=' + token - + '&web_id=' + token; - cnzzScript.setAttribute('language', 'JavaScript'); - cnzzScript.src = src; - $element.append($(cnzzScript)); - bindEle(); - } - + mipcnzz(); }; - - - // 绑定事件 - function bindEle() { - var tagBox = document.querySelectorAll('*[data-stats-cnzz-obj]'); - - for (var index = 0; index < tagBox.length; index++) { - var statusData = tagBox[index].getAttribute('data-stats-cnzz-obj'); - - // 检测statusData是否存在 - if (!statusData) { - return; - } - - try { - statusData = JSON.parse(decodeURIComponent(statusData)); - } catch (e) { - return; - } - var eventtype = statusData.type; - if (!statusData.data) { - return; - } - var data = buildArry(statusData.data); - - if (eventtype !== 'click' && eventtype !== 'mouseup' && eventtype !== 'load') { - // 事件限制到click,mouseup,load(直接触发) - return; - } - - if ($(tagBox[index]).hasClass('mip-stats-eventload')) { - return; - } - - $(tagBox[index]).addClass('mip-stats-eventload'); - - if (eventtype === 'load') { - czc.push(data); - } - else { - tagBox[index].addEventListener(eventtype, function (event) { - var tempData = this.getAttribute('data-stats-cnzz-obj'); - if (!tempData) { - return; - } - var statusJson; - try { - statusJson = JSON.parse(decodeURIComponent(tempData)); - } catch (e) { - return; - } - if (!statusJson.data) { - return; - } - var attrData = buildArry(statusJson.data); - czc.push(attrData); - }, false); - } - } - } - - // 数据换转 - function buildArry(arrayStr) { - if (!arrayStr) { - return; - } - - var strArr = arrayStr.slice(1, arrayStr.length - 1).split(','); - var newArray = []; - - for (var index = 0; index < strArr.length; index++) { - var item = strArr[index].replace(/(^\s*)|(\s*$)/g, '').replace(/\'/g, ''); - if (item === 'false' || item === 'true') { - item = Boolean(item); - } - - newArray.push(item); - } - return newArray; - } - return customElement; });