FurAffinity - Seamless Fav

Fav submissions without reloading the page

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        FurAffinity - Seamless Fav
// @namespace   proot
// @match       https://www.furaffinity.net/*
// @grant       none
// @version     1.0
// @author      a proot
// @license     MIT
// @description Fav submissions without reloading the page
// ==/UserScript==

let favURLMatcher = /https?:\/\/www\.furaffinity\.net\/(?:un)?fav\//;
let favButtonMatcher = /\/(?:un)?fav\/[0-9]+/;
let favTextMatcher = /href="(\/(?:un)?fav\/.*?)">(.*?)<\/a>/;

function allFavButtons() {
  return [...document.getElementsByTagName("a")].filter(a => favButtonMatcher.exec(a.href))
}

document.addEventListener("click", function (e) {
  e = e || window.event;
  let element = e.target || e.srcElement;

  if (element.tagName == 'A' && favURLMatcher.match(element.href)) {
    (async () => {
      allFavButtons().forEach(e => {
        // e.style.opacity = 0.5
        e.style.setProperty('color', '#808080', 'important')
        e.style.pointerEvents = "none"
      })
      let r = await fetch(element.href)
      let match = favTextMatcher.exec(await r.text())
      allFavButtons().forEach(e => {
        // e.style.opacity = 1
        e.style.color = ""
        e.style.pointerEvents = ""
        e.innerText = match[2].replace(" ", "")
        e.href = match[1]
      })
    })()
    e.preventDefault()
  }
})