Prefer IPv6 and HTTP/2 or HTTP/3 Requests

优先使用IPv6和HTTP/2或HTTP/3进行数据传输

  1. // ==UserScript==
  2. // @name Prefer IPv6 and HTTP/2 or HTTP/3 Requests
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description 优先使用IPv6和HTTP/2或HTTP/3进行数据传输
  6. // @author KiwiFruit
  7. // @match *://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // 定义一个函数用于发送请求
  16. async function fetchWithPreferences(url) {
  17. try {
  18. const response = await fetch(url, {
  19. // 浏览器会自动选择合适的协议和IP版本
  20. });
  21.  
  22. if (!response.ok) {
  23. throw new Error('Network response was not ok');
  24. }
  25.  
  26. // 输出响应头中的协议版本(仅适用于支持此功能的浏览器)
  27. console.log('Used protocol:', response.headers.get('alt-svc') || 'Unknown');
  28.  
  29. return await response.text();
  30. } catch (error) {
  31. console.error('There has been a problem with your fetch operation:', error);
  32. }
  33. }
  34.  
  35. // 获取当前页面的URL
  36. const currentUrl = window.location.href;
  37.  
  38. // 如果需要对特定域名或路径进行处理,可以在这里添加条件判断
  39. // 示例:如果要处理所有页面,直接使用currentUrl即可
  40. console.log(`Current URL: ${currentUrl}`);
  41.  
  42. // 使用当前页面的URL发起请求
  43. fetchWithPreferences(currentUrl).then(data => {
  44. console.log('Response data:', data);
  45.  
  46. // 如果需要自动跳转到另一个页面,可以在这里设置
  47. // 示例:假设你想跳转到一个特定的页面,可以使用以下代码
  48. // window.location.href = 'https://example.com';
  49. // 如果需要根据某些条件决定是否跳转,可以在这里添加逻辑
  50. // 例如,检查返回的数据内容,然后决定是否跳转
  51. }).catch(error => {
  52. console.error('Error fetching current page:', error);
  53. });
  54. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址