This commit is contained in:
2019-05-30 18:52:14 +08:00
commit aa360a22bf
341 changed files with 30369 additions and 0 deletions

View File

@ -0,0 +1,4 @@
{% include 'busuanzi-counter.swig' %}
{% include 'tencent-mta.swig' %}
{% include 'tencent-analytics.swig' %}
{% include 'cnzz-analytics.swig' %}

View File

@ -0,0 +1,11 @@
{% if theme.application_insights %}
<script>
var appInsights=window.appInsights||function(config){
function i(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s="AuthenticatedUserContext",h="start",c="stop",l="Track",a=l+"Event",v=l+"Page",y=u.createElement(o),r,f;y.src=config.url||"https://az416426.vo.msecnd.net/scripts/a/ai.0.js";u.getElementsByTagName(o)[0].parentNode.appendChild(y);try{t.cookie=u.cookie}catch(p){}for(t.queue=[],t.version="1.0",r=["Event","Exception","Metric","PageView","Trace","Dependency"];r.length;)i("track"+r.pop());return i("set"+s),i("clear"+s),i(h+a),i(c+a),i(h+v),i(c+v),i("flush"),config.disableExceptionTracking||(r="onerror",i("_"+r),f=e[r],e[r]=function(config,i,u,e,o){var s=f&&f(config,i,u,e,o);return s!==!0&&t["_"+r](config,i,u,e,o),s}),t
}({
instrumentationKey:"{{ theme.application_insights }}"
});
window.appInsights=appInsights;
appInsights.trackPageView();
</script>
{% endif %}

View File

@ -0,0 +1,11 @@
{% if theme.baidu_analytics %}
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?{{ theme.baidu_analytics }}";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
{% endif %}

View File

@ -0,0 +1,27 @@
{% if theme.busuanzi_count.enable %}
<div class="busuanzi-count">
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
{% if theme.busuanzi_count.total_visitors %}
<span class="post-meta-item-icon">
<i class="fa fa-{{ theme.busuanzi_count.total_visitors_icon }}"></i>
</span>
<span class="site-uv" title="{{ __('footer.total_visitors') }}">
<span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
</span>
{% endif %}
{% if theme.busuanzi_count.total_visitors and theme.busuanzi_count.total_views %}
<span class="post-meta-divider">|</span>
{% endif %}
{% if theme.busuanzi_count.total_views %}
<span class="post-meta-item-icon">
<i class="fa fa-{{ theme.busuanzi_count.total_views_icon }}"></i>
</span>
<span class="site-pv" title="{{ __('footer.total_views') }}">
<span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
</span>
{% endif %}
</div>
{% endif %}

View File

@ -0,0 +1,5 @@
{% if theme.cnzz_siteid %}
<div style="display: none;">
<script src="//s95.cnzz.com/z_stat.php?id={{ theme.cnzz_siteid }}&web_id={{ theme.cnzz_siteid }}"></script>
</div>
{% endif %}

View File

@ -0,0 +1,18 @@
{% if theme.facebook_sdk.enable %}
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '{{ theme.facebook_sdk.app_id }}',
xfbml : true,
version: 'v3.3'
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/{{ config.language|replace('-', '_') }}/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
{% endif %}

View File

@ -0,0 +1,99 @@
{% if theme.firestore.enable %}
<script src="https://www.gstatic.com/firebasejs/4.6.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.6.0/firebase-firestore.js"></script>
{% if theme.firestore.bluebird %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.5.1/bluebird.core.min.js"></script>
{% endif %}
<script>
(function () {
firebase.initializeApp({
apiKey: '{{ theme.firestore.apiKey }}',
projectId: '{{ theme.firestore.projectId }}'
})
function getCount(doc, increaseCount) {
//increaseCount will be false when not in article page
return doc.get().then(function (d) {
var count
if (!d.exists) { //has no data, initialize count
if (increaseCount) {
doc.set({
count: 1
})
count = 1
}
else {
count = 0
}
}
else { //has data
count = d.data().count
if (increaseCount) {
if (!(window.localStorage && window.localStorage.getItem(title))) { //if first view this article
doc.set({ //increase count
count: count + 1
})
count++
}
}
}
if (window.localStorage && increaseCount) { //mark as visited
localStorage.setItem(title, true)
}
return count
})
}
function appendCountTo(el) {
return function (count) {
$(el).append(
$('<span>').addClass('post-visitors-count').append(
$('<span>').addClass('post-meta-divider').text('|')
).append(
$('<span>').addClass('post-meta-item-icon').append(
$('<i>').addClass('fa fa-users')
)
).append($('<span>').text('{{ __("post.views")}} ' + count))
)
}
}
var db = firebase.firestore()
var articles = db.collection('{{ theme.firestore.collection }}')
//https://hexo.io/docs/variables.html
var isPost = '{{ page.title }}'.length > 0
var isArchive = '{{ page.archive }}' === 'true'
var isCategory = '{{ page.category }}'.length > 0
var isTag = '{{ page.tag }}'.length > 0
if (isPost) { //is article page
var title = '{{ page.title }}'
var doc = articles.doc(title)
getCount(doc, true).then(appendCountTo($('.post-meta')))
}
else if (!isArchive && !isCategory && !isTag) { //is index page
var titles = [] //array to titles
var postsstr = '{% for post in page.posts %}titles.push("{{ post.title }}");{% endfor %}' //if you have a better way to get titles of posts, please change it
eval(postsstr)
var promises = titles.map(function (title) {
return articles.doc(title)
}).map(function (doc) {
return getCount(doc)
})
Promise.all(promises).then(function (counts) {
var metas = $('.post-meta')
counts.forEach(function (val, idx) {
appendCountTo(metas[idx])(val)
})
})
}
})()
</script>
{% endif %}

View File

@ -0,0 +1,12 @@
{% if theme.google_analytics.tracking_id %}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ theme.google_analytics.tracking_id }}"></script>
<script>
var host = window.location.hostname;
if (host !== "localhost" || !{{theme.google_analytics.localhost_ignored}}) {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ theme.google_analytics.tracking_id }}');
}
</script>
{% endif %}

View File

@ -0,0 +1,7 @@
{% if theme.growingio_analytics %}
<script>
!function(e,t,n,g,i){e[i]=e[i]||function(){(e[i].q=e[i].q||[]).push(arguments)},n=t.createElement("script"),tag=t.getElementsByTagName("script")[0],n.async=1,n.src=('https:'==document.location.protocol?'https://':'http://')+g,tag.parentNode.insertBefore(n,tag)}(window,document,"script","assets.growingio.com/2.1/gio.js","gio");
gio('init','{{theme.growingio_analytics}}', {});
gio('send');
</script>
{% endif %}

View File

@ -0,0 +1,6 @@
{% include 'facebook-sdk.swig' %}
{% include 'vkontakte-api.swig' %}
{% include 'google-analytics.swig' %}
{% include 'baidu-analytics.swig' %}
{% include 'application-insights.swig' %}
{% include 'growingio.swig' %}

View File

@ -0,0 +1,116 @@
{% if theme.leancloud_visitors.enable and !theme.valine.visitor %}
{# custom analytics part create by xiamo; edited by LEAFERx #}
<script>
{% if page.layout === 'post' %}
function addCount(Counter) {
var $visitors = $('.leancloud_visitors');
var url = $visitors.attr('id').trim();
var title = $visitors.attr('data-flag-title').trim();
Counter('get', '/classes/Counter', { where: JSON.stringify({ url }) })
.done(function({ results }) {
if (results.length > 0) {
var counter = results[0];
{% if theme.leancloud_visitors.betterPerformance %}
var $element = $(document.getElementById(url));
$element.find('.leancloud-visitors-count').text(counter.time + 1);
{% endif %}
Counter('put', '/classes/Counter/' + counter.objectId, JSON.stringify({ time: { '__op': 'Increment', 'amount': 1 } }))
{% if not theme.leancloud_visitors.betterPerformance %}
.done(function() {
var $element = $(document.getElementById(url));
$element.find('.leancloud-visitors-count').text(counter.time + 1);
})
{% endif %}
.fail(function ({ responseJSON }) {
console.log('Failed to save Visitor num, with error message: ' + responseJSON.error);
})
} else {
{% if theme.leancloud_visitors.security %}
var $element = $(document.getElementById(url));
$element.find('.leancloud-visitors-count').text('Counter not initialized! More info at console err msg.');
console.error('ATTENTION! LeanCloud counter has security bug, see how to solve it here: https://github.com/theme-next/hexo-leancloud-counter-security. \n However, you can still use LeanCloud without security, by setting `security` option to `false`.');
{% else %}
Counter('post', '/classes/Counter', JSON.stringify({ title: title, url: url, time: 1 }))
.done(function() {
var $element = $(document.getElementById(url));
$element.find('.leancloud-visitors-count').text(1);
})
.fail(function() {
console.log('Failed to create');
});
{% endif %}
}
})
.fail(function ({ responseJSON }) {
console.log('LeanCloud Counter Error: ' + responseJSON.code + ' ' + responseJSON.error);
});
}
{% else %}
function showTime(Counter) {
var entries = [];
var $visitors = $('.leancloud_visitors');
$visitors.each(function() {
entries.push( $(this).attr('id').trim() );
});
Counter('get', '/classes/Counter', { where: JSON.stringify({ url: { '$in': entries } }) })
.done(function({ results }) {
var COUNT_CONTAINER_REF = '.leancloud-visitors-count';
if (results.length === 0) {
$visitors.find(COUNT_CONTAINER_REF).text(0);
return;
}
for (var i = 0; i < results.length; i++) {
var item = results[i];
var url = item.url;
var time = item.time;
var element = document.getElementById(url);
$(element).find(COUNT_CONTAINER_REF).text(time);
}
for (var i = 0; i < entries.length; i++) {
var url = entries[i];
var element = document.getElementById(url);
var countSpan = $(element).find(COUNT_CONTAINER_REF);
if (countSpan.text() == '') {
countSpan.text(0);
}
}
})
.fail(function ({ responseJSON }) {
console.log('LeanCloud Counter Error: ' + responseJSON.code + ' ' + responseJSON.error);
});
}
{% endif %}
$(function() {
$.get('https://app-router.leancloud.cn/2/route?appId=' + '{{ theme.leancloud_visitors.app_id }}')
.done(function({ api_server }) {
var Counter = function(method, url, data) {
return $.ajax({
method: method,
url: 'https://' + api_server + '/1.1' + url,
headers: {
'X-LC-Id': '{{ theme.leancloud_visitors.app_id }}',
'X-LC-Key': '{{ theme.leancloud_visitors.app_key }}',
'Content-Type': 'application/json',
},
data: data
});
};
{% if page.layout === 'post' %}
addCount(Counter);
{% else %}
if ($('.post-title-link').length >= 1) {
showTime(Counter);
}
{% endif %}
});
});
</script>
{% endif %}

View File

@ -0,0 +1,10 @@
{% if theme.tencent_analytics %}
<script>
(function() {
var hm = document.createElement("script");
hm.src = "//tajs.qq.com/stats?sId={{ theme.tencent_analytics }}";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
{% endif %}

View File

@ -0,0 +1,13 @@
{% if theme.tencent_mta %}
<script>
var _mtac = {};
(function() {
var mta = document.createElement("script");
mta.src = "https://pingjs.qq.com/h5/stats.js";
mta.setAttribute("name", "MTAH5");
mta.setAttribute("sid", "{{theme.tencent_mta}}");
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(mta, s);
})();
</script>
{% endif %}

View File

@ -0,0 +1,25 @@
{% if theme.vkontakte_api.enable %}
<div id="vk_api_transport"></div>
<script>
window.vkAsyncInit = function() {
VK.init({
apiId: {{ theme.vkontakte_api.app_id }}
});
{% if not is_home() and (is_post() and theme.vkontakte_api.like) %}
VK.Widgets.Like("vk_like", {type: "mini", height: 20});
{% endif %}
{% if page.comments and theme.vkontakte_api.comments %}
VK.Widgets.Comments("vk_comments", {limit: {{ theme.vkontakte_api.num_of_posts }}, attach: "*"});
{% endif %}
};
setTimeout(function() {
var el = document.createElement("script");
el.type = "text/javascript";
el.src = "//vk.com/js/api/openapi.js";
el.async = true;
document.getElementById("vk_api_transport").appendChild(el);
}, 0);
</script>
{% endif %}