Compact View on Ed Discussions

Reduces amount of space used by each post tile in the list view, by compacting each post to a single line on Ed discussion forum. Also reduces some whitespace in messages panel.

当前为 2021-08-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Compact View on Ed Discussions
  3. // @namespace waqas
  4. // @description Reduces amount of space used by each post tile in the list view, by compacting each post to a single line on Ed discussion forum. Also reduces some whitespace in messages panel.
  5. // @match *://edstem.org/*
  6. // @grant GM_addStyle
  7. // @version 0.1
  8. // @author Waqas Ilyas
  9. // @require http://code.jquery.com/jquery-latest.js
  10. // @run-at document-start
  11. // @licence MIT
  12. // jshint esversion: 6
  13. // ==/UserScript==
  14. (function() {
  15. 'use strict';
  16. GM_addStyle(`
  17. .split-divider-wi {
  18. padding-left: 0.5px;
  19. }
  20.  
  21. .discuss-feed-thread-wi {
  22. padding: 2px !important;
  23. }
  24.  
  25. .dft-body-wi {
  26. margin: 2px !important;
  27. padding: 0 5px 0 20px !important;
  28. }
  29.  
  30. .dft-body-unseen-wi {
  31. font-weight: bold !important;
  32. padding: 0 5px 0 5px !important;
  33. }
  34.  
  35. .dft-category-wi {
  36. margin: 0 2px 0 2px;
  37. }
  38.  
  39. .dft-author-wi {
  40. font-size: 70% !important;
  41. width: 2em;
  42. text-align: center;
  43. background-color: #eee;
  44. padding: 0 2px 0 2px;
  45. margin: 0 2px 0 2px;
  46. }
  47.  
  48. .discuss-show-full-wi {
  49. max-width: 90% !important;
  50. }
  51.  
  52. .dft-thread-count-new-wi {
  53. font-size: 70% !important;
  54. }
  55. `);
  56. var initialWidthSet = false;
  57. $(window).load(function() {
  58. var MutationObserver = window.MutationObserver;
  59. var myObserver = new MutationObserver (applyUpdates);
  60. var obsConfig = {
  61. childList: true, attributes: true,
  62. subtree: true, attributeFilter: ['class']
  63. };
  64.  
  65. myObserver.observe (document, obsConfig);
  66. });
  67.  
  68. function applyUpdates() {
  69. var selector = $('.split-divider');
  70. if (selector.length == 0)
  71. // HTML of our interest not available yet
  72. return;
  73. selector.addClass('split-divider-wi');
  74.  
  75. // Allow wider threads panel
  76. if (!initialWidthSet) {
  77. initialWidthSet = true;
  78. var threadsPanel = $('section.dif-tf-container').get(0);
  79. threadsPanel.parentElement.style = "flex: 0 0 650px";
  80. }
  81.  
  82. // Compact post tiles in the list
  83. selector = $('a.discuss-feed-thread');
  84. if (selector.length > 0)
  85. selector.addClass('discuss-feed-thread-wi');
  86.  
  87. // Hide all the footers, we will accomadate useful information into dft-body
  88. selector = $('a.discuss-feed-thread footer');
  89. if (selector.length > 0)
  90. selector.hide();
  91.  
  92. // Selector for post tiles, compact even more
  93. var dftBodySelector = $('a.discuss-feed-thread .dft-body');
  94. if (dftBodySelector.length > 0)
  95. dftBodySelector.addClass('dft-body-wi');
  96.  
  97. // Make changes to each tile
  98. dftBodySelector.each(function(i, o) {
  99. var dftBody = $(o);
  100.  
  101. // Adjust padding so that unread and read posts are aligned
  102. var unseenIcons = dftBody.find('.dft-thread-unseen-icon');
  103. if (unseenIcons.length > 0)
  104. dftBody.addClass('dft-body-unseen-wi');
  105. else
  106. dftBody.removeClass('dft-body-unseen-wi');
  107.  
  108. // Check if the post is from an instructor
  109. var footer = dftBody.parent().find('footer');
  110. // Number of new unread messages
  111. var newRepliesSpan = footer.find('.dft-thread-count > span.dft-thread-count-new');
  112. if (newRepliesSpan.length > 0) {
  113. console.log(newRepliesSpan.children().length);
  114. if (dftBody.find('.dft-thread-count-new').length == 0)
  115. dftBody.find('.dft-thread-title').after(`
  116. <span title="New Replies" class="dft-thread-count-new dft-thread-count-new-wi">
  117. ${newRepliesSpan.html()}
  118. </span>
  119. `);
  120. }
  121.  
  122. // Author name
  123. var authorSpan = footer.find('.dft-foot-fill > span.dft-thread-user');
  124.  
  125. // Handle author's role
  126. var roleDiv = footer.find('.dft-foot-fill > div.user-role-label');
  127. if (dftBody.find('span.dft-author-wi').length == 0) {
  128. var role = 'S';
  129. var roleClass = 'url-student';
  130. if (roleDiv.hasClass('url-admin')) {
  131. role = 'I';
  132. roleClass = 'url-admin';
  133. }
  134.  
  135. // Add an author tag, with initials
  136. dftBody.append(`
  137. <span title='${authorSpan.html()}' class='dft-author-wi ${roleClass}'>
  138. ${authorSpan.html().split(' ').map((n) => n[0]).slice(0, 3).join('')}
  139. </span>
  140. `);
  141. }
  142.  
  143. // Handle category, add a tag for it
  144. var catDiv = footer.find('.dft-foot-fill > .dft-thread-category-group');
  145. var catColor = catDiv.get(0).style.color;
  146. var catSpan = footer.find('.dft-foot-fill > .dft-thread-category-group > span');
  147. var category = catSpan.html();
  148. if (dftBody.find('span.dft-category-wi').length == 0)
  149. dftBody.append(`
  150. <span title='${category}'
  151. class='discuss-category-tag dsb-category-tag dft-category-wi'
  152. style='background-color: ${catColor}'></span>
  153. `);
  154. // Post body, reduce whitespace
  155. $('.discuss-show-full').addClass('discuss-show-full-wi');
  156. });
  157. }
  158. })();