Add a "Remove Notification" button to submissions

This adds a "Remove Notification" button next to the "+Fav" buttons.

  1. // ==UserScript==
  2. // @name Add a "Remove Notification" button to submissions
  3. // @namespace https://github.com/f1r3w4rr10r/fa-utils
  4. // @version 1.0.2
  5. // @description This adds a "Remove Notification" button next to the "+Fav" buttons.
  6. // @author f1r3w4rr10r
  7. // @match https://www.furaffinity.net/view/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (async function () {
  14. "use strict";
  15.  
  16. const upperFavLink = document.querySelector(".fav > a");
  17. if (!(upperFavLink instanceof HTMLAnchorElement))
  18. throw new Error(
  19. "'upperFavLink' was not an instance of 'HTMLAnchorElement'.",
  20. );
  21.  
  22. const href = upperFavLink.href;
  23. const urlMatch = href.match(/\/(?:un)?fav\/(\d+)\//);
  24. if (!urlMatch) {
  25. console.error("The fav URL did not match.", href);
  26. throw new Error("The fav URL did not match.");
  27. }
  28.  
  29. const submissionId = urlMatch[1];
  30. if (!submissionId) throw new Error("Could not extract a submission ID.");
  31.  
  32. const lowerFavLink = document.querySelector(
  33. '.favorite-nav > [href^="/fav/"], .favorite-nav > [href^="/unfav/"]',
  34. );
  35. if (!(lowerFavLink instanceof HTMLAnchorElement))
  36. throw new Error(
  37. "'lowerFavLink' was not an instance of 'HTMLAnchorElement'.",
  38. );
  39.  
  40. /**
  41. * @param {string} id the submission ID
  42. * @returns {HTMLAnchorElement}
  43. */
  44. function createNotifRemoveButton(id) {
  45. const anchor = document.createElement("a");
  46. anchor.href = "javascript:void(0)";
  47. anchor.textContent = "- S";
  48.  
  49. anchor.addEventListener("click", async () => {
  50. anchor.textContent = "⟳";
  51.  
  52. const result = await fetch("/msg/submissions/old@24/", {
  53. method: "POST",
  54. body: new URLSearchParams({
  55. "messagecenter-action": "remove_checked",
  56. "submissions[]": id,
  57. }),
  58. redirect: "manual",
  59. });
  60.  
  61. if (result.type !== "opaqueredirect") {
  62. console.error("Could not remove the submission notification.", result);
  63. anchor.textContent = "☓";
  64. }
  65.  
  66. anchor.textContent = "✓";
  67. });
  68.  
  69. return anchor;
  70. }
  71.  
  72. const upperButton = createNotifRemoveButton(submissionId);
  73.  
  74. const upperButtonDiv = document.createElement("div");
  75. upperButtonDiv.style.flexGrow = "0.5";
  76. upperButtonDiv.appendChild(upperButton);
  77.  
  78. upperFavLink.parentElement?.insertAdjacentElement("afterend", upperButtonDiv);
  79.  
  80. const lowerButton = createNotifRemoveButton(submissionId);
  81. lowerButton.className = "button standard mobile-fix";
  82.  
  83. lowerFavLink.insertAdjacentElement("afterend", lowerButton);
  84.  
  85. lowerButton.insertAdjacentText("beforebegin", " ");
  86. lowerButton.insertAdjacentText("afterend", " ");
  87. })();

QingJ © 2025

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