From 75417f5e3d32645859d94cec82255dc130ec4a2e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 18:55:34 +0200 Subject: Adding upstream version 2020.10.7. Signed-off-by: Daniel Baumann --- scripts/updategoogle.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 scripts/updategoogle.py (limited to 'scripts/updategoogle.py') diff --git a/scripts/updategoogle.py b/scripts/updategoogle.py new file mode 100755 index 0000000..a3046d4 --- /dev/null +++ b/scripts/updategoogle.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +import json +import sys + +from collections import OrderedDict + +def convert(text): + patterns = [] + for domain in text.split(): + patterns.append("https://www" + domain + "/*") + patterns.append("http://www" + domain + "/*") + return patterns + +def update_manifest(tempfile_path, manifest_path): + with open(manifest_path, 'r') as f: + manifest = json.load(f, object_pairs_hook=OrderedDict) + + with open(tempfile_path, 'r+') as f: + # tempfile_path contains Google's supported domains + match_patterns = convert(f.read()) + + scripts_idx = -1 + for idx, entry in enumerate(manifest['content_scripts']): + if "js/firstparties/google-search.js" in entry['js']: + scripts_idx = idx + break + if scripts_idx == -1: + print("Failed to locate the Google Search content script in the manifest!") + sys.exit(1) + + manifest['content_scripts'][scripts_idx]['matches'] = match_patterns + + # overwrite tempfile_path with the updated manifest + f.seek(0) + # print() auto-adds a trailing newline + print( + json.dumps( + manifest, + sort_keys=False, + indent=2, + separators=(',', ': ') + ), + file=f + ) + f.truncate() + +if __name__ == '__main__': + # argv[1]: the path to a copy of https://www.google.com/supported_domains + # argv[2]: the path to the extension manifest + update_manifest(sys.argv[1], sys.argv[2]) -- cgit v1.2.3