Fresh Lobsters

Highlights fresh comments on Lobste.rs.

目前為 2016-12-01 提交的版本,檢視 最新版本

// ==UserScript==
// @name          Fresh Lobsters
// @version       0.0.1
// @namespace     http://userscripts.psbarrett.com
// @description	  Highlights fresh comments on Lobste.rs.
// @include       https://lobste.rs/*
// @grant         GM_addStyle
// ==/UserScript==
'use strict'

GM_addStyle(
`
.byline.fresh-item > span,
.byline a.fresh-item {
  color:red;
}
`);

function get_comment_id(byline) {
  let a = byline.querySelector('a');
  return a.name;
}

function get_comment_time(byline) {
  let item_link_ele = byline.querySelector('span');
  return item_link_ele.title;
}

//
// Comments
//
let all_byline = document.querySelectorAll('.comment .byline');

for (let byline of all_byline) {
  let comment_id = get_comment_id(byline);
  let comment_time = get_comment_time(byline);
  
  if (comment_id !== null && comment_time !== null) {
    var status = localStorage.getItem(comment_id)

    if (status === null || comment_time !== status) {
      byline.classList.add("fresh-item");
      localStorage.setItem(comment_id, comment_time);
    }
  }
}

//
// Comment Links
//
let stories = document.querySelectorAll('.stories li')

for (let story of stories) {
  let story_id = story.dataset.shortid;
  let comment_link = story.querySelector('.byline .comments_label a');
  let story_comment_count = comment_link.textContent.trim().split(" ")[0].trim();
  
  console.log(story_id);
  
  if (story_id !== null && story_comment_count !== null && story_comment_count !== 'no') {
    var status = localStorage.getItem(story_id)

    if (status !== null && story_comment_count !== status) {
      comment_link.classList.add("fresh-item");
      
      if (stories.length == 1) { // is story page
        localStorage.setItem(story_id, story_comment_count);
      }
    }
  }
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址