Skip to content

Commit

Permalink
wip: update for gh-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
renxia committed Mar 3, 2023
1 parent 5bce694 commit 6ef5d93
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 31 deletions.
49 changes: 43 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,61 @@ GitHub 访问代理助手。一个适合中国大陆用户使用的浏览器油

## 主要功能

- 为源码`文件`添加加速代理链接浮动按钮
- 为仓库生成加速 `clone` 地址的可选项
-`release` 附件生成加速下载的链接可选项
- `源码文件、release附件`添加加速代理链接浮动按钮
- 为仓库生成加速 `clone` 地址的可选项
-`raw``release` 附件生成加速下载的链接可选项
- more...

## 安装

首先,你应确保浏览器已安装油猴扩展 [violentmonkey](https://violentmonkey.github.io/get-it/)

然后在浏览器地址栏输入如下地址,即可进行本脚本的安装
然后在浏览器地址栏输入如下地址,应当会被油猴插件检测到并跳转到安装确认界面(若未检测到,可手动复制其内容,在油猴插件中新建脚本并填入)

```txt
https://ghproxy.com/lzwme/vm-gh-proxy-cn/blob/main/gh-proxy.js
```

## 关于 Github 代理访问体验提升的几种策略

当前主要有以下几种策略,其核心是基于开源免费的 CDN 网站或代理网站地址,对要访问的 GitHub 资源地址支持代理、重定向、或镜像服务,以实现加速访问或下载。

低频率简单使用:

- `host绑定`:DNS 测速获取 host、host 绑定软件定时更新
- `host 切换管理软件 SwitchHosts`: <brew|scoop> install switchhosts
- `host定时更新`https://gitlab.cn/ineo6/hosts/-/raw/master/next-hosts
- `host定时更新`https://ghproxy.com/https://raw.githubusercontent.com/521xueweihan/GitHub520/main/hosts
- `浏览器插件网页助手`
- [violentmonkey(油猴插件)](https://violentmonkey.github.io/get-it/)
- [Git Master 插件](https://github.com/ineo6/git-master)
- `免费的代理资源站(raw/archive/release 下载、git clone)、mirror镜像`
- [https://ghproxy.com](https://ghproxy.com)
- [https://fastgit.org](https://fastgit.org)
- [CF workers 免费代理站(域名污染,已基本失效)](https://dash.cloudflare.com)
- [https://cdn.jsdelivr.net/gh](https://cdn.jsdelivr.net/gh) 50MB 限制
- [https://cdn.staticaly.com/gh](https://cdn.staticaly.com/gh) 图片与源码文件,30MB 限制
- more...
- `代理软件:`拦截请求,重定向、代理、SNI
- 本地起 nginx 等 webserver 服务,设置为本地代理,配置代理、重定向、SNI 配置等规则
- [https://github.com/docmirror/dev-sidecar](https://github.com/docmirror/dev-sidecar)
- more...
- `仓库镜像`:使用国内开源站查找或自行建立定时同步镜像
- [gitee mirrors](https://gitee.com/organizations/mirrors/projects)
- [gitlab.cn](https://gitlab.cn)
- [gitcode.net/mirrors](https://gitcode.net/mirrors)

高频逛 `GitHub` 的重度用户:

- 买 VPN 服务
- 买外网 VPS 服务器自建代理
- More...

**提示:请注意风险,应仅以为学习研究提供便利为唯一目的,切勿触及道德与法律底线。**

## 相关参考

感谢以下开源仓库的工作。本脚本参考了其中部分仓库的相关逻辑。

- https://github.com/du33169/gh-proxy-buttons
- https://github.com/RC1844/FastGithub
- [https://github.com/du33169/gh-proxy-buttons](https://github.com/du33169/gh-proxy-buttons)
- [https://github.com/RC1844/FastGithub](https://github.com/RC1844/FastGithub)
84 changes: 84 additions & 0 deletions dev-sidecar-remote_config.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"server": {
"intercepts": {
"github.com": {
"/.*/.*/releases/download/": {
"redirect": "ghproxy.com/https://github.com/",
"desc": "release文件加速下载跳转地址"
},
"/.*/.*/archive/": {
"redirect": "download.fastgit.org"
},
"/.*/.*/blame/": {
"redirect": "hub.fastgit.org"
},
"^/[^/]+/[^/]+(/releases(/.*)?)?$": {
"script": [
"github"
],
"desc": "clone加速复制链接脚本"
},
"/.*": {
"proxy": "github.com",
"desc": "目前禁掉sni就可以直接访问,如果后续github.com的ip被封锁,只能再走proxy模式",
"sni": "baidu.com"
},
"/.*/.*/raw/": {
"replace": "(.+)\\/raw\\/(.+)",
"proxy": "raw.fastgit.org$1/$2",
"sni": "baidu.com"
}
},
"github.githubassets.com": {
".*": {
"proxy": "github.githubassets.com",
"sni": "baidu.com"
}
},
"www.gstatic.com": {
"/recaptcha/.*": {
"proxy": "www.recaptcha.net"
}
}
},
"dns": {
"mapping": {
"*jetbrains.com": "quad9",
"*azureedge.net": "quad9",
"*stackoverflow.com": "quad9"
},
"speedTest": {
"interval": 300000
}
}
},
"plugin": {
"overwall": {
"targets": {
"*azureedge.net": true,
"github.com": true,
"*wikimedia.org": true,
"v2ex.com": true,
"*cloudfront.net": true,
"*bing.com": true,
"*discourse-cdn.com": true,
"*gravatar.com": true,
"*docker.com": true,
"*vueuse.org": true,
"*elastic.co": true,
"*optimizely.com": true,
"*stackpathcdn.com": true,
"*fastly.net": true,
"*cloudflare.com": true,
"*233v2.com": true,
"*v2fly.org": true,
"*telegram.org": true,
"*amazon.com": true,
"*googleapis.com": true,
"*cloudflareinsights.com": true,
"*.intlify.dev": true,
"*segment.io": true
}
}
}
}
47 changes: 22 additions & 25 deletions gh-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// @include *://hub.fastgit.xyz/*
// @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.slim.min.js
// @icon https://github.githubassets.com/favicon.ico
// @version 1.0.0
// @version 1.0.1
// ==/UserScript==

(function () {
Expand All @@ -28,8 +28,8 @@
},
ghproxy1: {
url: 'https://gh.api.99988866.xyz/github.com',
name: 'ghproxy-99988866',
desc: 'ghproxy 代理',
name: 'ghproxy-xyz',
desc: 'ghproxy 代理(演示站)',
types: ['clone', 'download', 'raw'],
format: url => `${Mirrors.ghproxy1.url}/${url.replace(/^\//, '')}`,
},
Expand Down Expand Up @@ -70,29 +70,29 @@
types: ['raw'],
},
// fastgitdl: {
// url: 'https://download.fastgit.org',
// url: 'https://download.fastgit.org', // todo: only release files、zip
// name: 'fastgit-dl',
// desc: 'fastgit download',
// types: ['download'],
// },
// fastgitxyz: {
// url: 'https://hub.fastgit.xyz',
// name: 'fastgit',
// desc: '由@KevinZonda推动的FastGit项目',
// types: ['clone', 'mirror'],
// },
// wuyanzheshui: {
// url: 'https://github.wuyanzheshui.workers.dev',
// name: 'CF加速 1',
// desc: '每日10万次调用上限,由wuyanzheshui提供',
// desc: '【CF加速】每日10万次调用上限,由 wuyanzheshui 提供',
// types: ['mirror', 'clone', 'download'],
// },
// rc1844: {
// "url": "https://github.rc1844.workers.dev",
// "name": "CF加速 2",
// "desc": "每日10万次调用上限,由@lzwme提供",
// "desc": "【CF加速】每日10万次调用上限,由 @rc1844 提供",
// types: ['clone', 'download', 'raw'],
// },
// lzwme: {
// "url": "https://gh.lzwme.workers.dev",
// "name": "CF加速 2",
// "desc": "【CF加速】每日10万次调用上限,由 @renxia 提供",
// types: ['clone', 'download', 'raw', 'mirror'],
// },
// gitclone: {
// "url": "https://gitclone.com/github.com",
// "name": "GitClone",
Expand All @@ -102,7 +102,7 @@
};
const OtherUrl = [
["https://github.com/lzwme/vm-gh-proxy-cn", "脚本Github仓库地址,点个赞谢谢"],
["https://greasyfork.org/zh-CN/scripts/397419", "GreasyFork地址,请评分收藏"],
["https://greasyfork.org/zh-CN/scripts/397419", "GreasyFork 地址,请评分收藏"],
["https://doc.fastgit.org/", "FastGit,请仔细甄别"],
["https://d.serctl.com", "GitHub中转下载"],
["https://gitee.com/organizations/mirrors/projects", "Gitee 极速下载"],
Expand All @@ -112,6 +112,9 @@
MirrorsList.forEach(item => {
if (!item.format) {
item.format = (href, type) => {
if (type === 'raw' && ['Statically', 'jsDelivr'].includes(item.name)) {
return item.url + href.replace(`${repo}/raw/`, `${repo}@`);
}
const sep = item.url.includes('@') ? ':' : '/';
return `${item.url}${sep}${href.replace(/^\//, '')}`;
};
Expand Down Expand Up @@ -150,13 +153,12 @@
* 添加Raw列表
*/
function addRawList() {
const rawUrl = $("#raw-url");
let rawUrl = $("#raw-url");
if (!rawUrl.length) rawUrl = $(`a[data-testid="raw-button"]:last`);
const rawHref = rawUrl.attr('href');
if (!rawHref) return;

// rawHtml(11, MirrorUrl[11][0] + href.replace("/raw", ""));
// rawHtml(9, MirrorUrl[9][0] + href.replace("/raw/", "@"));
// rawHtml(12, MirrorUrl[12][0] + href.replace("/raw", ""));
$('.raw-btn-proxy').remove();
RawSet.forEach((item) => {
const span = rawUrl.clone().removeAttr('id');

Expand All @@ -165,7 +167,7 @@
title: item.desc,
target: "_blank",
});
span.text(item.name);
span.text(item.name).addClass('raw-btn-proxy');
rawUrl.before(span);
});
}
Expand Down Expand Up @@ -303,17 +305,12 @@
const preBtn = $('#gh-proxy-btn');
const href =$el.attr('href').replace(/^https:\/\/github\.com/, '');
const proxyHref = `${Mirrors.ghproxy.url}${href}`;
if (
!/\/(blob|release|archive)\//.test(href) ||
href.startsWith('http') ||
preBtn.attr('href') === proxyHref) {
return;
}
if (!/\/(blob|release|archive)\//.test(href) || href.startsWith('http') || preBtn.attr('href') === proxyHref) return;

$('#gh-proxy-btn').remove();
const $btn = $(`<a class="btn" href="${proxyHref}" target="_blank" title="proxy link" id="gh-proxy-btn">🚀</a>`);

$el.parent().append($btn).css({ position: 'relative' });
$el.parent().append($btn).css({ position: 'relative', overflow: 'visible' });
$btn.css({ position: 'absolute', left: 120, top: 2 });
$btn.on('mouseleave', () => $btn.remove());
});
Expand Down

0 comments on commit 6ef5d93

Please sign in to comment.