FANBOX直转KEMONO

在创作者的FANBOX页面生成一个‘在KEMONO中打开’的按钮

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
  1. // ==UserScript==
  2. // @name FANBOX直转KEMONO
  3. // @namespace https://greasyfork.org/zh-CN/users/325815-monat151
  4. // @version 1.0.2
  5. // @description 在创作者的FANBOX页面生成一个‘在KEMONO中打开’的按钮
  6. // @author monat151
  7. // @match http*://*.fanbox.cc
  8. // @match http*://www.fanbox.cc/@*
  9. // @match http*://*.fanbox.cc/posts*
  10. // @match http*://*.fanbox.cc/plans*
  11. // @match http*://www.pixiv.net/fanbox/creator/*
  12. // @icon https://www.google.com/s2/favicons?sz=64&domain=fanbox.cc
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. const _CONFIG_MAX_RETRY_TIME = 30
  18. const _CONFIG_RETRY_INTERVAL = 100
  19. 'use strict';
  20. let retry_times = 0
  21. const generateKemonoButton = () => {
  22. const retry = () => {
  23. if (retry_times < _CONFIG_MAX_RETRY_TIME) {
  24. setTimeout(() => {
  25. console.warn('生成失败.即将重试...')
  26. generateKemonoButton()
  27. retry_times++
  28. }, _CONFIG_RETRY_INTERVAL)
  29. } else {
  30. console.error('生成失败并达到了最大重试次数。')
  31. }
  32. }
  33.  
  34. try {
  35. const creatorId = getCreatorId()
  36. if (!creatorId) retry()
  37. else {
  38. const pageTabs = document.getElementsByClassName('TabList__Wrapper-sc-kqugtg-0 eYVlDP')[0]
  39. const tabCount = pageTabs.children.length
  40. const tabClass = document.location.href.match('posts') ? 'InnerTab__Tab-sc-vy9p7q-0 jzsgph'
  41. : document.location.href.match('plans') ? 'InnerTab__Tab-sc-vy9p7q-0 ifbxDI' : 'InnerTab__Tab-sc-vy9p7q-0 bngNqu'
  42. let kemonoNode = document.createElement('a')
  43. kemonoNode.href = 'https://kemono.su/fanbox/user/' + creatorId
  44. kemonoNode.innerHTML = `<div class="${tabClass}">在KEMONO中打开</div>`
  45. pageTabs.children[tabCount-2].after(kemonoNode)
  46. console.log('生成成功!')
  47. }
  48. } catch (err) {
  49. console.error(err)
  50. retry()
  51. }
  52. }
  53. const getCreatorId = () => {
  54. const urlRegex = /(?<=creator\/)\d+/g;
  55. const backImgRegex = /(?<=creator\/)\d+(?=\/cover)/g;
  56. if (document.location.href.match(urlRegex)) { // https://www.pixiv.net/fanbox/creator/16051830
  57. return document.location.href.match(urlRegex)[0]
  58. } else if (document.body.innerHTML.match(backImgRegex)) {
  59. return document.body.innerHTML.match(backImgRegex)[0]
  60. } else {
  61. return null
  62. }
  63. }
  64.  
  65. setTimeout(() => {
  66. generateKemonoButton()
  67. }, 500);
  68. })();