Pixiv quick fav

One-click fav on Pixiv

  1. // ==UserScript==
  2. // @name Pixiv quick fav
  3. // @name:zh-CN Pixiv 一键收藏
  4. // @namespace https://twitter.com/ikenaikoto
  5. // @version 1.6
  6. // @description One-click fav on Pixiv
  7. // @description:zh-cn Pixiv 一键收藏,避免烦人的页面跳转
  8. // @author fireattack
  9. // @match *://www.pixiv.net/member_illust.php?mode=medium&illust_id=*
  10. // ==/UserScript==
  11.  
  12. function urlencodeFormData(fd) { //From: https://stackoverflow.com/questions/7542586/new-formdata-application-x-www-form-urlencoded
  13. var s = '';
  14.  
  15. function encode(s) {
  16. return encodeURIComponent(s).replace(/%20/g, '+');
  17. }
  18. for (var pair of fd.entries()) {
  19. if (typeof pair[1] == 'string') {
  20. s += (s ? '&' : '') + encode(pair[0]) + '=' + encode(pair[1]);
  21. }
  22. }
  23. return s;
  24. }
  25.  
  26. var target = document.querySelector('body');
  27.  
  28. // create an observer instance
  29. var observer = new MutationObserver(function (mutations, ob) {
  30. mutations.forEach(function (mutation) {
  31. var favBtn = document.querySelector('a[href*="/bookmark_add.php"]');
  32. if (favBtn && favBtn.querySelectorAll('path')) {
  33. main(favBtn);
  34. //ob.disconnect();
  35. }
  36. });
  37. });
  38.  
  39. // configuration of the observer:
  40. var config = {
  41. attributes: true,
  42. childList: true,
  43. characterData: true,
  44. subtree: true
  45. };
  46.  
  47. // pass in the target node, as well as the observer options
  48. observer.observe(target, config);
  49.  
  50. function gradientColorChange(favBtn) {
  51. var i = 255;
  52. var j = -10;
  53. return setInterval(() => {
  54. favBtn.querySelectorAll('path')[1].style.fill = `rgb(${i}, 64, 96`;
  55. i = i + j;
  56. if (i < 0) {
  57. i = -i;
  58. j = -j;
  59. };
  60. if (i > 255) {
  61. i = 255 - (i - 255);
  62. j = -j;
  63. }
  64. }, 30);
  65. }
  66.  
  67. function main(favBtn) {
  68. favBtn.onclick = (event) => {
  69. var color = window.getComputedStyle(favBtn.querySelectorAll('path')[0]).fill;
  70. if (color != "rgb(255, 64, 96)") {
  71. var data = new FormData();
  72. data.append('mode', 'save_illust_bookmark');
  73. data.append('illust_id', window.location.href.match(/id=(\d+)/)[1]);
  74. data.append('restrict', '0');
  75. data.append('comment', '');
  76. data.append('tags', '');
  77. data.append('tt', globalInitData.token);
  78. data = urlencodeFormData(data);
  79.  
  80. var xhr = new XMLHttpRequest();
  81. xhr.open('POST', '/rpc/index.php', true);
  82. xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
  83. xhr.onload = () => {
  84. var jsonResponse = JSON.parse(xhr.responseText);
  85. if (jsonResponse.error) {
  86. console.log('Bookmark error!');
  87. } else {
  88. clearInterval(t);
  89. favBtn.querySelectorAll('path')[0].style.fill = 'rgb(255, 64, 96)';
  90. favBtn.querySelectorAll('path')[1].style.fill = 'rgb(255, 64, 96)';
  91. }
  92. };
  93. xhr.send(data);
  94. t = gradientColorChange(favBtn);
  95. event.preventDefault();
  96. }
  97. }
  98. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址