Gab.ai User Stats

Profile a user's timeline by clicking a button that appears on user pages

  1. // ==UserScript==
  2. // @name Gab.ai User Stats
  3. // @namespace http://gab.ai/Jeremy20_9
  4. // @version 0.1
  5. // @description Profile a user's timeline by clicking a button that appears on user pages
  6. // @author Jeremiah 20:9
  7. // @match https://gab.ai/*
  8. // @exclude https://gab.ai/self-censor
  9. // @exclude https://gab.ai/notifications
  10. // @exclude https://gab.ai/home
  11. // @exclude https://gab.ai/popular
  12. // @exclude https://gab.ai/pulse
  13. // @exclude https://gab.ai/following
  14. // @exclude https://gab.ai/followers
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18. $(document).ready(function(){
  19. var btndiv = document.createElement("div");
  20. $(btndiv).click(function(){
  21. var numfollowers = user.follower_count;
  22. var numfollowing = user.following_count;
  23. var numposts = user.post_count;
  24.  
  25. var introduction = "";
  26. var rextags = /#[A-Za-z0-9_]+/gmi;
  27. var rexats = /@[A-Za-z0-9_]+/gmi;
  28.  
  29. var plist = (postlist.posts.length > 0) ? postlist.posts : userpostlist.posts;
  30. var mentions = 0;
  31. var replies = 0;
  32. var reposts = 0;
  33. var replyreposts = 0;
  34. var regularposts = 0;
  35. var totalposts = plist.length;
  36. var tags = {};
  37. var ats = {};
  38. var votetotal = 0;
  39. var gifposts = 0;
  40. var linkposts = 0;
  41. var textposts = 0;
  42. var days = new Array(7);
  43.  
  44. days[0] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  45. days[1] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  46. days[2] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  47. days[3] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  48. days[4] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  49. days[5] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  50. days[6] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  51.  
  52. for(var p in plist)
  53. {
  54. var body = plist[p].post.body;
  55.  
  56.  
  57. var rexgif = /giphy\.com\/media\/\w+\/[\w-_]+\.gif/gmi;
  58.  
  59. if(plist[p].post.embed.html)
  60. {
  61. if(rexgif.test(plist[p].post.embed.html))
  62. gifposts++;
  63. else
  64. linkposts++;
  65. }
  66. else
  67. {
  68. textposts++;
  69. }
  70.  
  71. // gather tags
  72. var m = rextags.exec(body);
  73. var posttextval = body;
  74. while(m && m.length > 0)
  75. {
  76. var ttext = m[0].toLowerCase();
  77. if(tags[ttext] === undefined)
  78. tags[ttext] = 1;
  79. else
  80. tags[ttext]++;
  81.  
  82. posttextval = posttextval.substr(m.index + m[0].length);
  83. m = rextags.exec(posttextval);
  84. }
  85.  
  86. var cdate = Date.parse(plist[p].post.created_at);
  87. cdate = new Date(cdate);
  88. var day = cdate.getDay();
  89. var hour = cdate.getHours();
  90. days[day][hour]++;
  91.  
  92. var type = null;
  93. if(plist[p].type == "repost" && !plist[p].post.is_reply)
  94. {
  95. type = "repost";
  96. reposts++;
  97. }
  98. else if(plist[p].type == "repost" && plist[p].post.is_reply)
  99. {
  100. type = "replyrepost";
  101. replyreposts++;
  102. }
  103. else if(plist[p].post.is_reply)
  104. {
  105. type = "reply";
  106. replies++;
  107. }
  108. else if(body.indexOf("@") === 0)
  109. {
  110. type = "mention";
  111. mentions++;
  112. }
  113. else
  114. {
  115. regularposts++;
  116. type = "post";
  117. }
  118.  
  119. if(type == "post" && /#introduceyourself/gmi.test(body))
  120. {
  121. introduction = body;
  122. }
  123. if(type == "post" || type == "mention" || type == "reply")
  124. {
  125. m = rexats.exec(body);
  126. posttextval = body;
  127. while(m && m.length > 0)
  128. {
  129. var atext = m[0].toLowerCase();
  130. if(ats[atext] === undefined)
  131. ats[atext] = 1;
  132. else
  133. ats[atext]++;
  134.  
  135. posttextval = posttextval.substr(m.index + m[0].length);
  136. m = rexats.exec(posttextval);
  137. }
  138. }
  139. if(type == "post")
  140. votetotal += plist[p].post.score;
  141. }
  142.  
  143. var message = "";
  144.  
  145. if(introduction !== "")
  146. message += "Introduction:\n" + introduction + "\n\n";
  147.  
  148. var percregposts = Math.round(100 * (regularposts / totalposts));
  149. var percreposts = Math.round(100 * (reposts / totalposts));
  150. var percreplies = Math.round(100 * (replies / totalposts));
  151. var percreplyreposts = Math.round(100 * (replyreposts / totalposts));
  152. var percmentions = Math.round(100 * (mentions / totalposts));
  153.  
  154. message += "Post Distribution:\n";
  155. message += Math.round(100 * (regularposts / totalposts)) + "% posts\n";
  156. message += Math.round(100 * (reposts / totalposts)) + "% reposts\n";
  157. message += Math.round(100 * (replies / totalposts)) + "% replies\n";
  158. message += Math.round(100 * (replyreposts / totalposts)) + "% reply reposts\n";
  159. message += Math.round(100 * (mentions / totalposts)) + "% mentions\n";
  160. message += "\n\n";
  161.  
  162. message += "Content Distribution:\n";
  163. message += Math.round(100 * (textposts / totalposts)) + "% text posts\n";
  164. message += Math.round(100 * (linkposts / totalposts)) + "% link posts\n";
  165. message += Math.round(100 * (gifposts / totalposts)) + "% gif posts\n";
  166. message += "\n\n";
  167.  
  168. message += "Schedule:\n";
  169. var daynames = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
  170. for(var d = 0; d < days.length; d++)
  171. {
  172. var daystr = daynames[d][0] + "";
  173. var daytotal = 0;
  174. for(var h = 0; h < days[d].length; h++)
  175. {
  176. if(days[d][h] === 0)
  177. daystr += "▁";
  178. else if(days[d][h] > 0 && days[d][h] <= 2)
  179. daystr += "▃";
  180. else if(days[d][h] > 2 && days[d][h] <= 6)
  181. daystr += "▅";
  182. else if(days[d][h] > 6)
  183. daystr += "█";
  184. daytotal += days[d][h];
  185. }
  186. daystr += "\n";
  187. message += daystr;
  188. }
  189. message += "\n\n";
  190.  
  191. message += "Avg Score: " + Math.round(votetotal/regularposts) + " per " + regularposts + " posts\n\n";
  192.  
  193. var sorttags = [];
  194. for(var t in tags)
  195. {
  196. sorttags.push({tag:t, count:tags[t]});
  197. }
  198. if(sorttags.length > 0)
  199. {
  200. message += "Top Tags:\n";
  201. sorttags.sort(sortobjs);
  202. for(var tt = 0; tt < Math.min(sorttags.length,5); tt++)
  203. {
  204. message += sorttags[tt].tag + ": " + sorttags[tt].count + "\n";
  205. }
  206. }
  207.  
  208. message += "\n";
  209.  
  210. var sortmentions = [];
  211. for(var a in ats)
  212. {
  213. sortmentions.push({at:a, count:ats[a]});
  214. }
  215. if(sortmentions.length > 0)
  216. {
  217. message += "Top Mentions:\n";
  218. sortmentions.sort(sortobjs);
  219. for(var aa = 0; aa < Math.min(sortmentions.length,10); aa++)
  220. {
  221. message += sortmentions[aa].at + ": " + sortmentions[aa].count + "\n";
  222. }
  223. }
  224.  
  225. alert(message);
  226. });
  227. var styling = "float: right; display: inline-block; background: #e14283; color: white; padding: 5px 20px; text-transform: uppercase; letter-spacing: 3px; margin-top: 5px; margin-right: 10px; border-radius: 3px; text-decoration: none; -webkit-transition: background .2s, opacity .2s; transition: background .2s, opacity .2s;";
  228. $(btndiv).html('<a style="position:fixed; bottom:10px; right:10px; ' +styling + '" href="#" class="composer__content__button"><span>Profile User</span></a>');
  229. $(document.body).append(btndiv);
  230. });
  231.  
  232. function sortobjs(a,b) {
  233. if (a.count > b.count)
  234. return -1;
  235. if (a.count < b.count)
  236. return 1;
  237. return 0;
  238. }