返回列表 发布新帖
查看: 206|回复: 4

Cursor Students 强制加入China油猴脚本

发表于 2025-5-7 20:30:51 来自手机 | 查看全部 |阅读模式

欢迎注册账号,享受无广告更清爽的界面!

您需要 登录 才可以下载或查看,没有账号?申请账号

×
  1. // ==UserScript==
  2. // [url=home.php?mod=space&uid=4014]@name[/url]         Cursor SheerID CN国家添加
  3. // @namespace    [url]http://tampermonkey.net/[/url]
  4. // @version      0.1
  5. // @description  将SheerID验证服务的响应中添加CN(中国)国家代码
  6. // @author       You
  7. // @match        [url]https://my.sheerid.com/[/url]*
  8. // @match        https://*.sheerid.com/*
  9. // @match        [url]https://www.cursor.com/cn/student[/url]*
  10. // @match        [url]https://www.cursor.com/cn/student-verified[/url]*
  11. // @match        [url]https://cursor.com/cn/student[/url]*
  12. // @match        [url]https://services.sheerid.com/verify/[/url]*
  13. // @run-at       document-start
  14. // @grant        none
  15. // ==/UserScript==

  16. (function() {
  17.     'use strict';

  18.     // 创建一个拦截和修改响应的函数
  19.     const originalFetch = window.fetch;
  20.     window.fetch = async function(url, options) {
  21.         const response = await originalFetch(url, options);
  22.         
  23.         // 只拦截特定的URL
  24.         if (url.includes('/rest/v2/program/681044b7729fba7beccd3565/theme') ||
  25.             url.includes('theme?locale=') ||
  26.             url.includes('/rest/v2/program/') && url.includes('/theme')) {
  27.             try {
  28.                 // 克隆响应以便修改
  29.                 const clonedResponse = response.clone();
  30.                 const responseBody = await clonedResponse.json();
  31.                
  32.                 // 检查并修改countries数组
  33.                 if (responseBody && responseBody.config && Array.isArray(responseBody.config.countries)) {
  34.                     // 检查CN是否已存在
  35.                     if (!responseBody.config.countries.includes('CN')) {
  36.                         console.log('添加CN到国家列表中...');
  37.                         // 在合适的位置添加CN,按字母顺序
  38.                         // CH和CI之间是CN的合适位置
  39.                         const chIndex = responseBody.config.countries.indexOf('CH');
  40.                         if (chIndex !== -1) {
  41.                             responseBody.config.countries.splice(chIndex + 1, 0, 'CN');
  42.                         } else {
  43.                             // 如果没找到CH,就直接添加到数组中
  44.                             responseBody.config.countries.push('CN');
  45.                         }
  46.                         
  47.                         // 添加CN对应的标签
  48.                         if (responseBody.config.orgSearchCountryTags) {
  49.                             responseBody.config.orgSearchCountryTags['CN'] = ["HEI", "qualifying_hs", "qualifying_ps"];
  50.                         }
  51.                         
  52.                         console.log('成功添加CN到国家列表');
  53.                     }
  54.                     
  55.                     // 创建一个新的响应对象
  56.                     return new Response(JSON.stringify(responseBody), {
  57.                         status: response.status,
  58.                         statusText: response.statusText,
  59.                         headers: response.headers
  60.                     });
  61.                 }
  62.             } catch (e) {
  63.                 console.error('处理fetch响应时出错:', e);
  64.                 return response;
  65.             }
  66.         }
  67.         return response;
  68.     };
  69.    
  70.     // 如果网站使用XMLHttpRequest,同样需要拦截
  71.     const originalXHROpen = XMLHttpRequest.prototype.open;
  72.     const originalXHRSend = XMLHttpRequest.prototype.send;
  73.    
  74.     XMLHttpRequest.prototype.open = function(method, url, ...rest) {
  75.         this._url = url;
  76.         return originalXHROpen.apply(this, [method, url, ...rest]);
  77.     };
  78.    
  79.     XMLHttpRequest.prototype.send = function(body) {
  80.         const xhr = this;
  81.         
  82.         if (xhr._url && (xhr._url.includes('/rest/v2/program/681044b7729fba7beccd3565/theme') ||
  83.                         xhr._url.includes('theme?locale=') ||
  84.                         xhr._url.includes('/rest/v2/program/') && xhr._url.includes('/theme'))) {
  85.             const originalOnReadyStateChange = xhr.onreadystatechange;
  86.             xhr.onreadystatechange = function() {
  87.                 if (xhr.readyState === 4 && xhr.status === 200) {
  88.                     try {
  89.                         const responseBody = JSON.parse(xhr.responseText);
  90.                         
  91.                         if (responseBody && responseBody.config && Array.isArray(responseBody.config.countries)) {
  92.                             // 检查CN是否已存在
  93.                             if (!responseBody.config.countries.includes('CN')) {
  94.                                 console.log('添加CN到国家列表中...(XHR)');
  95.                                 // 在合适的位置添加CN,按字母顺序
  96.                                 const chIndex = responseBody.config.countries.indexOf('CH');
  97.                                 if (chIndex !== -1) {
  98.                                     responseBody.config.countries.splice(chIndex + 1, 0, 'CN');
  99.                                 } else {
  100.                                     responseBody.config.countries.push('CN');
  101.                                 }
  102.                                 
  103.                                 // 添加CN对应的标签
  104.                                 if (responseBody.config.orgSearchCountryTags) {
  105.                                     responseBody.config.orgSearchCountryTags['CN'] = ["HEI", "qualifying_hs", "qualifying_ps"];
  106.                                 }
  107.                                 
  108.                                 console.log('成功添加CN到国家列表(XHR)');
  109.                             }
  110.                            
  111.                             // 使用定义属性的方式替换responseText
  112.                             Object.defineProperty(xhr, 'responseText', {
  113.                                 get: function() {
  114.                                     return JSON.stringify(responseBody);
  115.                                 }
  116.                             });
  117.                         }
  118.                     } catch (e) {
  119.                         console.error('处理XHR响应时出错:', e);
  120.                     }
  121.                 }
  122.                
  123.                 if (originalOnReadyStateChange) {
  124.                     originalOnReadyStateChange.apply(xhr);
  125.                 }
  126.             };
  127.         }
  128.         
  129.         return originalXHRSend.apply(this, [body]);
  130.     };
  131.    
  132.     console.log('Cursor SheerID CN国家添加脚本已加载');
  133. })();
复制代码
爱生活,爱奶昔~
发表于 2025-5-7 20:32:48 | 查看全部
好东西,顶了!但不知道是不是bug,用Taiwan(台湾省)然后弄个不重名的大学也行
爱生活,爱奶昔~
回复 支持 反对

使用道具 举报

发表于 2025-5-7 20:34:42 来自手机 | 查看全部
aa11 发表于 2025-5-7 20:32
好东西,顶了!但不知道是不是bug,用Taiwan(台湾省)然后弄个不重名的大学也行 ...

直接台湾,然后选大陆大学可以嘛
我试过了可以,但不能重名。比如清华大学只有台湾那个国立清华大学 
发表于 2025-5-7 21:09
爱生活,爱奶昔~
回复 支持 反对

使用道具 举报

发表于 2025-5-8 13:30:09 | 查看全部
非常不错啊
爱生活,爱奶昔~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 申请账号

本版积分规则

  • 加入电报群
  • 订阅推送频道
© 2025 Naixi Networks 沪ICP备13020230号-1|沪公网安备 31010702007642号
关灯 在本版发帖
扫一扫订阅推送频道
返回顶部
快速回复 返回顶部 返回列表