Skip to content

Commit

Permalink
close #1
Browse files Browse the repository at this point in the history
  • Loading branch information
chaosrun committed Nov 3, 2020
1 parent 88c5b01 commit d84c9a3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
data/
tmp/
.idea/
*.sh
log
config.ini
output.json
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Firefox 上的插件 [FoxyProxy](https://addons.mozilla.org/firefox/addon/foxypr

此程序实现的功能很简单,用于从 GFWList 中生成一份 `json` 文件,将其导入到 FoxyProxy 后,可实现类似于 SwitchyOmega 插件的 Auto Switch 功能。

注意:由于 FoxyProxy 的规则只能针对域名进行匹配,故 GFWList 中涉及网址具体路径的规则无法发挥其效果,不过好在这类规则数量较少,而本程序的策略是对涉及路径的规则直接采用其域名,将域名添加到自动代理的列表中。
**注意:**由于 FoxyProxy 的规则只能针对域名进行匹配,故 GFWList 中涉及网址具体路径的规则无法发挥其效果,不过好在这类规则数量较少,而本程序的策略是对涉及路径的规则直接采用其域名,将域名添加到自动代理的列表中。

**注意:**您可能需要先关闭 FoxyProxy 中的「同步」,否则导入的规则可能会无法生效,详情请见文末「排疑解答」。

## 使用方法

Expand Down Expand Up @@ -64,6 +66,18 @@ deactivate

![](images/custom.png)

## 排疑解难

关于导入规则后不生效的解决办法:

由于 FoxyProxy 插件本身的[已知 Bug](https://github.com/foxyproxy/firefox-extension/issues/95),导入规则后,用户可能会发现规则并没有生效。

在 FoxyProxy 正式修复此问题之前,根据[该插件作者提供的方法](https://github.com/foxyproxy/firefox-extension/issues/95#issuecomment-669396670),用户需要关闭「同步设置」功能,才可正常导入规则。

![](images/synchronize.png)

---

## 参考

FoxyProxy Pattern Help(扩展自带帮助页面)
Expand Down
Binary file added images/synchronize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 29 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.WARNING,
filename="log",
filemode="w"
filemode="a"
)
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -88,6 +88,8 @@

def get_dict(rule: str) -> (int, dict):
# Get pattern dict
result = (0, {})

try:
protocol = 1
white = 1
Expand Down Expand Up @@ -126,25 +128,36 @@ def get_dict(rule: str) -> (int, dict):
"active": True
}

return white, the_dict
result = (white, the_dict)
except Exception as ee:
print(f"[ERROR] Get dict error: {e}")
logger.warning(f"Get dict error: {ee}", exc_info=True)

return 0, {}
return result


def main() -> bool:
result = False

def main():
try:
copyright_text = ("FoxyProxy, Copyright (C) 2019-2020 SCP-079 <https://scp-079.org>\n"
"Licensed under the terms of the GNU General Public License v3 or later (GPLv3+)\n" +
"-" * 24)
print(copyright_text)

result = get(url, proxies=proxies)

if not result or not result.content:
return True
return False

text = b64decode(result.content)
text = text.decode("utf-8")

if not text:
return True
return False

print("[INFO] Got the GFWList!")
print("[INFO] Processing...")

rules = list(filter(None, text.split("\n")))

Expand All @@ -168,11 +181,21 @@ def main():
else:
base["whitePatterns"].append(the_dict)

print("[INFO] Saving the output file...")

with open("output.json", "w") as ff:
dump(base, ff, indent=4)

print("[INFO] Succeeded!")
print("[INFO] Please check the file: output.json")

result = True
except Exception as ee:
print(f"[ERROR] Main function error: {e}")
logger.warning(f"Error: {ee}", exc_info=True)

return result


if __name__ == "__main__":
main()
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
certifi==2019.11.28
certifi==2020.6.20
chardet==3.0.4
idna==2.9
idna==2.10
PySocks==1.7.1
requests==2.23.0
urllib3==1.25.8
requests==2.24.0
urllib3==1.25.11

0 comments on commit d84c9a3

Please sign in to comment.