Pixiv Ajax Bookmark Mod

You can bookmark without going to the related pages. ページ遷移なく非同期的にブックマークします。

当前为 2018-09-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pixiv Ajax Bookmark Mod
  3. // @namespace com.SaddestPanda.net.moe
  4. // @version 2.2.0
  5. // @description You can bookmark without going to the related pages. ページ遷移なく非同期的にブックマークします。
  6. // @include http://www.pixiv.net/member_illust.php*illust_id=*
  7. // @include https://www.pixiv.net/member_illust.php*illust_id=*
  8. // @exclude http://www.pixiv.net/member*mode=manga*
  9. // @exclude https://www.pixiv.net/member*mode=manga*
  10. // @homepage https://greasyfork.org/en/scripts/22767-pixiv-ajax-bookmark-mod
  11. // @supportURL https://greasyfork.org/en/scripts/22767-pixiv-ajax-bookmark-mod/feedback
  12. // @author qa2 & SaddestPanda
  13. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js
  14. // @grant none
  15. // @run-at document-idle
  16. // @noframes
  17. // ==/UserScript==
  18.  
  19. //When you add an illustration to bookmarks also give it a like.
  20. // 1 でしたらブックマークした時、同時に「いいね!」もします。
  21. var givelike = 1;
  22.  
  23. //R18 illustrations are added as private bookmarks.
  24. // 1 でしたらイラストはR-18であった場合プライベートブックマークにします。
  25. var r18private = 1;
  26.  
  27. // If set to "1": Always add to private bookmarks list.
  28. //ブックマークする作品をいつも非公開にするかどうか 0:公開 1:非公開
  29. var bkm_restrict = 0;
  30.  
  31. //Add all tags to the bookmark.
  32. //作品に登録されているすべてのタグをブックマークタグとして追加
  33. var add_all_tags = 1;
  34.  
  35. var tags, useNewDesign = "", tagsInterval = "", TheInterval = "", resCheckerInterval = "", currLocation = "";
  36.  
  37. pageisNew();
  38.  
  39. function pageisNew() {
  40. var TheInterval = setInterval(function () { //Check if the page is using the new design.
  41. try {
  42. if (globalInitData.token != null) {
  43. useNewDesign = 1;
  44. tagsInterval = setInterval(startingUp, 125);
  45. clearInterval(TheInterval);
  46. }
  47. } catch (e) {}
  48. try {
  49. if (pixiv.context.token != null) {
  50. useNewDesign = 0;
  51. oldstartingUp();
  52. clearInterval(TheInterval);
  53. }
  54. } catch (e) {}
  55. }, 125);
  56. }
  57.  
  58. function startingUp() {
  59. tags = "";
  60. clearInterval(resCheckerInterval);
  61. resCheckerInterval = setInterval(restartChecker, 100);
  62. currLocation = document.location.href;
  63. //get all tags
  64. $("footer >").children().each(function () {
  65. try {
  66. tags += decodeURIComponent($(this).find("a")[0].href).split("&word=")[1] + " ";
  67. } catch (e) {}
  68. });
  69.  
  70. if (tags != "") {
  71. //cancel if already bookmarked
  72. if ($(".gtm-main-bookmark").length != 1) {
  73. clearInterval(tagsInterval);
  74. return;
  75. } else {
  76. //Set the button action
  77. $(".gtm-main-bookmark")[0].href = "javascript:void(0)";
  78. $(".gtm-main-bookmark").on("click", function () {
  79. bkm();
  80. return false;
  81. });
  82. //console.log(tags);
  83. clearInterval(tagsInterval);
  84. }
  85. }
  86. }
  87.  
  88. function restartChecker() {
  89. if (document.location != currLocation) {
  90. clearInterval(resCheckerInterval);
  91. var restartInterval = setInterval(restartingSoon, 100);
  92. }
  93. }
  94.  
  95. function restartingSoon() {
  96. try {
  97. if ($(".gtm-main-bookmark")[0].disabled == false) {
  98. pageisNew();
  99. }
  100. } catch (e) {}
  101. }
  102.  
  103.  
  104. // ajaxでブックマークする関数
  105. function bkm() {
  106. //var illustid = $("input[name=illust_id").val();
  107. //var tt = $("input[name=tt]").val();
  108. //var type = $("input[name=type]:eq(1)").val();
  109. //var illustid = pixiv.context.queries.id;
  110. var illustid = document.location.href.split("illust_id=")[1];
  111. var url = "https://www.pixiv.net/bookmark_add.php?id=" + illustid; //https://www.pixiv.net/bookmark_add.php?rest=show&type=illust&p=1&illust_id=70318176
  112. var tt = globalInitData.token;
  113. if (!add_all_tags) {
  114. tags = "";
  115. }
  116. //var illusttype = "illust";
  117.  
  118. try {
  119. if ($("footer >")[0].firstChild.innerText == "R-18" && r18private) {
  120. bkm_restrict = 1;
  121. }
  122. } catch (e) {}
  123.  
  124. $.ajax({
  125. url: url,
  126. type: 'POST',
  127. dataType: 'json',
  128. data: {
  129. mode: "add",
  130. tt: tt,
  131. id: illustid,
  132. from_sid: "",
  133. type: "illust",
  134. comment: "",
  135. tag: tags,
  136. restrict: bkm_restrict,
  137. success: function () {
  138. $(".gtm-main-bookmark svg")[0].style.fill = "#ff4060";
  139. $(".gtm-main-bookmark svg path")[0].style.fill = "#ff4060";
  140. $(".gtm-main-bookmark")[0].href = "https://www.pixiv.net/bookmark_add.php?type=illust&illust_id=" + illustid;
  141. $(".gtm-main-bookmark").unbind("click");
  142. $(".gtm-main-bookmark").on("click", function (e) {
  143. e.preventDefault();
  144. window.location = "https://www.pixiv.net/bookmark_add.php?type=illust&illust_id=" + illustid;
  145. return false;
  146. });
  147. }
  148. },
  149. });
  150.  
  151. if (givelike) {
  152. $(".gtm-main-bookmark").parent()[0].nextSibling.children[0].click();
  153. }
  154. }
  155.  
  156.  
  157. /////// BELOW FUNCTIONS ARE ///////
  158. /////// FOR THE OLD DESIGN ///////
  159. function oldstartingUp() {
  160. tags = "";
  161. $(".tag > .text").contents().not($('span')).each(function () {
  162. tags += $(this).text() + " ";
  163. });
  164.  
  165. $(".add-bookmark").on("click", function () {
  166. //e.preventDefault();
  167. oldbkm();
  168. return false;
  169. });
  170.  
  171. }
  172.  
  173. function oldbkm() {
  174. //var illustid = $("input[name=illust_id").val();
  175. //var tt = $("input[name=tt]").val();
  176. //var type = $("input[name=type]:eq(1)").val();
  177. var illustid = pixiv.context.illustId;
  178. var url = "https://www.pixiv.net/bookmark_add.php?id=" + illustid;
  179. var tt = pixiv.context.token;
  180. var type = pixiv.context.type;
  181.  
  182. if ($(".r-18")[0] != null && r18private) {
  183. bkm_restrict = 1;
  184. }
  185.  
  186. $.ajax({
  187. url: url,
  188. type: 'POST',
  189. dataType: 'json',
  190. data: {
  191. mode: "add",
  192. tt: tt,
  193. id: illustid,
  194. type: type,
  195. //from_sid: "",
  196. comment: "",
  197. tag: tags,
  198. restrict: bkm_restrict,
  199. success: function () {
  200. if ($(".add-bookmark").text() == "ブックマークに追加") {
  201. $(".add-bookmark").html($('<span>', {
  202. class: 'description',
  203. html: "ブックマークを編集"
  204. }));
  205. } else if ($(".add-bookmark").text() == "添加收藏") {
  206. $(".add-bookmark").html($('<span>', {
  207. class: 'description',
  208. html: "编辑收藏"
  209. }));
  210. } else {
  211. $(".add-bookmark").html($('<span>', {
  212. class: 'description',
  213. html: "Edit Bookmark"
  214. }));
  215. }
  216. $(".add-bookmark")[0].classList.add("edit-bookmark");
  217. $(".add-bookmark")[0].classList.add("bookmarked");
  218. $(".edit-bookmark")[0].classList.remove("add-bookmark");
  219. }
  220. },
  221. });
  222.  
  223. if (givelike) {
  224. $("._nice-button").trigger("click");
  225. }
  226. }