grgk0604 发表于 2025-5-7 20:30:51

Cursor Students 强制加入China油猴脚本

// ==UserScript==
// @name         Cursor SheerID CN国家添加
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description将SheerID验证服务的响应中添加CN(中国)国家代码
// @author       You
// @match      https://my.sheerid.com/*
// @match      https://*.sheerid.com/*
// @match      https://www.cursor.com/cn/student*
// @match      https://www.cursor.com/cn/student-verified*
// @match      https://cursor.com/cn/student*
// @match      https://services.sheerid.com/verify/*
// @run-at       document-start
// @grant      none
// ==/UserScript==

(function() {
    'use strict';

    // 创建一个拦截和修改响应的函数
    const originalFetch = window.fetch;
    window.fetch = async function(url, options) {
      const response = await originalFetch(url, options);
      
      // 只拦截特定的URL
      if (url.includes('/rest/v2/program/681044b7729fba7beccd3565/theme') ||
            url.includes('theme?locale=') ||
            url.includes('/rest/v2/program/') && url.includes('/theme')) {
            try {
                // 克隆响应以便修改
                const clonedResponse = response.clone();
                const responseBody = await clonedResponse.json();
               
                // 检查并修改countries数组
                if (responseBody && responseBody.config && Array.isArray(responseBody.config.countries)) {
                  // 检查CN是否已存在
                  if (!responseBody.config.countries.includes('CN')) {
                        console.log('添加CN到国家列表中...');
                        // 在合适的位置添加CN,按字母顺序
                        // CH和CI之间是CN的合适位置
                        const chIndex = responseBody.config.countries.indexOf('CH');
                        if (chIndex !== -1) {
                            responseBody.config.countries.splice(chIndex + 1, 0, 'CN');
                        } else {
                            // 如果没找到CH,就直接添加到数组中
                            responseBody.config.countries.push('CN');
                        }
                        
                        // 添加CN对应的标签
                        if (responseBody.config.orgSearchCountryTags) {
                            responseBody.config.orgSearchCountryTags['CN'] = ["HEI", "qualifying_hs", "qualifying_ps"];
                        }
                        
                        console.log('成功添加CN到国家列表');
                  }
                  
                  // 创建一个新的响应对象
                  return new Response(JSON.stringify(responseBody), {
                        status: response.status,
                        statusText: response.statusText,
                        headers: response.headers
                  });
                }
            } catch (e) {
                console.error('处理fetch响应时出错:', e);
                return response;
            }
      }
      return response;
    };
   
    // 如果网站使用XMLHttpRequest,同样需要拦截
    const originalXHROpen = XMLHttpRequest.prototype.open;
    const originalXHRSend = XMLHttpRequest.prototype.send;
   
    XMLHttpRequest.prototype.open = function(method, url, ...rest) {
      this._url = url;
      return originalXHROpen.apply(this, );
    };
   
    XMLHttpRequest.prototype.send = function(body) {
      const xhr = this;
      
      if (xhr._url && (xhr._url.includes('/rest/v2/program/681044b7729fba7beccd3565/theme') ||
                        xhr._url.includes('theme?locale=') ||
                        xhr._url.includes('/rest/v2/program/') && xhr._url.includes('/theme'))) {
            const originalOnReadyStateChange = xhr.onreadystatechange;
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                  try {
                        const responseBody = JSON.parse(xhr.responseText);
                        
                        if (responseBody && responseBody.config && Array.isArray(responseBody.config.countries)) {
                            // 检查CN是否已存在
                            if (!responseBody.config.countries.includes('CN')) {
                              console.log('添加CN到国家列表中...(XHR)');
                              // 在合适的位置添加CN,按字母顺序
                              const chIndex = responseBody.config.countries.indexOf('CH');
                              if (chIndex !== -1) {
                                    responseBody.config.countries.splice(chIndex + 1, 0, 'CN');
                              } else {
                                    responseBody.config.countries.push('CN');
                              }
                              
                              // 添加CN对应的标签
                              if (responseBody.config.orgSearchCountryTags) {
                                    responseBody.config.orgSearchCountryTags['CN'] = ["HEI", "qualifying_hs", "qualifying_ps"];
                              }
                              
                              console.log('成功添加CN到国家列表(XHR)');
                            }
                           
                            // 使用定义属性的方式替换responseText
                            Object.defineProperty(xhr, 'responseText', {
                              get: function() {
                                    return JSON.stringify(responseBody);
                              }
                            });
                        }
                  } catch (e) {
                        console.error('处理XHR响应时出错:', e);
                  }
                }
               
                if (originalOnReadyStateChange) {
                  originalOnReadyStateChange.apply(xhr);
                }
            };
      }
      
      return originalXHRSend.apply(this, );
    };
   
    console.log('Cursor SheerID CN国家添加脚本已加载');
})();

aa11 发表于 2025-5-7 20:32:48

好东西,顶了!但不知道是不是bug,用Taiwan(台湾省)然后弄个不重名的大学也行{tieba27}

闲云 发表于 2025-5-7 20:34:42

aa11 发表于 2025-5-7 20:32
好东西,顶了!但不知道是不是bug,用Taiwan(台湾省)然后弄个不重名的大学也行 ...

直接台湾,然后选大陆大学可以嘛

fkeyou 发表于 2025-5-8 13:30:09

非常不错啊
页: [1]
查看完整版本: Cursor Students 强制加入China油猴脚本