Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Dakota Free Press comments
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description tweak DFP comment section for better readability
- // @author Anonymous Coward
- // @match https://dakotafreepress.com/*
- // @grant none
- // ==/UserScript==
- ////////////////////////////////////////////////////////////////////////////
- // 1. reduce margins above & below comments
- // 2. move author after date, on same line (clickable to expand/collapse that comment)
- // 3. add background to date/author line to better deliniate comments
- // 4. automatically collapse comments by selected authors & show approx. # of lines hidden
- // (# of lines is really more like # of paragraphs; a line that wraps
- // and occupies multiple lines on screen counts as 1 line)
- ////////////////////////////////////////////////////////////////////////////
- var separator_border_style = '1px dashed #888';
- // regular expressions to match muteworthy authors
- var hide_list = [
- 'grudznick',
- 'Mike +(Lee +)?Zitterich',
- ];
- function toggle_comment(ev) {
- var comment_id = ev.currentTarget.parentNode.dataset.comment_id;
- var content_div = document.getElementById('content-' + comment_id);
- if ( content_div ) {
- var author_div = ev.currentTarget.parentNode;
- var spans = Array.from(author_div.getElementsByTagName('span'));
- var lines_span = spans[spans.length-1];
- if ( content_div.style.display == 'none' ) {
- content_div.style.display = '';
- lines_span.style.display = 'none';
- }
- else {
- content_div.style.display = 'none';
- lines_span.style.display = '';
- }
- }
- }
- (function() {
- 'use strict';
- var arts = document.getElementsByTagName('article');
- for ( var i = 0; i < arts.length; i++ ) {
- var art = arts[i];
- if ( art.id && art.id.match(/^comment-(\d+)$/) ) {
- var comment_id = RegExp.$1;
- art.dataset.comment_id = comment_id;
- art.style.margin = '0px';
- //art.style.borderTop = separator_border_style;
- art.parentNode.style.margin = '0px';
- var author_div = art.children[0];
- var content_div = art.children[1];
- var span1 = author_div.children[0];
- var span2 = author_div.children[1];
- author_div.style.background = '#eee';
- span1.className = '';
- var search_node = span1;
- if ( span1.getElementsByTagName('a').length ) {
- search_node = span1.getElementsByTagName('a')[0];
- }
- var hide_this_one = 0;
- for ( var j = 0; j < hide_list.length; j++ ) {
- var regex = RegExp('^' + hide_list[j] + '$', 'i');
- if ( search_node.innerHTML.match(regex) ) {
- hide_this_one = 1;
- break;
- }
- }
- span2.style.display = 'inline';
- span2.innerHTML += ' ';
- author_div.removeChild(span1);
- author_div.removeChild(span2);
- author_div.appendChild(span2);
- author_div.appendChild(span1);
- author_div.addEventListener('click', toggle_comment);
- author_div.style.marginTop = '1em';
- var comment_lines = content_div.innerHTML.split(/\n/);
- var span3 = document.createElement('span');
- span3.style.marginRight = '1em';
- span3.style.float = 'right';
- span3.style.display = 'none';
- if ( comment_lines.length ) {
- span3.innerHTML = ' (' + comment_lines.length + ' lines)';
- }
- author_div.appendChild(span3);
- content_div.id = 'content-' + comment_id;
- content_div.style.display = '';
- if ( hide_this_one ) {
- content_div.style.display = 'none';
- span3.style.display = '';
- }
- }
- }
- // add bright header to comments section
- document.getElementById('comments').children[0].style.background = '#f80';
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement