ajaxhook 接口数据拦截 油猴脚本

// ==UserScript==
// @name         CSDN博客数据接口拦截
// @namespace    http://tampermonkey.net/
// @version      0.0.1
// @description  拦截接口数据,验证极端情况下的样式展示
// @author       石小石Orz
// @match        https://mp.csdn.net/*
// @require      https://unpkg.com/ajax-hook@3.0.3/dist/ajaxhook.min.js
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  ah.proxy({
    onRequest: (config, handler) => {
      handler.next(config);
    },
    onError: (err, handler) => {
      handler.next(err);
    },
    onResponse: (response, handler) => {
       // console.info('response.config.url', typeof response.config.url)
      const url = 'https://bizapi.csdn.net/blog/phoenix/console/v1/data/get-blog-statistics-data'
      if (response.config.url === url) {
        console.info('匹配上了')
        const hookResponse = JSON.parse(response.response);

        // 伪造数据
        // hookResponse.data.allViewCount = 10000;   // 文章总数
        hookResponse.data = {
          "allViewCount": 100000,
          "yesterdayViewCount": 100000,
          "allFansCount": 998878,
          "yesterdayFansCount": 994845,
          "allFavoriteCount": 654511,
          "yesterdayFavoriteCount": 15005,
          "allOriginalArticleCount": 11235185
      }

        console.log("修改后的数据:", hookResponse);

        response.response = JSON.stringify(hookResponse);
      }
      handler.next(response);
    }

  });

})();


ref
写了个脚本,发现CSDN的前端居然如此不严谨
https://juejin.cn/post/7519005878566748186

posted @ 2025-07-11 17:38  彭成刚  阅读(58)  评论(0)    收藏  举报