// ==UserScript== // @name Prefer IPv6 and HTTP/2 or HTTP/3 Requests // @namespace http://tampermonkey.net/ // @version 1.1 // @description 优先使用IPv6和HTTP/2或HTTP/3进行数据传输 // @author KiwiFruit // @match *://*/* // @grant none // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/529503/Prefer%20IPv6%20and%20HTTP2%20or%20HTTP3%20Requests.user.js // @updateURL https://update.greasyfork.icu/scripts/529503/Prefer%20IPv6%20and%20HTTP2%20or%20HTTP3%20Requests.meta.js // ==/UserScript== (function() { 'use strict'; // 定义一个函数用于发送请求 async function fetchWithPreferences(url) { try { const response = await fetch(url, { // 浏览器会自动选择合适的协议和IP版本 }); if (!response.ok) { throw new Error('Network response was not ok'); } // 输出响应头中的协议版本(仅适用于支持此功能的浏览器) console.log('Used protocol:', response.headers.get('alt-svc') || 'Unknown'); return await response.text(); } catch (error) { console.error('There has been a problem with your fetch operation:', error); } } // 获取当前页面的URL const currentUrl = window.location.href; // 如果需要对特定域名或路径进行处理,可以在这里添加条件判断 // 示例:如果要处理所有页面,直接使用currentUrl即可 console.log(`Current URL: ${currentUrl}`); // 使用当前页面的URL发起请求 fetchWithPreferences(currentUrl).then(data => { console.log('Response data:', data); // 如果需要自动跳转到另一个页面,可以在这里设置 // 示例:假设你想跳转到一个特定的页面,可以使用以下代码 // window.location.href = 'https://example.com'; // 如果需要根据某些条件决定是否跳转,可以在这里添加逻辑 // 例如,检查返回的数据内容,然后决定是否跳转 }).catch(error => { console.error('Error fetching current page:', error); }); })();