Thumblr Seen

Marks posts already seen on thumblr

目前為 2017-12-15 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            Thumblr Seen
// @name:en         Thumblr Seen
// @namespace       https://gitlab.com/xaxim
// @version         0.2.0
// @description:en  Marks posts already seen on thumblr
// @author          Xaxim
// @match           https://www.tumblr.com/dashboard
// @match           https://www.tumblr.com/dashboard/*
// @grant           none
// @require         https://cdnjs.cloudflare.com/ajax/libs/lockr/0.8.4/lockr.min.js
// @description     Marks posts already seen on thumblr
// ==/UserScript==

Lockr.prefix = "thumblrseen_";
const seenPosfix = "seen";

measurePerformance(markAlreadySeenPosts);

function measurePerformance(fn) {
  console.clear();
  const t0 = performance.now();
  try {
    fn();
  } catch (err) {
    console.error("There was error(s)", err);
  }
  const t1 = performance.now();
  console.log(
    `thumblrseen version ${GM_info.script.version}: It took ${t1 -
      t0} milliseconds.`
  );
}

function markAlreadySeenPosts() {
  const posts = Array.from(document.querySelectorAll(".post_container"));
  posts.forEach(markAlreadySeenPost);
}

function markAlreadySeenPost(article) {
  const { pageable } = article.dataset;
  if (Lockr.sismember(seenPosfix, pageable)) {
    article.prepend(createAlreadySeen());
  } else {
    Lockr.sadd(seenPosfix, pageable);
  }
}

function createAlreadySeen() {
  const seen = document.createElement("p");
  seen.innerHTML = `<mark onClick="JSON.parse(localStorage.${Lockr.prefix}${seenPosfix}).data.map((item, i) => console.log(i,JSON.parse(item)));">ALREADY SEEN</mark>`;
  return seen;
}