其他分类 · 30 4 月, 2025 0

如何自己制作PAC规则:模板及说明

典型样式

PAC规则一般由JavaScript写成,典型的形式如下:

var proxy = "PROXY 192.168.1.1:1080";
// ^ 指定代理服务器地址。
//  协议可以为PROXY(普通HTTP代理)/SOCKS5/HTTPS,一般PROXY就行了。
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);
    }
}

// --- 这里开始指定经由代理访问的网址 ---
var domains = {
  "baidu.com": 1,
  "bing.com": 1
  // 一行一个网址
};