pixiv ajax bookmark and follow

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

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

  1. // ==UserScript==
  2. // @name pixiv ajax bookmark and follow
  3. // @namespace
  4. // @version 0.5
  5. // @description ブックマークとお気に入り登録をページ遷移なく非同期的に行います。
  6. // @include http://www.pixiv.net/member_illust.php*
  7. // @include http://www.pixiv.net/member.php?*
  8. // @copyright 2014+, qa2
  9. // @author qa2
  10. // ==/UserScript==
  11.  
  12. //初期設定
  13. /*
  14. 参考
  15. char code list: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
  16.  
  17. */
  18.  
  19. // bkm_restrict ブックマークする作品を非公開にするかどうか 0:公開 1:非公開
  20. var bkm_restrict = 0;
  21.  
  22. // follow_restrict フォローしたユーザーを非公開にするかどうか 0:公開 1:非公開
  23. var follow_restrict = 0;
  24.  
  25.  
  26. //eキーを押すとブクマする
  27. $(window).keydown(function(e) {
  28. if (e.which == 69) {
  29. $(".add-bookmark").text("ブクマ編集");
  30. bkm();
  31. }
  32. });
  33.  
  34.  
  35. //zキーを押したらユーザーをお気に入り登録する
  36. $(window).keydown(function(e) {
  37. if (e.which == 90) {
  38. $("#favorite-button").attr("data-text-follow", "フォロー中です");
  39. $("#favorite-button > .text").text("フォロー中です");
  40. follow();
  41. }
  42. });
  43.  
  44.  
  45. // ajaxでブックマークする関数
  46. function bkm() {
  47. var illustid = $("input[name=illust_id").val();
  48. var url = "http://www.pixiv.net/bookmark_add.php?id=" + illustid
  49. var tt = $("input[name=tt]").val();
  50. var type = $("input[name=type]:eq(1)").val();
  51. //作品に登録されているすべてのタグをブックマークタグとして追加
  52. var tags = "";
  53. $(".tag > .text").each(function() {
  54. tags += $(this).text() + " "
  55. });
  56.  
  57. $.ajax({
  58. url: url,
  59. type: 'POST',
  60. dataType: 'json',
  61. data: {
  62. mode: "add",
  63. tt: tt,
  64. id: illustid,
  65. type: type,
  66. from_id: "",
  67. comment: "",
  68. tag: tags,
  69. restrict: bkm_restrict,
  70. success: function() {
  71. $(".add-bookmark _button")
  72. .removeClass(".add-bookmark _button")
  73. .addClass(".edit-bookmark button-on")
  74. $("._button")
  75. .css("color", "#666")
  76. .css("text-shadow", "none")
  77. .css("background-color", "#f4f4e7");
  78. }
  79. },
  80. })
  81. }
  82.  
  83. // ajaxでお気に入り登録する関数
  84. function follow() {
  85. var usr_id = $(".user-link").attr("href");
  86. var usrid = usr_id.match(/\/member.php\?id=([0-9]+)/);
  87. var id = usrid[1];
  88.  
  89. var tt = $("input[name=tt]").val();
  90.  
  91. $.ajax({
  92. url: 'http://www.pixiv.net/bookmark_add.php',
  93. type: 'POST',
  94. dataType: 'json',
  95. data: {
  96. mode: "add",
  97. type: "user",
  98. user_id: id,
  99. tt: tt,
  100. from_sid: "",
  101. restrict: follow_restrict,
  102. left_column: "OK",
  103. success: function() {
  104. $("i._icon sprites-follow")
  105. .removeClass("_icon sprites-follow")
  106. .addClass("_icon sprites-follow");
  107. }
  108. },
  109. })
  110. }