Greasy Fork 支持简体中文。

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.

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