Commit 6f0f0487 authored by Van's avatar Van

uvstat

parent b1ebf0b2
......@@ -17,7 +17,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<script src="https://cdn.jsdelivr.net/npm/uvstat@v1.0.2/dist/index.min.js"></script>
<#--<script src="https://cdn.jsdelivr.net/npm/uvstat@v1.0.2/dist/index.min.js"></script>-->
<script src="/js/index.min.js"></script>
<script>
var Label = {
servePath: "${servePath}",
......
......@@ -33,8 +33,8 @@ var Util = {
* 初始化浏览数
*/
initViewCnt: function () {
Util.uvstat = new Uvstat({loading:'<span>0</span>'})
Util.uvstat.setStat()
Util.uvstat = new Uvstat()
Util.uvstat.addStat()
Util.uvstat.renderStat()
},
/**
......
/*!
* uvstat v1.0.2 - Statistics tool for static page.
*
* MIT License
*
* Copyright (c) 2019-present B3log 开源, b3log.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Uvstat=e():t.Uvstat=e()}(window,(function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e);var o=function(t,e,n){return new Promise((function(o,r){fetch(t,{body:JSON.stringify(e),cache:"no-cache",method:"POST"}).then((function(t){return t.json()})).then((function(t){return o(t)})),n&&setTimeout((function(){r(e)}),n)}))},r=function(t,e,n,o){return new(n||(n=Promise))((function(r,i){function a(t){try{u(o.next(t))}catch(t){i(t)}}function c(t){try{u(o.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}u((o=o.apply(t,e||[])).next())}))},i=function(t,e){var n,o,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,o=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(r=(r=a.trys).length>0&&r[r.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){a.label=i[1];break}if(6===i[0]&&a.label<r[1]){a.label=r[1],r=i;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},a=function(){function t(t){this.options=function(t){var e={cache:!0,cacheId:"uvstat",loading:'<svg version="1.1" style="vertical-align: bottom;" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 100 100" enable-background="new 0 0 0 0" xml:space="preserve">\n<circle fill="#3b3e43" stroke="none" cx="6" cy="50" r="6">\n<animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.1"></animate>\n</circle>\n<circle fill="#3b3e43" stroke="none" cx="26" cy="50" r="6">\n<animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.2"></animate>\n</circle>\n<circle fill="#3b3e43" stroke="none" cx="46" cy="50" r="6">\n<animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.3"></animate>\n</circle>\n</svg>',location:{hash:!1,pathname:!0,search:!1},renderName:"uvstaturl",timeout:2e3,url:"https://hacpai.com/uvstat"};return t&&t.location&&(t.location=Object.assign({},e.location,t.location)),Object.assign({},e,t)}(t)}return t.prototype.getStat=function(t,e){return void 0===e&&(e=0),r(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return[4,o(this.options.url+"/get",{data:t},e)];case 1:return[2,n.sent().data]}}))}))},t.prototype.renderStat=function(){return r(this,void 0,void 0,(function(){var t,e,n=this;return i(this,(function(o){switch(o.label){case 0:if(t=[],document.querySelectorAll("[data-"+this.options.renderName+"]").forEach((function(e){t.push({count:parseInt(e.textContent.trim(),10)||0,url:e.getAttribute("data-"+n.options.renderName).toLowerCase()});var o=e.getBoundingClientRect().height;e.innerHTML=n.options.loading,e.firstElementChild.style.height=o+"px",e.firstElementChild.style.width=o+"px"})),0===t.length)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.getStat(t,this.options.timeout)];case 2:return e=o.sent(),Object.keys(e).forEach((function(t){var o=document.querySelector("[data-"+n.options.renderName+'="'+t+'" i]');o&&(o.innerText=e[t].toString())})),[3,4];case 3:return o.sent(),t.forEach((function(t){var e=document.querySelector("[data-"+n.options.renderName+'="'+t+'" i]');e&&(e.innerText="0")})),[3,4];case 4:return[2]}}))}))},t.prototype.addStat=function(){var t=location.origin;if(this.options.location.pathname&&(t+=location.pathname),this.options.location.search&&(t+=location.search),this.options.location.hash&&(t+=location.hash),t=t.toLowerCase(),this.options.cache){var e=JSON.parse(localStorage.getItem(this.options.cacheId)||"[]");if(e.includes(t))return;e.push(t),localStorage.setItem(this.options.cacheId,JSON.stringify(e)),o(this.options.url+"/inc?url="+t)}else o(this.options.url+"/inc?url="+t)},t.prototype.clearCache=function(){localStorage.removeItem(this.options.cacheId)},t}();e.default=a}]).default}));
\ No newline at end of file
......@@ -70,7 +70,7 @@
&nbsp; | &nbsp;
<span class="vditor-tooltipped vditor-tooltipped__n" aria-label="${viewCountLabel}">
<i class="icon-views"></i>
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span> ${viewLabel}
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span> ${viewLabel}
</span>
</div>
</header>
......
......@@ -87,9 +87,7 @@
</span>
</#list>
&nbsp;&nbsp;${viewCount1Label}
<a rel="nofollow" href="${servePath}${article.articlePermalink}" data-uvstaturl="${servePath}${article.articlePermalink}">
0
</a>
<a rel="nofollow" href="${servePath}${article.articlePermalink}" data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</a>
</div>
<div class="clear"></div>
<div class="marginTop12">
......
......@@ -59,7 +59,7 @@
</li>
<li>
<a rel="nofollow" href="${servePath}${article.articlePermalink}" title="${viewLabel}">
${viewLabel} (<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span>)
${viewLabel} (<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span>)
</a>
</li>
<#if commentable>
......
......@@ -66,7 +66,7 @@
<a class="ft__red" href="${servePath}${article.articlePermalink}#comments"><#if article.articleCommentCount gt 0>${article.articleCommentCount} </#if>${commentLabel}</a>
</#if>
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span> ${viewLabel}
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span> ${viewLabel}
</div>
</div>
......
......@@ -77,7 +77,7 @@
${article.articleUpdateDate?string("yyyy-MM-dd")} •
</time>
<a class="post__view" href="${servePath}${article.articlePermalink}">
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span> ${viewLabel}</a>
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span> ${viewLabel}</a>
<div class="fn-right">
<span class="vditor-tooltipped vditor-tooltipped__n post__share-icon ft-green"
onclick="$('#comment').focus()"
......@@ -125,7 +125,7 @@
<div class="article__toolbar">
<div class="wrapper">
<a class="post__view" href="${servePath}${article.articlePermalink}">
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span> ${viewLabel}
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span> ${viewLabel}
</a>
<div class="fn-right">
<span class="vditor-tooltipped vditor-tooltipped__n post__share-icon ft-green"
......
......@@ -66,7 +66,7 @@
</a>&nbsp;&nbsp;
</#if>
<a rel="nofollow" href="${servePath}${article.articlePermalink}">
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span>&nbsp;&nbsp;${viewLabel}
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span>&nbsp;&nbsp;${viewLabel}
</a>
</div>
<div class="clear"></div>
......
......@@ -62,7 +62,7 @@
<#if article.category??>
in <a href="${servePath}/category/${article.category.categoryURI}">${article.category.categoryTitle}</a>
</#if>
with <span data-uvstaturl="${servePath}${article.articlePermalink}">0</span> views
with <span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span> views
<#if commentable>
<#if article.articleCommentCount != 0>
and <a href="#comments">${article.articleCommentCount} comments</a>
......
......@@ -78,7 +78,7 @@
<div class="margin25">
<a rel="nofollow" href="${servePath}${article.articlePermalink}" class="left">
<span class="left article-browserIcon" title="${viewLabel}"></span>
<span class="count"><span data-uvstaturl="${servePath}${article.articlePermalink}">0</span></span>
<span class="count"><span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span></span>
</a>
<div class="left">
<span class="tagsIcon" title="${tagLabel}"></span>
......
......@@ -81,7 +81,7 @@
<div class="margin5">
<a rel="nofollow" class="left" href="${servePath}${article.articlePermalink}">
<span title="${viewLabel}" class="left article-browserIcon"></span>
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span>
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span>
</a>
<div class="left">
<span title="${tagLabel}" class="tagsIcon"></span>
......
......@@ -65,7 +65,7 @@
</a>
</#if>
<a rel="nofollow" data-ico="&#xe185;" href="${servePath}${article.articlePermalink}">
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span>
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span>
</a>
<a rel="nofollow" data-ico="&#x0060;" href="${servePath}/authors/${article.authorId}">
${article.authorName}
......
......@@ -68,7 +68,7 @@
</span>
</#if>
&nbsp; | &nbsp; ${viewsLabel}
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span>°C
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span>°C
</div>
</header>
......
......@@ -79,7 +79,7 @@
</#if>
<span class="tag">
<i class="icon__views"></i>
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span> ${viewLabel}
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span> ${viewLabel}
</span>
</div>
......
......@@ -59,7 +59,7 @@ ${topBarReplacement}
</#if>${article.articleUpdateDate?string("yyyy-MM-dd HH:mm")} |
${viewCount1Label}
<a rel="nofollow" href="${servePath}${article.articlePermalink}">
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span>
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span>
</a>
<#if commentable> | ${commentCount1Label}
<a rel="nofollow" href="${servePath}${article.articlePermalink}#comments">
......
......@@ -90,7 +90,7 @@ ${topBarReplacement}
</#if>
<span class="ico-view ico" title="${viewLabel}">
<a rel="nofollow" href="${servePath}${article.articlePermalink}">
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span>
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span>
</a>
</span>
</article>
......
......@@ -95,7 +95,7 @@
</a>
</#if>
<a rel="nofollow" href="${servePath}${article.articlePermalink}" class="left">
&nbsp;&nbsp;<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span> ${viewLabel}&nbsp;&nbsp;
&nbsp;&nbsp;<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span> ${viewLabel}&nbsp;&nbsp;
</a>
</div>
<div class="clear"></div>
......
......@@ -74,7 +74,7 @@
<a class="vditor-tooltipped__n vditor-tooltipped link fn__flex-center"
href="${servePath}${article.articlePermalink}"
aria-label="${viewLabel}">
<span data-uvstaturl="${servePath}${article.articlePermalink}">0</span>
<span data-uvstaturl="${servePath}${article.articlePermalink}">${article.articleViewCount}</span>
<span class="icon-views"></span>
</a>
<a rel="nofollow" href="${servePath}/authors/${article.authorId}" class="fn__flex-center">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment