nijienhance

nijie ajax bookmark 412305

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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)
  })
})()