Pixiv ajax bookmark and follow mod

You can bookmark and follow without going to the related pages. ブックマークとお気に入り登録をページ遷移なく非同期的に行います。

目前為 2017-04-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name             Pixiv ajax bookmark and follow mod
// @namespace  
// @version          1.6.3
// @description      You can bookmark and follow without going to the related pages. ブックマークとお気に入り登録をページ遷移なく非同期的に行います。
// @include          http://www.pixiv.net/member_illust.php?*
// @include          http://www.pixiv.net/member.php?*
// @include          https://www.pixiv.net/member_illust.php?*
// @include          https://www.pixiv.net/member.php?*
// @copyright        2014+, qa2
// @author           qa2 & SaddestPanda
// @grant            none
// ==/UserScript==

//When you add an illustration to bookmarks also give it a like.
// 1 でしたらブックマークした時、同時に「いいね!」もします。
var givelike = 1;

//R18 illustrations are added as private bookmarks.
// 1 でしたらイラストはR-18であった場合プライベートブックマークにします。
var r18private = 1;

// If set to "1": Always add to private bookmarks list.
//ブックマークする作品をいつも非公開にするかどうか 0:公開 1:非公開
var bkm_restrict = 0;

// If set to "1": Always quick add to public follow list.
// フォローしたユーザーをいつも公開にするかどうか 0:Yes 1:No
var follow_always_public = 1;

//Add all tags to the bookmark.
//作品に登録されているすべてのタグをブックマークタグとして追加
var tags = "";
$(".tag > .text").each(function() {
  tags +=  $(this).text() + " "
});

$(".add-bookmark").click(function(e){
	//e.preventDefault();
  bkm();
  return false;
});

if (follow_always_public) {
  $(".follow").click(function(e){
    //e.preventDefault();
    follow();
    return false;
  });
} else {
  if ($(".follow").length) {
    $("#favorite-preference").find(".button").click(function(e){
      //e.preventDefault();
      follow();
      return false;
    });
  }
}


//Keybindings from the old script. Maybe you could want these.
/*    

//eキーを押すとブクマする
//press e to bookmark
$(window).keydown(function(e) {
  if (!$("input[name=word]").is(":focus") && e.which == 69) {   
    bkm();
  }
});

//press R to private bookmark
$(window).keydown(function(e) {
  if (!$("input[name=word]").is(":focus") && e.which == 82) {
    bkm_restrict = 1;
    bkm();
  }
});

//zキーを押したらユーザーをお気に入り登録する
//press z to follow
$(window).keydown(function(e) {
  if (!$("input[name=word]").is(":focus") && e.which == 90) {
    follow();
  }
});

*/

// ajaxでブックマークする関数
function bkm() {

  var illustid = $("input[name=illust_id").val();
  var url = "https://www.pixiv.net/bookmark_add.php?id=" + illustid
  var tt = $("input[name=tt]").val();
  var type = $("input[name=type]:eq(1)").val();

  if ($(".r-18")[0] != null && r18private) {
    bkm_restrict = 1;
  }
  
  $.ajax({
    url: url,
    type: 'POST',
    dataType: 'json',
    data: {
      mode: "add",
      tt: tt,
      id: illustid,
      type: type,
      from_sid: "",
      comment: "",
      tag: tags,
      restrict: bkm_restrict,
      success: function() {
        $(".edit-bookmark").unbind('click');
        if ($(".add-bookmark").text() == "ブックマークに追加") {
          $(".add-bookmark").text("ブックマークを編集");
        } else {
          $(".add-bookmark").text("Edit Bookmark");
        }
        $(".add-bookmark")[0].classList.add("bookmarked");
        $(".add-bookmark")[0].classList.add("edit-bookmark");
        $(".edit-bookmark")[0].classList.remove("add-bookmark");
      }
    },
  })

  if (givelike) {
    $("._nice-button").click();
  }
}

// ajaxでお気に入り登録する関数
function follow() {
    var usr_id = $(".user-link").attr("href");
    var usrid = usr_id.match(/\/member.php\?id=([0-9]+)/);
    var id = usrid[1];
    var follow_restrict = 0;
    if (document.getElementsByName("restrict")[1].checked && !follow_always_public) {
      follow_restrict = 1; 
    }
    var tt = $("input[name=tt]").val();
    
    $.ajax({
        url: 'https://www.pixiv.net/bookmark_add.php',
        type: 'POST',
        dataType: 'json',
        data: {
            mode: "add",
            type: "user",
            user_id: id,
            tt: tt,
            from_sid: "",
            restrict: follow_restrict,
            left_column: "OK",
            success: function() {
              $("#favorite-preference")[0].remove();
              $("#favorite-button").unbind('click');
              //$("#favorite-button").attr("data-text-follow", "Following");
              if ($("#favorite-button > .text").text() == "フォローする") {
                $("#favorite-button > .text").text("フォロー中です");
              } else {
                $("#favorite-button > .text").text("Following");
              }
              $("#favorite-button")[0].classList.add("following");
              $("#favorite-button")[0].classList.remove("follow");
              $(".sprites-follow")[0].classList.add("sprites-checked");
              $(".sprites-follow")[0].classList.remove("sprites-follow");
              $("#favorite-button")[0].href = "javascript:window.location.reload(false)";
            }
        },
    })
}