• This repository has been archived on 09/Feb/2020
  • Stars
    star
    113
  • Rank 308,304 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[Archived] A tiny comment system based on Github issue comments.

comment.js

GitHub release license

IMPORTANT!!! This project is archived and will no more be mantained! Please use gitalk or gitment instead.

Table of Contents

Pure JavaScript to make a Disqus-like comment system. Use issue system of code hosting sites like Github/OSChina as the backend. Easily to use. Free for running.

Demo

Dependencies

  • jQuery - for making Ajax requests and manipulating DOM.
  • marked - for rendering markdown.
  • timeago.js - for formatting time labels.
  • highlight.js - for syntax highlighting(optional).
  • spin - for displaying a spinning indicator(optional).

How to use

For people using Hexo as static blog generator, they can try a theme hexo-theme-freemind with comment.js as the default comment system that works out of box.

0. Add stylesheets and JavaScript files

<!-- stylesheet -->
<link rel="stylesheet" href="path_to_comment_css/comment.css">

<!-- for IE support -->
<!--[if lte IE 9]>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.9/es5-shim.min.js"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-sham.min.js"></script>
<![endif]-->

<!-- javascripts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.6/marked.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/timeago.js/3.0.2/timeago.min.js"></script>

<!-- loading spin indicator(optional) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.3.2/spin.min.js"></script>

<!-- syntax highlighting(optional) -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script type="text/javascript">
  marked.setOptions({
  highlight: function (code, lang) {
     return hljs.highlightAuto(code).value;
  }
  });
  function Highlighting(){
    var markdowns = document.getElementsByClassName('markdown');
    for(var i=0;i<markdowns.length;i++){
       if(markdowns[i].innerHTML) markdowns[i].innerHTML =marked(markdowns[i].innerHTML);
    }
  }
  window.addEventListener('DOMContentLoaded', Highlighting, false);
  window.addEventListener('load', Highlighting, false);
</script>

<!-- comment.js -->
<script src="path_to_comment_js/comment.js"></script>

1. Create Github Repo

Create a Github repo for hosting your comments.

2. Register an OAuth App

To avoid abused API calling, Github API (and the same as OSChina API) has Rate Limiting. To enlarge the limit you can register an OAuth application.

After that, you will get a client id as well as a client secret.

Tips: When you registering the App, the Authorization callback URL can be assigned as your site address. For example http://hahack.com .

3. Comment Thread

In this section I will describe on how to generate a comment thread of a certain page for your site.

Firstly, write a div for placing your comment thread.

<div id="comment-thread"></div>

Secondly, write a div for placing a spinning indicator(optional):

<div id="loading-spin"></div>

Thirdly, call getComments() function to fetch comment thread and display them to the page.

<script type="text/javascript">
   var opt = {
       type: "github",
	   user: "wzpan",
	   repo: "comment.js",
	   no_comment: "No comments yet. Press the button and go to comment now!",
	   go_to_comment: "Go to comment",
	   issue_id: "1",
	   btn_class: "btn",
	   comments_target: "#comment-thread",
	   loading_target: "#loading-spin",
	   client_id: "xxxxxx",
	   client_secret: "xxxxxx"
   };
   getComments(opt);
</script>

parameters explaning:

  • type: the site as the backend. Currently supports Github and OSChina.
  • user: your site's user account.
  • repo: your repo for comment issue tracking.
  • no_comment: tips when no comments are fetched.
  • go_to_comment: text of the "go to comment" button.
  • issue_title: the corresponding issue title to your page. Alternatively you can use issue_id.
  • issue_id: the corresponding issue id to your page. Alternatively you can use issue_title.
  • btn_class: css class name for the "go to comment" button.
  • comments_target: target for displaying comment thread.
  • loading_target(optional): target for displaying loading a spinning indicator.
  • client_id(optional but recommended): the client id of your OAuth App.
  • client_secret(optional but recommended): the client secret of your OAuth App.

example(You won't see this from README):

4. Recent Comment List

In this section I will describe on how to generate a recent comment list for your site.

Firstly, write a div for placing the recent comment list.

<div id="recent-comments"></div>

Secondly, call getRecentCommentsList() function to fetch a comment list and display them to the page.

<script type="text/javascript">
   var opt = {
       type: "github",
	   user: "wzpan",
	   repo: "comment.js",
	   recent_comments_target: "#recent-comments",
	   count: 5,
	   client_id: "xxxxxx",
	   client_secret: "xxxxxx"
   };
   getRecentCommentsList(opt);
</script>

parameters explaning:

  • type: the site as the backend. Currently supports Github and OSChina.
  • user: your site's user account.
  • repo: your repo for comment issue tracking.
  • recent_comments_target: target for displaying recent comment list.
  • count(optional): the maximize length of the comment list. Default value is 5.
  • client_id(optional but recommended): the client id of your OAuth App.
  • client_secret(optional but recommended): the client secret of your OAuth App.

example(You won't see this from README):

Browser support

All of the above browsers should support using comment.js, although I haven't fully test all of them.

  • Chrome
  • Safari
  • Firefox
  • IE8+

How to contribute

  • A Github star outweights 1000 dollars(一星胜千元).
  • Pull requests are always welcome.
  • Your donation will encourage me to improve this project. Supports Alipay & Wechat Pay.
Alipay Wechat Pay

More Repositories

1

wukong-robot

🤖 wukong-robot 是一个简单、灵活、优雅的中文语音对话机器人/智能音箱项目,支持ChatGPT多轮对话能力,还可能是首个支持脑机交互的开源智能音箱项目。
Python
5,319
star
2

cmake-demo

《CMake入门实战》源码
CMake
2,009
star
3

dingdang-robot

🤖 叮当是一款可以工作在 Raspberry Pi 上的中文语音对话机器人/智能音箱项目。
Python
1,857
star
4

BeamerStyleSlides

🌈Beamer风格的幻灯片模板集。包含了PowerPoint和Keynote两套格式。
TeX
949
star
5

hexo-generator-search

A plugin to generate search data for Hexo.
JavaScript
433
star
6

hexo-theme-freemind

Most powerful bootstrap theme for hexo.
CSS
392
star
7

Learn-Python-The-Hard-Way

My answer for the book Learn Python The Hard Way
Python
238
star
8

QtEVM

C++ implementation of EVM(Eulerian Video Magnification), based on OpenCV and Qt.
C++
166
star
9

hexo-theme-wixo

A wiki theme for Hexo.
CSS
155
star
10

wukong-contrib

来自用户贡献的wukong-robot插件集
Python
82
star
11

2dMorphing

2D Image Morphing Algorithms based on mesh warping. C++ project, which is transplanted from the c codes given by Yurong Sun and George Wolberg. Details: http://davis.wpi.edu/~matt/courses/morph/2d.htm
C++
68
star
12

orgwiki

用org-mode搭建的wiki,已经停止更新。新的笔记放在http://hahack.com/wiki
JavaScript
42
star
13

wzpan.github.io

个人博客,转载请保留出处。
HTML
36
star
14

rhubarb-lip-sync-ccc

Cocos Creator extension for rhubarb-lip-sync
JavaScript
30
star
15

2048

使用 Cocos Creator 开发微信小游戏 2048(代码基于 Cocos Creator 1.10)
JavaScript
29
star
16

MusicBoxApi

从网易云音乐Musicbox项目抽离出来的API,去掉了界面相关逻辑。
Python
28
star
17

wukong-itchat

用于微信控制wukong-robot
Python
26
star
18

hexo-tag-bootstrap

Bootstrap tag plugins for Freemind.
JavaScript
25
star
19

org-beamer-cn

[Deprecated] org-mode Simple Chinese Template for Beamer
24
star
20

ChatGPT-python-example

演示如何使用4行代码调用ChatGPT的官方API
Python
21
star
21

dingdang-smart-mi-fan

叮当机器人的智米电风扇插件
Python
17
star
22

xiaoai-wukong

小爱音箱联动wukong-robot
Python
15
star
23

awesome-config

My config file for Awesome window manager.
Lua
14
star
24

python-muse

A toy project to demonstrate how to interact with Muse Headband in Python.
Python
12
star
25

wukong-starter

wukong-robot 的基本环境安装脚本
Python
11
star
26

wukong-robot-pi-installer

wukong-robot 的树莓派 docker 安装脚本
Shell
9
star
27

dissertation

LaTeX source code of my master dissertation.
TeX
9
star
28

FC-EVM

Foreground Constrained Eulerian Video Magnification(FC-EVM)
C++
9
star
29

lipsync-demo

Cocos lipsync 插件的 demo 示例
JavaScript
8
star
30

chinese-chess-bot

中国象棋QQ频道机器人
Python
8
star
31

ReSpeaker-Switcher

ReSpeaker 2-Mics Pi HAT 麦克风开关
Python
7
star
32

wukong-qq-guild

wukong-robot 的 QQ 频道机器人客户端
Python
6
star
33

oil-price-bot

油价助手QQ频道机器人
Python
6
star
34

python2-miio

Python2 library for interfacing with Xiaomi miio components
Python
5
star
35

Qt_Toys

Some toy exemplars for Qt start-up.
C++
4
star
36

git-repo-sync

A tool to sync all branches from a git repo to another.
Python
3
star
37

wukong-doc

wukong-robot 的 reference 文档
HTML
3
star
38

wukong-next

腾讯 Next 课堂版本的 wukong-robot
Python
2
star
39

awesome-instant-apps

Awesome list for google instant apps.
2
star
40

MiMeshHelper

🤖 小米 Mesh 助手
Python
2
star
41

hexo-theme-freemind-blog

source blog repo for hexo-theme-freemind
HTML
1
star
42

infer-xcode-plugin

Facebook infer plugin for xcode.
Objective-C
1
star
43

MuseFlappyBird

Use Muse headband to play Flappy Bird game with blink event.
Python
1
star
44

timeline

my story
CSS
1
star
45

handout-with-script

A LaTeX template for writing script with handout of slides.
1
star