Greasy Fork镜像 支持简体中文。

vanyaha-bot

抓取详情

  1. // ==UserScript==
  2. // @name vanyaha-bot
  3. // @description 抓取详情
  4. // @match https://www.douban.com/*
  5. // @match https://36kr.com/*
  6. // @match https://www.skateboardchina.com/*
  7. // @require http://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
  8. // @connect https://meirixinxue.com
  9. // @connect https://xinxue.meirixinxue.com
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM_addStyle
  13. // @grant unsafeWindow
  14. // @grant GM_notification
  15. // @grant GM_xmlhttpRequest
  16. // @grant GM_registerMenuCommand
  17. // @version 1.3
  18. // @namespace vanyah
  19. // ==/UserScript==
  20.  
  21. // https://xinxue.meirixinxue.com/api/traces?api_auth_token=3d8435df-c912-4fee-a9fb-151300b9e13d
  22. // https://meirixinxue.com/api/traces?api_auth_token=3d8435df-c912-4fee-a9fb-151300b9e13d
  23.  
  24. ;(function () {
  25. 'use strict'
  26. unsafeWindow.GM_notification = GM_notification
  27. unsafeWindow.GM_xmlhttpRequest = GM_xmlhttpRequest
  28.  
  29. const href = window.location.href
  30. const apiUrl = GM_getValue('apiUrl')
  31.  
  32. const website = {
  33. douban: 'https://www.douban.com/',
  34. kr: 'https://36kr.com/',
  35. skateboardchina: 'https://www.skateboardchina.com/',
  36. }
  37.  
  38. const filterParams = () => {
  39. const api_auth_token = apiUrl.split('?api_auth_token=')[1]
  40. let params = { raw_url: href, api_auth_token }
  41. if (href.includes(website.skateboardchina)) {
  42. const title = $('.cms_title h2').text()
  43. const body = $('.detail_content').html()
  44. params = Object.assign(params, { category: 'article', title, body })
  45. }
  46. return params
  47. }
  48.  
  49. const saveData = (params) => {
  50. const api = apiUrl.split('?')[0]
  51. const data = { ...params }
  52. fetch(api, {
  53. method: 'POST',
  54. body: JSON.stringify(data),
  55. headers: new Headers({ 'Content-Type': 'application/json' }),
  56. })
  57. .then((res) => res.json())
  58. .then((res) => {
  59. unsafeWindow.GM_notification(
  60. res.error
  61. ? { title: '抓取失败', text: res.error, timeout: 30000 }
  62. : { title: '抓取成功', text: '已保存', timeout: 30000 }
  63. )
  64. })
  65. }
  66.  
  67. const addSaveBtn = () => {
  68. const body = $('body')
  69. const style =
  70. 'width:100px;height:50px;background:#f00;color:#fff;border:none;display:block;margin-left:auto'
  71. const text = `<button type="button" style=${style} id="save_data">保存</button>`
  72. body.prepend(text)
  73. $('#save_data').click(function () {
  74. const params = filterParams()
  75. saveData(params)
  76. })
  77. }
  78.  
  79. const setting = () => {
  80. GM_registerMenuCommand(`设置地址 ${apiUrl}`, () => {
  81. setTimeout(() => {
  82. const apiUrl = prompt('链接地址', 'https://xxxxx.com?api_auth_token=yyy')
  83. if (apiUrl !== null) {
  84. GM_setValue('apiUrl', apiUrl)
  85. unsafeWindow.GM_notification('设置完成', '重新刷新网页')
  86. }
  87. }, 1000)
  88. })
  89. }
  90.  
  91. setting()
  92. addSaveBtn()
  93. })()

QingJ © 2025

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