mirror of
https://github.com/iBug/pac.git
synced 2025-07-13 21:02:16 +08:00
Slightly compact domain list
This commit is contained in:
parent
6a039ce9c8
commit
c09c33bcf1
2
code.js
2
code.js
@ -44,6 +44,8 @@ function checkDomainType(host) {
|
|||||||
ptr = ptr[segment];
|
ptr = ptr[segment];
|
||||||
if (ptr === undefined)
|
if (ptr === undefined)
|
||||||
break;
|
break;
|
||||||
|
if (typeof ptr === "number")
|
||||||
|
return ptr;
|
||||||
if (ptr["@"] !== undefined)
|
if (ptr["@"] !== undefined)
|
||||||
type = ptr["@"];
|
type = ptr["@"];
|
||||||
}
|
}
|
||||||
|
27
gfwlist.py
27
gfwlist.py
@ -1,18 +1,25 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
GFWLIST_FILE = "gfwlist.txt"
|
||||||
GFWLIST_URL = 'https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt'
|
GFWLIST_URL = 'https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt'
|
||||||
|
|
||||||
|
|
||||||
def get_gfwlist():
|
def get_gfwlist():
|
||||||
r = requests.get(GFWLIST_URL)
|
if os.path.isfile(GFWLIST_FILE):
|
||||||
r.raise_for_status()
|
with open(GFWLIST_FILE, "r") as f:
|
||||||
return base64.b64decode(r.text).decode("utf-8").rstrip("\n")
|
text = f.read()
|
||||||
|
else:
|
||||||
|
r = requests.get(GFWLIST_URL)
|
||||||
|
r.raise_for_status()
|
||||||
|
text = r.text
|
||||||
|
return base64.b64decode(text).decode("utf-8").rstrip("\n")
|
||||||
|
|
||||||
|
|
||||||
def update_domains(domains, host, mode=0):
|
def update_domains(domains, host, mode=0):
|
||||||
@ -26,6 +33,19 @@ def update_domains(domains, host, mode=0):
|
|||||||
this["@"] = mode
|
this["@"] = mode
|
||||||
|
|
||||||
|
|
||||||
|
def postproc_domains(domains):
|
||||||
|
# Turn all {"@": 1} into 1 to save some text
|
||||||
|
keys = list(domains.keys())
|
||||||
|
for key in keys:
|
||||||
|
if key == "@":
|
||||||
|
continue
|
||||||
|
obj = domains[key]
|
||||||
|
if len(obj) == 1 and "@" in obj:
|
||||||
|
domains[key] = obj["@"]
|
||||||
|
else:
|
||||||
|
postproc_domains(obj)
|
||||||
|
|
||||||
|
|
||||||
def parse_gfwlist(text):
|
def parse_gfwlist(text):
|
||||||
domains = {}
|
domains = {}
|
||||||
blackpat = [] # blacklisted patterns
|
blackpat = [] # blacklisted patterns
|
||||||
@ -61,6 +81,7 @@ def parse_gfwlist(text):
|
|||||||
blackpat.append(line)
|
blackpat.append(line)
|
||||||
else:
|
else:
|
||||||
whitepat.append(line)
|
whitepat.append(line)
|
||||||
|
postproc_domains(domains)
|
||||||
return domains, blackpat, whitepat
|
return domains, blackpat, whitepat
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user