]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
github voting
authorAilin Nemui <redacted>
Wed, 24 Aug 2016 18:28:53 +0000 (20:28 +0200)
committerAilin Nemui <redacted>
Wed, 24 Aug 2016 18:28:53 +0000 (20:28 +0200)
_includes/footer.html
assets/js/votes.js [new file with mode: 0644]
index.html

index 1438833a22f98e8d9af94f38d9c6bc7bf2e2be41..e273f29ac9cbafe1df042d4d76160bf3aa585440 100644 (file)
@@ -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 (file)
index 0000000..4fb585d
--- /dev/null
@@ -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, $);
index 6cbafe47ef3e8422924d0aaf4f84aca7f66008b2..b44aa251c56c90d1382b86ead736a4048cc2e1b4 100644 (file)
@@ -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">&hellip;</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>
git clone https://git.99rst.org/PROJECT