nijienhance

nijie ajax bookmark 412305

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         nijienhance
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  nijie ajax bookmark 412305
// @author       nijietan
// @match        https://nijie.info/*
// @match        https://sp.nijie.info/*
// @icon         https://www.google.com/s2/favicons?domain=nijie.info
// @grant        none
// @license      MIT
// ==/UserScript==

;(function () {
  "use strict"
  console.log("running nijienhance")
  // sp のブックマークを fetch にする
  document
    .querySelectorAll('#bookmark_button > a[href^="bookmark_add.php"]')
    .forEach((elem) => {
      elem.removeAttribute("onclick")
      const handleBookmarkButton = (e) => {
        e.preventDefault()
        if (!confirm("[ajax] ブックマークに追加してもよろしいですか?")) return

        fetch(elem.href, {
          headers: {
            "cache-control": "no-cache",
          },
          referrer: location.href,
          referrerPolicy: "same-origin",
          method: "GET",
          credentials: "include",
        }).then((r) => {
          if (r.ok) {
            elem.href = elem.href.replace("add", "edit")
            elem.removeEventListener("click", handleBookmarkButton)
            const bookmark = elem.querySelector("#bookmark")
            if (bookmark) {
              bookmark.id = "bookmark_edit"
            }
          } else {
            alert("ブックマークの追加に失敗しました")
          }
        })
      }
      elem.addEventListener("click", handleBookmarkButton)
      console.log("applied", elem)
    })
  // pc のブックマークを fetch にする
  document.querySelectorAll('a[href^="/bookmark.php"]').forEach((elem) => {
    const url = new URL(elem.href)
    const _id = url.searchParams.get("id")
    if (!_id) return

    const handleBookmarkButton = (e) => {
      e.preventDefault()
      const bukumafolder = prompt("ブクマフォルダーを指定")
      if (bukumafolder === null) return
      fetch("https://nijie.info/bookmark_add.php", {
        headers: {
          "cache-control": "max-age=0",
          "content-type": "application/x-www-form-urlencoded",
        },
        referrer: location.href,
        referrerPolicy: "same-origin",
        body: `tag=${bukumafolder}&id=${_id}`,
        method: "POST",
        credentials: "include",
      }).then((r) => {
        if (r.ok) {
          elem.id = "bukuma"
          elem.href = elem.href.replace("add", "edit")
          elem.removeEventListener("click", handleBookmarkButton)
        } else {
          alert("ブックマークの追加に失敗しました")
        }
      })
    }
    elem.addEventListener("click", handleBookmarkButton)
    console.log("applied", elem)
  })
})()