Skip to content

Instantly share code, notes, and snippets.

@jonbakerfish
Last active July 21, 2023 15:12
Show Gist options
  • Save jonbakerfish/3df2b1cfbbae15e411672358eb2f3020 to your computer and use it in GitHub Desktop.
Save jonbakerfish/3df2b1cfbbae15e411672358eb2f3020 to your computer and use it in GitHub Desktop.
my pac
var proxy = 'SOCKS5 127.0.0.1:1088; DIRECT;';
var rules = [
[
[],
[]
],
[
[
"onedrive.com",
"onedrive.live.com",
"1drv.ms",
"akamaitechnologies.com",
"51.132.193.104",
"20.205.115.102",
"40.79.189.58"
],
[]
]
];
var lastRule = '';
function FindProxyForURL(url, host) {
for (var i = 0; i < rules.length; i++) {
ret = testHost(host, i);
if (ret != undefined)
return ret;
}
return 'DIRECT';
}
function testHost(host, index) {
for (var i = 0; i < rules[index].length; i++) {
for (var j = 0; j < rules[index][i].length; j++) {
lastRule = rules[index][i][j];
if (host == lastRule || host.endsWith('.' + lastRule))
return i % 2 == 0 ? 'DIRECT' : proxy;
}
}
lastRule = '';
}
// REF: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(searchString, position) {
var subjectString = this.toString();
if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.indexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment