pixiv ajax bookmark and follow

ブックマークとお気に入り登録をページ遷移なく非同期的に行います。

当前为 2014-09-04 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name       pixiv ajax bookmark and follow
// @namespace  
// @version    0.5
// @description  ブックマークとお気に入り登録をページ遷移なく非同期的に行います。
// @include 	http://www.pixiv.net/member_illust.php*
// @include 	http://www.pixiv.net/member.php?*
// @copyright  2014+, qa2
// @author qa2
// ==/UserScript==

//初期設定
/*
参考
 char code list: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

 */

// bkm_restrict ブックマークする作品を非公開にするかどうか 0:公開 1:非公開
var bkm_restrict = 0;

// follow_restrict フォローしたユーザーを非公開にするかどうか 0:公開 1:非公開
var follow_restrict = 0;


//eキーを押すとブクマする
$(window).keydown(function(e) {
    if (e.which == 69) {
	$(".add-bookmark").text("ブクマ編集");
        bkm();
    }
});


//zキーを押したらユーザーをお気に入り登録する
$(window).keydown(function(e) {
    if (e.which == 90) {
    		$("#favorite-button").attr("data-text-follow", "フォロー中です");
    		$("#favorite-button > .text").text("フォロー中です");
        follow();
    }
});


// ajaxでブックマークする関数
function bkm() {
  
   var illustid = $("input[name=illust_id").val();
   var url = "http://www.pixiv.net/bookmark_add.php?id=" + illustid
   var tt = $("input[name=tt]").val();
   var type = $("input[name=type]:eq(1)").val();
//作品に登録されているすべてのタグをブックマークタグとして追加
   var tags = "";
     $(".tag > .text").each(function() {
     		tags +=  $(this).text() + " "
     });

	$.ajax({
	  	url: url,
	  	type: 'POST',
	  	dataType: 'json',
	  	data: {
	  		mode: "add",
	  		tt: tt,
	  		id: illustid,
	  		type: type,
	  		from_id: "",
	  		comment: "",
	  		tag: tags,
	  		restrict: bkm_restrict,
	  		success: function() {
			  	$(".add-bookmark _button")
			  	.removeClass(".add-bookmark _button")
			  	.addClass(".edit-bookmark button-on")
			  	$("._button")
			  		.css("color", "#666")
			  		.css("text-shadow", "none")
			  		.css("background-color", "#f4f4e7");
	  		}
	  	},
	  })
}

// 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 tt = $("input[name=tt]").val();

    $.ajax({
        url: 'http://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() {
	            $("i._icon sprites-follow")
	                .removeClass("_icon sprites-follow")
	                .addClass("_icon sprites-follow");
	           }
        },
    })
}