diff options
| -rw-r--r-- | _includes/footer.html | 1 | ||||
| -rw-r--r-- | assets/js/votes.js | 75 | ||||
| -rw-r--r-- | index.html | 6 | 
3 files changed, 80 insertions, 2 deletions
| diff --git a/_includes/footer.html b/_includes/footer.html index 1438833..e273f29 100644 --- a/_includes/footer.html +++ b/_includes/footer.html @@ -4,6 +4,7 @@          <script src="assets/js/filtertable.js"></script>          <script src="assets/js/jquery.timeago.js"></script>          <script src="assets/js/hashfill.js"></script> +        <script src="assets/js/votes.js"></script>          <script>              $(function() {                jQuery.timeago.settings.cutoff = 365*24*60*60*1000; diff --git a/assets/js/votes.js b/assets/js/votes.js new file mode 100644 index 0000000..4fb585d --- /dev/null +++ b/assets/js/votes.js @@ -0,0 +1,75 @@ +(function(document, $){ +    'use strict'; +    var jsonpRe = /^\/\*[\s\S]*?\*\/jsonp\(([\s\S]*)\)$/m; + +    function requestAll(start) { +	$.ajax({ +	    accepts: { json: 'application/vnd.github.squirrel-girl-preview' }, +	    dataType: 'json', +	    url: start, +	    jsonp: false, +	    jsonpCallback: 'jsonp', +	    dataFilter: function(dta, typ) { +		if (typ == "json") { +		    return dta.replace(jsonpRe, "$1"); +		} +		return dta; +	    } +	}) +	    .done(function(r) { +		var remaining = r.meta['X-RateLimit-Remaining']; +		var rateReset = r.meta['X-RateLimit-Reset']; +		var timeOut = 0; +		var hasMore = false; +		if (remaining < 10) { +		    timeOut = 1000 + rateReset * 1000 - (new Date() / 1); +		} +		if (timeOut < 0) timeOut = 0; +		if (r.meta.Link) { +		    r.meta.Link.forEach(function(l) { +			if (l[1].rel == "next") { +			    window.setTimeout(function(){requestAll(l[0]);}, timeOut); +			    hasMore = true; +			    return; +			} +		    }); +		} +		if (timeOut > 0) { +		    timeOut += 1000; +		} + +		r.data.forEach(function(e) { +		    e.body = e.body.replace(/\r/g, ""); +		    var redir = e.body.match(/^#(\d+)$/); +		    if (redir) { +			var l = start.replace(/(\/issues\/)\d+(\/comments\?)/, "$1" + redir[1] + "$2").replace(/&.*/, ""); +			window.setTimeout(function(){requestAll(l);}, timeOut); +			hasMore = true; +			return; +		    } +			 +		    var lines = e.body.split("\n"); +		    var script = lines[0].replace(/[^-a-zA-Z0-9_]/g, "_"); +		    if (script == "comment") { +			script = "adv_windowlist_pl"; +		    } +		    var st = "#script-" + script + " .votes"; +		    var row = $(st); +		    if (row.length) { +			var votes = 1+ e.reactions['+1'] - e.reactions['-1']; +			var link = "*"; +			if (e.reactions['heart'] >= votes) { +			    link = "💜"; +			} +			row.html( "" + votes ); +			 +			row.append("<span><a data-toggle=\"tooltip\" title=\"vote on github\" href=\"" + e.html_url + "\">"+link+"</a></span>"); +		    } +		}); +		if (!hasMore) { +		    $("#th-votes").html("Votes"); +		} +	    }); +    } +    requestAll('https://api.github.com/repos/ailin-nemui/scripts.irssi.org/issues/2/comments?callback=jsonp'); +})(document, $); @@ -37,7 +37,7 @@ layout: default              <dt>How do I submit a script to this page?</dt>              <dd>See information on how to contribute <a href="https://github.com/irssi/scripts.irssi.org">here</a>.</dd>          </dl> - +	          <hr>          <input type="search" class="light-table-filter form-control" data-table="sortable" data-name="q" placeholder="Filter" style="width: 100%"> @@ -50,11 +50,12 @@ layout: default                      <th class="sorttable_alpha">Description</th>                      <th class="sorttable_alpha">Authors</th>                      <th class="sorttable_alpha">Modified</th> +                    <th class="sorttable_numeric" id="th-votes">…</th>                  </tr>              </thead>              <tbody>              {% for script in site.data.scripts %} -                <tr> +                <tr id="script-{{ script.filename | replace: ".", "_" }}">                      <td class="filename">                          <a href="scripts/{{ script.filename }}">{{ script.filename }}</a>                          <small> @@ -70,6 +71,7 @@ layout: default                              {{ script.modified | date: "%Y-%m-%d" }}                          </abbr>                      </td> +		    <td class="votes"></td>                  </tr>              {% endfor %}              </tbody> | 
