Cursor-Sheerid-Bypass

拦截指定 Fetch 请求并修改URL中的 country=XXX 为 CN

  1. // ==UserScript==
  2. // @name Cursor-Sheerid-Bypass
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description 拦截指定 Fetch 请求并修改URL中的 country=XXX 为 CN
  6. // @author ZAMBAR
  7. // @match https://services.sheerid.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. const originalFetch = window.fetch;
  17.  
  18. const modifyCountryParam = (url) => {
  19. if (typeof url !== 'string') return url;
  20. const urlObj = new URL(url, location.origin);
  21. if (urlObj.searchParams.has('country')) {
  22. urlObj.searchParams.set('country', 'CN');
  23. return urlObj.toString();
  24. }
  25. return url;
  26. };
  27.  
  28. window.fetch = function (input, init) {
  29. if (typeof input === 'string' && input.includes("orgsearch.sheerid.net/rest/organization/search")) {
  30. console.log("Got input:", input);
  31. input = modifyCountryParam(input);
  32. console.log("Modified to:", input);
  33. } else if (input instanceof Request) {
  34. const url = input.url;
  35. if (url.includes("orgsearch.sheerid.net/rest/organization/search")) {
  36. console.log("Got fetch:", url);
  37. const newUrl = modifyCountryParam(url);
  38. console.log("Modified to:", newUrl);
  39.  
  40. // Clone
  41. const newRequest = new Request(newUrl, {
  42. method: input.method,
  43. headers: input.headers,
  44. body: input.body,
  45. mode: input.mode,
  46. credentials: input.credentials,
  47. cache: input.cache,
  48. redirect: input.redirect,
  49. referrer: input.referrer,
  50. integrity: input.integrity,
  51. keepalive: input.keepalive,
  52. signal: input.signal
  53. });
  54. return originalFetch.call(this, newRequest, init);
  55. }
  56. }
  57. return originalFetch.call(this, input, init);
  58. };
  59. })();