-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #439 from Doublemine/pisces
Feature:notes and show number of visitors to each article
- Loading branch information
Showing
7 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ sidebar: | |
post: | ||
posted: 发表于 | ||
in: 分类于 | ||
visitors: 阅读次数 | ||
read_more: 阅读全文 | ||
untitled: 未命名 | ||
toc_empty: 此文章未包含目录 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ sidebar: | |
post: | ||
posted: 發表於 | ||
in: 分類於 | ||
visitors: 閱讀次數 | ||
read_more: 閱讀全文 | ||
untitled: 未命名 | ||
toc_empty: 此文章未包含目錄 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ sidebar: | |
post: | ||
posted: 發表於 | ||
in: 分類於 | ||
visitors: 閱讀次數 | ||
read_more: 閱讀全文 | ||
untitled: 未命名 | ||
toc_empty: 此文章未包含目錄 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<!-- custom analytics part create by xiamo --> | ||
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script> | ||
<script>AV.initialize("{{theme.leancloud_visitors.app_id}}", "{{theme.leancloud_visitors.app_key}}");</script> | ||
<script> | ||
function showTime(Counter) { | ||
var query = new AV.Query(Counter); | ||
$(".leancloud_visitors").each(function() { | ||
var url = $(this).attr("id").trim(); | ||
query.equalTo("url", url); | ||
query.find({ | ||
success: function(results) { | ||
if (results.length == 0) { | ||
var content = $(document.getElementById(url)).text() + ': 0'; | ||
$(document.getElementById(url)).text(content); | ||
return; | ||
} | ||
for (var i = 0; i < results.length; i++) { | ||
var object = results[i]; | ||
var content = $(document.getElementById(url)).text() + ': ' + object.get('time'); | ||
$(document.getElementById(url)).text(content); | ||
} | ||
}, | ||
error: function(object, error) { | ||
console.log("Error: " + error.code + " " + error.message); | ||
} | ||
}); | ||
|
||
}); | ||
} | ||
|
||
function addCount(Counter) { | ||
var Counter = AV.Object.extend("Counter"); | ||
url = $(".leancloud_visitors").attr('id').trim(); | ||
title = $(".leancloud_visitors").attr('data-flag-title').trim(); | ||
var query = new AV.Query(Counter); | ||
query.equalTo("url", url); | ||
query.find({ | ||
success: function(results) { | ||
if (results.length > 0) { | ||
var counter = results[0]; | ||
counter.fetchWhenSave(true); | ||
counter.increment("time"); | ||
counter.save(null, { | ||
success: function(counter) { | ||
var content = $(document.getElementById(url)).text() + ': ' + counter.get('time'); | ||
$(document.getElementById(url)).text(content); | ||
}, | ||
error: function(counter, error) { | ||
console.log('Failed to save Visitor num, with error message: ' + error.message); | ||
} | ||
}); | ||
} else { | ||
var newcounter = new Counter(); | ||
newcounter.set("title", title); | ||
newcounter.set("url", url); | ||
newcounter.set("time", 1); | ||
newcounter.save(null, { | ||
success: function(newcounter) { | ||
var content = $(document.getElementById(url)).text() + ': ' + newcounter.get('time'); | ||
$(document.getElementById(url)).text(content); | ||
}, | ||
error: function(newcounter, error) { | ||
console.log('Failed to create'); | ||
} | ||
}); | ||
} | ||
}, | ||
error: function(error) { | ||
console.log('Error:' + error.code + " " + error.message); | ||
} | ||
}); | ||
} | ||
$(function() { | ||
var Counter = AV.Object.extend("Counter"); | ||
if ($('.leancloud_visitors').length == 1) { | ||
addCount(Counter); | ||
} else if ($('.post-title-link').length > 1) { | ||
showTime(Counter); | ||
} | ||
}); | ||
</script> |