Advertisement
Guest User

Dakota Free Press comment section de-unpleasant-inator

a guest
Dec 22nd, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Dakota Free Press comments
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  tweak DFP comment section for better readability
  6. // @author       Anonymous Coward
  7. // @match        https://dakotafreepress.com/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. ////////////////////////////////////////////////////////////////////////////
  12. // 1. reduce margins above & below comments
  13. // 2. move author after date, on same line (clickable to expand/collapse that comment)
  14. // 3. add background to date/author line to better deliniate comments
  15. // 4. automatically collapse comments by selected authors & show approx. # of lines hidden
  16. //    (# of lines is really more like # of paragraphs; a line that wraps
  17. //     and occupies multiple lines on screen counts as 1 line)
  18. ////////////////////////////////////////////////////////////////////////////
  19.  
  20. var separator_border_style = '1px dashed #888';
  21.  
  22. // regular expressions to match muteworthy authors
  23. var hide_list = [
  24.     'grudznick',
  25.     'Mike +(Lee +)?Zitterich',
  26. ];
  27.  
  28. function toggle_comment(ev) {
  29.     var comment_id = ev.currentTarget.parentNode.dataset.comment_id;
  30.     var content_div = document.getElementById('content-' + comment_id);
  31.     if ( content_div ) {
  32.         var author_div = ev.currentTarget.parentNode;
  33.         var spans = Array.from(author_div.getElementsByTagName('span'));
  34.         var lines_span = spans[spans.length-1];
  35.         if ( content_div.style.display == 'none' ) {
  36.             content_div.style.display = '';
  37.             lines_span.style.display = 'none';
  38.         }
  39.         else {
  40.             content_div.style.display = 'none';
  41.             lines_span.style.display = '';
  42.         }
  43.     }
  44. }
  45.  
  46. (function() {
  47.     'use strict';
  48.  
  49.     var arts = document.getElementsByTagName('article');
  50.     for ( var i = 0; i < arts.length; i++ ) {
  51.         var art = arts[i];
  52.         if ( art.id && art.id.match(/^comment-(\d+)$/) ) {
  53.             var comment_id = RegExp.$1;
  54.             art.dataset.comment_id = comment_id;
  55.             art.style.margin = '0px';
  56.             //art.style.borderTop = separator_border_style;
  57.             art.parentNode.style.margin = '0px';
  58.             var author_div = art.children[0];
  59.             var content_div = art.children[1];
  60.             var span1 = author_div.children[0];
  61.             var span2 = author_div.children[1];
  62.             author_div.style.background = '#eee';
  63.             span1.className = '';
  64.             var search_node = span1;
  65.             if ( span1.getElementsByTagName('a').length ) {
  66.                 search_node = span1.getElementsByTagName('a')[0];
  67.             }
  68.             var hide_this_one = 0;
  69.             for ( var j = 0; j < hide_list.length; j++ ) {
  70.                 var regex = RegExp('^' + hide_list[j] + '$', 'i');
  71.                 if ( search_node.innerHTML.match(regex) ) {
  72.                     hide_this_one = 1;
  73.                     break;
  74.                 }
  75.             }
  76.             span2.style.display = 'inline';
  77.             span2.innerHTML += '&nbsp;&nbsp;';
  78.             author_div.removeChild(span1);
  79.             author_div.removeChild(span2);
  80.             author_div.appendChild(span2);
  81.             author_div.appendChild(span1);
  82.             author_div.addEventListener('click', toggle_comment);
  83.             author_div.style.marginTop = '1em';
  84.             var comment_lines = content_div.innerHTML.split(/\n/);
  85.             var span3 = document.createElement('span');
  86.             span3.style.marginRight = '1em';
  87.             span3.style.float = 'right';
  88.             span3.style.display = 'none';
  89.             if ( comment_lines.length ) {
  90.                 span3.innerHTML = ' (' + comment_lines.length + ' lines)';
  91.             }
  92.             author_div.appendChild(span3);
  93.             content_div.id = 'content-' + comment_id;
  94.             content_div.style.display = '';
  95.             if ( hide_this_one ) {
  96.                 content_div.style.display = 'none';
  97.                 span3.style.display = '';
  98.             }
  99.         }
  100.     }
  101.  
  102.     // add bright header to comments section
  103.     document.getElementById('comments').children[0].style.background = '#f80';
  104. })();
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement