yurikhan: (Default)
[personal profile] yurikhan

В каких-то темах оформления ЖЖ есть пометка непрочитанных комментариев жёлтой плашкой. В моей — нет. А я предпочитаю чужие журналы читать в своей теме (потому что у всех слишком мелко и/или слишком ярко).

Поэтому написал себе скриптик для Greasemonkey, добавляющий аналогичную функциональность.

Тестировалось на Firefox 35.0.1; LJ схема Lynx (light), тема Cuteness Attack; DW схема Lynx (light mode), тема Tabula Rasa. Для использования с другими схемами и темами может понадобиться настроить селекторы, определяющие видимость текста комментария (помечено [1]) и стили самого индикатора ([2]).

// ==UserScript==
// @name        LJ: Highlight unread comments
// @namespace   http://yurikhan.dreamwidth.org/
// @include     http://*.livejournal.com/*.html
// @include     http://*.livejournal.com/*.html?*
// @include     http://*.dreamwidth.org/*.html
// @include     http://*.dreamwidth.org/*.html?*
// @version     1
// @require     https://gist.githubusercontent.com/arantius/3123124/raw/grant-none-shim.js
// @grant       GM_registerMenuCommand
// ==/UserScript==

const observerOptions = {childList: true, subtree: true};

function highlightUnread(mutations, observer)
{
  observer.disconnect();

  var allComments = Array.prototype.slice.call(document.querySelectorAll('[id^=ljcmt], [id^=cmt]'));

  (allComments
   .filter(function(comment) { return !GM_getValue(comment.id, false); })
   .forEach(function(comment) { comment.classList.add('yk-unread'); }));
  (allComments
   .filter(function(comment) { return comment.querySelector('.entry-item, .full') !== null; }) // [1]
   .forEach(function(comment) { GM_setValue(comment.id, true); }));
  
  observer.observe(document.body, observerOptions);
}

GM_addStyle(
  [['.yk-unread .comment-info .ljuser:after', // [2]
    '.yk-unread [id=comment-info] .ljuser:after',
    '.yk-unread[id^=cmt] .full .poster:after',
    '.yk-unread[id^=cmt] .partial .comment > .inner:after',
    '.yk-unread [id^=expand]:after'
   ].join(',\n'),
   '{',
   '  margin-left: 0.25em; border-radius: 0.25em; padding: 0em 0.25em;',
   '  background-color: #edd400; color: white;',
   '  font-size: smaller; font-weight: bold; content: "new";',
   '}'].join('\n'));

var observer = new MutationObserver(highlightUnread);
highlightUnread([], observer);

GM_registerMenuCommand('Mark all unread', function() {
  if (confirm('Mark all comments in ' + location.hostname + ' as read?')) {
    GM_listValues().forEach(GM_deleteValue);
  }
}, 'u')
(will be screened)
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

yurikhan: (Default)
Yuri Khan

August 2018

S M T W T F S
   1234
567891011
12131415161718
19202122232425
26 2728293031 

Links

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated 2025-06-25 20:03
Powered by Dreamwidth Studios