使用 chrome 插件SwitchyOmega 分流节约梯子流量

2020/2/8 9:01:25

本文主要是介绍使用 chrome 插件SwitchyOmega 分流节约梯子流量,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

导致原因

  • ssr 飞机场和 公司 vpn 冲突
  • 公司的 vpn 连接以后,小飞机直接熄火了。

找了很久的原因不知道为什么,其他同事和朋友都可以正常使用, 下面迫不得已使用了 chrome 的 SwitchyOmega 插件来做了分流。

解决问题

  • 分流,内网使用内网端口,外网使用外网端口,这样也可以节省流量。

使用 chrome 的 SwitchyOmega 插件

  • chrome.google.com/webstore/de…
  • 这个插件的功能主要是根据你访问的域名来切换端口(proxy)
  • 流程: 新建一个情景模式--> 写入 pac 脚本 --> 应用这个选项

image

代理 pac 语法介绍

function FindProxyForURL(url, host) {
    // 这里面写各种规则
    // 返回的是字符串:
    // - "DIRECT" 直接连接
    // - "PROXY: 127.0.0.1:1080"  代理连接
}
复制代码

demo

// Generated by gfwlist2pac
var domains = __DOMAINS__;

var proxy = __PROXY__; // 'PROXY' or 'SOCKS5' or 'HTTPS'

var direct = 'DIRECT;';

var hasOwnProperty = Object.hasOwnProperty;

function FindProxyForURL(url, host) {
    var suffix;
    var pos = host.lastIndexOf('.');
    pos = host.lastIndexOf('.', pos - 1);
    while(1) {
        if (pos == -1) {
            if (hasOwnProperty.call(domains, host)) {
                return proxy;
            } else {
                return direct;
            }
        }
        suffix = host.substring(pos + 1);
        if (hasOwnProperty.call(domains, suffix)) {
            return proxy;
        }
        pos = host.lastIndexOf('.', pos - 1);
    }
}
复制代码

动手实践

  • 我们希望访问 google 和 facebook 网站
var domains = {
  "google.com": 1,
  "facebook.com": 1,
  "__THE_END__": 1
}

var proxy = "HTTP 127.0.0.1:1087;SOCKS5 127.0.0.1:1086; DIRECT;";

var direct = 'DIRECT;';

var hasOwnProperty = Object.hasOwnProperty;

function FindProxyForURL(url, host) {
    var suffix;
    var pos = host.lastIndexOf('.');
    pos = host.lastIndexOf('.', pos - 1);
    while(1) {
        if (pos == -1) {
            if (hasOwnProperty.call(domains, host)) {
                return proxy;
            } else {
                return direct;
            }
        }
        suffix = host.substring(pos + 1);
        if (hasOwnProperty.call(domains, suffix)) {
            return proxy;
        }
        pos = host.lastIndexOf('.', pos - 1);
    }
}
复制代码

这里有个问题了,我们怎么找到我们的 HTTP 和 SOCKS5 端口配置来,如果你使用的是 ssr-->偏好设置 可以按照下面的图示找到。

image
image

或者在网络设置-->高级-->代理中可以看到相关设置项

随后在设置 domains 中设置你需要分流的网站就可以了。

  • 在参考中有一个 py 的分流工具大家也可以研究一下。

参考



这篇关于使用 chrome 插件SwitchyOmega 分流节约梯子流量的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程