Minds UI Improvements

Shows comments on the right hand side of the page.

  1. // ==UserScript==
  2. // @name Minds UI Improvements
  3. // @namespace http://www.minds.com/
  4. // @version 0.8
  5. // @description Shows comments on the right hand side of the page.
  6. // @author You
  7. // @match https://www.minds.com/newsfeed/*
  8. // @grant none
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
  10. // ==/UserScript==
  11.  
  12. function addGlobalStyle(css) {
  13. var head, style;
  14. head = document.getElementsByTagName('head')[0];
  15. if (!head) { return; }
  16. style = document.createElement('style');
  17. style.type = 'text/css';
  18. style.innerHTML = css;
  19. head.appendChild(style);
  20. }
  21.  
  22. addGlobalStyle(`
  23. .myp {
  24. padding: 5px;
  25. background: #FFFFFF;
  26. border-radius: 3px;
  27. width: 100%;
  28. display: flex;
  29. margin-bottom: 10px;
  30. word-break: break-word;
  31. border: 1px solid #e8e8e8;
  32. }
  33. .tagged {
  34. border: 1px solid #e8e8e8;
  35. width: 100%;
  36. padding: 5px;
  37. border-radius: 3px;
  38. background: #EEEEFF;
  39. }
  40. .mytime {
  41. margin-right: 5px;
  42. color: #4690df;
  43. font-style: normal;
  44. font-size: .8em;
  45. }
  46. .myimg {
  47. max-width: 40%;
  48. max-height: 100px;
  49. margin: 0px;
  50. margin-right: 15px;
  51. border-radius: 3px;
  52. }
  53. .mya {
  54. text-decoration: none;
  55. }
  56. .m-newsfeed--boost-sidebar {
  57. max-width: initial !important;
  58. right: 50px !important;
  59. width: 45%;
  60. }
  61. .m-newsfeed--feed {
  62. margin-left: 20px !important;
  63. width: 50% !important;
  64. }
  65. .m-newsfeed--sidebar,
  66. .m-boost-rotator-item,
  67. .m-boost-console-link,
  68. .m-boost-rotator-tools
  69. {
  70. display: none !important;
  71. }
  72. `);
  73.  
  74. function formatComment(n) {
  75. console.log(n)
  76.  
  77. let title = n.entity.title;
  78. if (title === false) {
  79. title = n.entity.message;
  80. }
  81. if (title === false && n.entity.remind_object !== undefined) {
  82. title = n.entity.remind_object.message;
  83. }
  84. if (title === "") {
  85. title = "[empty]";
  86. }
  87.  
  88. let img = n.entity.thumbnail_src;
  89. if ((img == false || img == undefined) && n.entity.custom_data !== false) {
  90. img = n.entity.custom_data[0].src;
  91. }
  92. if ((img == false || img == undefined) && n.entity.remind_object !== undefined) {
  93. img = n.entity.remind_object.thumbnail_src;
  94. }
  95.  
  96. let ret = '<i class="mytime">' + getTime(n) + '</i> ' +
  97. '<a class="mya" target="_blank" href="https://www.minds.com/' + n.from.username + '">' + n.from.username + '</a>' +
  98. ' on ' +
  99. '<a class="mya" target="_blank" href="https://www.minds.com/newsfeed/' + n.entity.guid + '">' + title + '</a>' +
  100. '<p class="myp">';
  101. console.log(img);
  102. if (img !== false && img !== undefined) {
  103. img = encodeURI(img);
  104. ret += '<img class="myimg" src="https://cdn.minds.com/api/v2/media/proxy?src=' + img + '">';
  105. }
  106. if (n.description !== false) {
  107. ret += n.description;
  108. }
  109. ret += '</p>';
  110.  
  111. return ret;
  112. }
  113.  
  114. function formatGroupActivity(n) {
  115. let img = n.entity.thumbnail_src;
  116. if (img == false && n.entity.custom_data[0] !== undefined) {
  117. img = n.entity.custom_data[0].src;
  118. }
  119.  
  120. let ret = '<i class="mytime">' + getTime(n) + '</i> ' +
  121. '<a class="mya" target="_blank" href="https://www.minds.com/' + n.from.username + '">' + n.from.username + '</a>' +
  122. ' in group ' +
  123. '<a class="mya" target="_blank" href="https://www.minds.com/newsfeed/' + n.entity.guid + '">' + n.params.group.name + '</a>' +
  124. '<p class="myp">';
  125.  
  126. if (img !== false) {
  127. ret += '<img class="myimg" src="' + img + '">';
  128. }
  129. if (n.description !== false) {
  130. ret += n.description;
  131. }
  132. ret += '</p>';
  133.  
  134. return ret;
  135. }
  136.  
  137. function formatTag(n) {
  138. let description = n.entity.description;
  139. if (description == false || description == undefined) {
  140. description = n.description;
  141. }
  142. let guid = n.entity.parent_guid;
  143. if (guid == false || guid == undefined) {
  144. guid = n.entity.guid;
  145. }
  146. let ret = '<i class="mytime">' + getTime(n) + '</i> ' +
  147. '<a class="mya" target="_blank" href="https://www.minds.com/' + n.from.username + '">' + n.from.username + '</a> ' +
  148. '<a class="mya" target="_blank" href="https://www.minds.com/newsfeed/' + guid + '">tagged you</a>' +
  149. '<p class="tagged">' +
  150. description +
  151. '</p>';
  152. return ret;
  153. }
  154.  
  155. function getTime(n) {
  156. let time = new Date(n.time_created * 1000);
  157. let options = {
  158. year: 'numeric',
  159. month: 'numeric',
  160. day: 'numeric',
  161. hour: 'numeric',
  162. minute: 'numeric',
  163. second: 'numeric'
  164. };
  165. return time.toLocaleDateString("en-US", options);
  166. }
  167.  
  168. function showNotifications() {
  169. getNotifications(function(response) {
  170. let target = $('.m-newsfeed--boost-sidebar')[0];
  171. target.innerHTML = "";
  172. let nn = response.notifications;
  173. for (var i = 0; i < nn.length; i++) {
  174. var n = nn[i];
  175.  
  176. if (n.notification_view === "group_activity") {
  177. target.innerHTML += formatGroupActivity(n);
  178. } else
  179. if (n.notification_view === "comment") {
  180. target.innerHTML += formatComment(n);
  181. } else
  182. if (n.notification_view === "tag") {
  183. target.innerHTML += formatTag(n);
  184. } else {
  185. //console.log(n);
  186. }
  187. }
  188. });
  189. }
  190.  
  191. function getNotifications(callback) {
  192. return http('GET', 'api/v1/notifications/all?limit=100', null, callback);
  193. }
  194.  
  195. function getCookie(name) {
  196. var value = "; " + document.cookie;
  197. var parts = value.split("; " + name + "=");
  198. if (parts.length == 2) {
  199. return parts.pop().split(";").shift();
  200. }
  201. }
  202.  
  203. function http(method, url, payload, callback) {
  204. $.ajax({
  205. method: method,
  206. url: url,
  207. headers: {
  208. 'x-xsrf-token': getCookie('XSRF-TOKEN')
  209. }
  210. })
  211. .done(function(ret) {
  212. callback(ret);
  213. });
  214. }
  215.  
  216. showNotifications();
  217. setInterval(showNotifications, 5 * 1000);