]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
load votes from cache instead of github api
authorAilin Nemui <redacted>
Sat, 4 Apr 2020 21:44:39 +0000 (23:44 +0200)
committerAilin Nemui <redacted>
Sat, 4 Apr 2020 22:42:27 +0000 (00:42 +0200)
[skip ci]

_includes/footer.html
assets/js/sorttable.js
assets/js/votes2.js [new file with mode: 0644]

index e273f29ac9cbafe1df042d4d76160bf3aa585440..e88f2663d818fc531138ad811ed2a26d33c7d979 100644 (file)
@@ -1,10 +1,11 @@
         <script src="assets/js/jquery.min.js"></script>
+        <script src="assets/js/votes2.js"></script>
+        <script async src="https://ailin-nemui.github.io/irssi-script-votes/votes.js"></script>
         <script src="assets/js/bootstrap.min.js"></script>
         <script src="assets/js/sorttable.js"></script>
         <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;
index 6d54c1a1655a42cefe2703186d0e46a6f2b7e07d..f103beb51bef4a44f6ab986c15c676dad75a648c 100644 (file)
@@ -36,7 +36,14 @@ sorttable = {
         sorttable.makeSortable(table);
       }
     });
-
+    if (window.sortSorttable) {
+      var k;
+      for (k in sortSorttable) {
+        sortSorttable[k]();
+        delete sortSorttable[k];
+      }
+    }
+    sorttable.MADE = true;
   },
 
   makeSortable: function(table) {
diff --git a/assets/js/votes2.js b/assets/js/votes2.js
new file mode 100644 (file)
index 0000000..6cbdf07
--- /dev/null
@@ -0,0 +1,47 @@
+(function(document){
+    'use strict';
+    function sort() {
+       var myTH = $("#th-votes");
+       var isSorted = [0];
+       Array.prototype.forEach.call(myTH[0].parentNode.children, function(e) {
+           if (e.classList.contains("sorttable_sorted") || e.classList.contains("sorttable_sorted_reverse")) {
+               isSorted[0] = 1;
+           }
+       });
+       if (!isSorted[0]) {
+           sorttable.innerSortFunction.apply(myTH[0].parentNode.children[0], []);
+           sorttable.innerSortFunction.apply(myTH[0].parentNode.children[0], []);
+           sorttable.innerSortFunction.apply(myTH[0], []);
+           sorttable.innerSortFunction.apply(myTH[0], []);
+       }
+    }
+    function signalDone() {
+       var myTH = $("#th-votes");
+       myTH.html("Votes");
+       if (window.sorttable && window.sorttable.MADE) {
+           sort();
+       } else {
+           if (!window.sortSorttable) { window.sortSorttable = {}; }
+           sortSorttable.votes = sort;
+       }
+    }
+    function addVotes(d) {
+       var script;
+       for (script in d) {
+           var sn = script.replace(/[^-a-zA-Z0-9_]/g, "_");
+           var row = $("#script-" + sn + " .votes");
+           if (row.length) {
+               var votes = d[script].v;
+               var link = "*";
+               if (d[script].h) link = "💜";
+               row.html( "" + votes  );
+               row.append("<span><a data-toggle=\"tooltip\" title=\"vote on github\" href=\""
+                          + d[script].u + "\">"+link+"</a></span>");
+               row.attr("sorttable_customkey", 9999+votes);
+           }
+       }
+       signalDone();
+    }
+
+    window.addVotes = addVotes;
+})(document);
git clone https://git.99rst.org/PROJECT