mirror of
https://codeberg.org/Amm0ni4/bypass-all-shortlinks-debloated.git
synced 2024-12-29 16:33:02 +05:00
generate include and match rules separatedly
this can be useful for copy-pasting these rules into the script settings in ViolentMonkey
This commit is contained in:
parent
74d6bc83b2
commit
66391fb7c0
2 changed files with 34 additions and 37 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
||||||
untouched_Bypass_All_Shortlinks.user.js
|
untouched_Bypass_All_Shortlinks.user.js
|
||||||
includes.txt
|
includes.txt
|
||||||
|
match_rules.txt
|
||||||
|
include_rules.txt
|
||||||
|
|
|
@ -7,7 +7,6 @@ def extract_regex_from_js(js_code):
|
||||||
|
|
||||||
pattern2 = r"(?<!//)BloggerPemula\('([^']+)',"
|
pattern2 = r"(?<!//)BloggerPemula\('([^']+)',"
|
||||||
matches2 = re.findall(pattern2, js_code)
|
matches2 = re.findall(pattern2, js_code)
|
||||||
#matches2 = ['/' + s + '/' for s in matches2]
|
|
||||||
|
|
||||||
pattern3 = r"(?<!//)RemoveBp\('([^']+)',"
|
pattern3 = r"(?<!//)RemoveBp\('([^']+)',"
|
||||||
matches3 = re.findall(pattern3, js_code)
|
matches3 = re.findall(pattern3, js_code)
|
||||||
|
@ -20,44 +19,40 @@ def extract_regex_from_js(js_code):
|
||||||
|
|
||||||
return matches1+matches2+matches3+matches4+matches5
|
return matches1+matches2+matches3+matches4+matches5
|
||||||
|
|
||||||
def regex_to_include_line(regex):
|
def write_list_of_strings_to_file(filename, lines):
|
||||||
#regex = regex.strip("/")
|
|
||||||
|
|
||||||
#Use @include for more complex regex
|
|
||||||
if any(char in regex for char in ['|', '(', ')', '*']):
|
|
||||||
regex = '(' + regex + ')'
|
|
||||||
include_line = "// @include /^(https?:\/\/)(.+)?" + regex + "(\/.*)/"
|
|
||||||
include_line = include_line.replace( "\.*)(\/.*)/", "\.*)/" ) #clean excess in the regex
|
|
||||||
|
|
||||||
#Use @match for simpler regex
|
|
||||||
else:
|
|
||||||
include_line = '// @match *://*.' + regex + '/*'
|
|
||||||
|
|
||||||
return include_line
|
|
||||||
|
|
||||||
def generate_include_lines(regex_list):
|
|
||||||
include_lines = []
|
|
||||||
for regex in regex_list:
|
|
||||||
include_line = regex_to_include_line(regex)
|
|
||||||
include_lines.append(include_line)
|
|
||||||
|
|
||||||
return include_lines
|
|
||||||
|
|
||||||
def write_to_file(filename, lines):
|
|
||||||
with open(filename, 'w', encoding='utf-8') as file:
|
with open(filename, 'w', encoding='utf-8') as file:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
file.write(line + '\n')
|
file.write(line + '\n')
|
||||||
print(f"OK: Generated {filename}")
|
print(f"OK: Generated {filename}")
|
||||||
|
|
||||||
def compile_and_print(regex_strings):
|
def generate_include_lines(regex_list):
|
||||||
#for regex_string in regex_strings: print(regex_string)
|
include_rules = []
|
||||||
write_to_file('supported_sites.txt', regex_strings)
|
match_rules = []
|
||||||
|
include_and_match_lines = []
|
||||||
|
|
||||||
include_lines = generate_include_lines(regex_strings)
|
for regex in regex_list:
|
||||||
print(f"OK: Generated {len(include_lines)} include lines.")
|
|
||||||
|
|
||||||
#for line in include_lines: print(line)
|
#Use @include for more complex regex
|
||||||
write_to_file('includes.txt', include_lines)
|
if any(char in regex for char in ['|', '(', ')', '*']):
|
||||||
|
regex = '(' + regex + ')'
|
||||||
|
include_rule = "/^(https?:\/\/)(.+)?" + regex + "(\/.*)/"
|
||||||
|
include_rule = include_rule.replace( "\.*)(\/.*)/", "\.*)/" ) #clean excess in the regex
|
||||||
|
include_rules.append(include_rule)
|
||||||
|
include_line = "// @include " + include_rule
|
||||||
|
include_and_match_lines.append(include_line)
|
||||||
|
|
||||||
|
#Use @match for simpler regex
|
||||||
|
else:
|
||||||
|
match_rule = '*://*.' + regex + '/*'
|
||||||
|
match_rules.append(match_rule)
|
||||||
|
match_line = '// @match ' + match_rule
|
||||||
|
include_and_match_lines.append(match_line)
|
||||||
|
|
||||||
|
#Output results to txt files
|
||||||
|
write_list_of_strings_to_file('supported_sites.txt', regex_list)
|
||||||
|
write_list_of_strings_to_file('match_rules.txt', match_rules)
|
||||||
|
write_list_of_strings_to_file('include_rules.txt', include_rules)
|
||||||
|
write_list_of_strings_to_file('includes.txt', include_and_match_lines)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -79,7 +74,7 @@ def main():
|
||||||
]
|
]
|
||||||
regex_strings = [s for s in regex_strings if not any(word in s for word in blocked_words_for_includes)]
|
regex_strings = [s for s in regex_strings if not any(word in s for word in blocked_words_for_includes)]
|
||||||
|
|
||||||
compile_and_print(regex_strings)
|
generate_include_lines(regex_strings)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(f"Error: File '{file_path}' not found.")
|
print(f"Error: File '{file_path}' not found.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in a new issue