AH/QQ/SB/SV Find button

Jump to the last visible liked/bookmarked post on this page, button added to the navigation bar.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        AH/QQ/SB/SV Find button
// @description Jump to the last visible liked/bookmarked post on this page, button added to the navigation bar.
// @author      C89sd
// @namespace   https://greasyfork.org/users/1376767
// @version     1.2
// @match       https://*.alternatehistory.com/*
// @match       https://*.questionablequesting.com/*
// @match       https://*.spacebattles.com/*
// @match       https://*.sufficientvelocity.com/*
// @noframes
// ==/UserScript==

if (!window.location.href.includes('/threads/')) return;

const nav = document.querySelector('.p-nav-opposite');
nav.insertAdjacentHTML('afterbegin',
  '<div class="p-navgroup-link" style="cursor:pointer">Find</div>');
const btn = nav.querySelector('.p-navgroup-link');

btn.onclick = () => {
  let last;

  for (const msg of document.querySelectorAll('.message')) { // .hasThreadmark
    // bookmarks
      const list = msg.querySelectorAll('.bookmarkLink.is-bookmarked');
      if (list.length) last = list[list.length - 1];

    // SB likes
      const sb = [...msg.querySelectorAll('.actionBar-action--sv-rate')]
                   .reverse()
                   .find(n => n.textContent.trim() === 'Remove');
      if (sb) last = sb;

    // SV likes
      const sv = [...msg.querySelectorAll('.button--sv-rate')]
                   .reverse()
                   .find(n => n.textContent.trim() === 'Remove');
      if (sv) last = sv;

    // QQ / AH likes
      const list2 = msg.querySelectorAll('.reaction--1.has-reaction');
      if (list2.length) last = list2[list2.length - 1];
  }

  if (last) {
    const id = 'rand' + Math.random().toString(36).slice(2); // random id
    last.id = id;
    location.hash = '#' + id;                                // jump to it
  } else {
    btn.textContent = "None!";
  }
};