nijie ajax bookmark and favorite command

nijieでブックマークとユーザーのお気に入り登録をページ遷移なく行う(nijie ajax bookmark and favorite)

  1. // ==UserScript==
  2. // @name nijie ajax bookmark and favorite command
  3. // @namespace qa3
  4. // @version 0.2
  5. // @description nijieでブックマークとユーザーのお気に入り登録をページ遷移なく行う(nijie ajax bookmark and favorite)
  6. // @include https://nijie.info/*
  7. // @include http://nijie.info*
  8. // @author qa3
  9. // @copyright 2014+, qa
  10. // ==/UserScript==
  11.  
  12. /*
  13. 参考
  14. char code list: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
  15. */
  16.  
  17. //ブックマークボタンをクリックするとajaxでブクマ
  18.  
  19. //eキーを押すとブクマする
  20.  
  21. $(window).on("keydown", function(e) {
  22. if (e.which == 69 && $("#bukuma-do")) {
  23. $(".add-bookmark").text("ブクマ編集");
  24. bkm();
  25. }
  26. });
  27.  
  28.  
  29. $("#bukuma-do").on("click", function() {
  30. bkm();
  31. });
  32.  
  33.  
  34.  
  35. // $("#not-bookmark").click(follow);
  36.  
  37. //zキーを押したらユーザーをお気に入り登録する
  38. $(window).on("keydown", function(e) {
  39. if (e.which == 90 && $("not-bookmark") != null) {
  40. follow();
  41. }
  42. });
  43.  
  44. // bookmarkする
  45. function bkm() {
  46.  
  47. $('#bukuma-do').removeAttr('href').html('Adding...');
  48.  
  49. //illustId   location.hrefから取得する
  50. illustId = location.href.match(/\?id=([0-9]+)/)[1];
  51.  
  52. var tags = '';
  53. //タグ情報のあるa要素の一番目のテキストの合計
  54. var num = $('.tag_name > a:first-child').length;
  55. //a要素の1番目のタグすべてを変数「tags」に格納していく
  56. for (i = 0; i < num ; i++) {
  57. cur = $(".tag_name > a:first-child").eq(i).text();
  58. tags += cur+' ';
  59. }
  60.  
  61. //リクエストを送る
  62. $.ajax({
  63. type:"POST",
  64. url: "https://nijie.info/bookmark_add.php",
  65. dataType:'jsonp',
  66. data: {
  67. tag: tags,
  68. id: illustId,
  69. done: function() {
  70. $('#bukuma-do')
  71. .css('background: url', '//nijie.info/pic/sprite/sprite_background.png repeat-x')
  72. .css('color', 'black')
  73. .css('background-position', '0 -1202px')
  74. .css('text-shadow', 'none')
  75. .html('ブックマークを編集');
  76. }
  77. },
  78. });
  79. }
  80.  
  81.  
  82. // ajaxでお気に入り登録
  83. function follow() {
  84. if ($("#not-bookmark")) {
  85. var url = $(".friend").attr("href");
  86. var userid = $(".name").attr("href").match(/[0-9]+/);
  87.  
  88. $.ajax({
  89. url: url,
  90. type: 'GET',
  91. data: {
  92. done: function() {
  93. $("#not-bookmark").text("登録済み");
  94. }
  95. },
  96. })
  97. }
  98. }