From 2a996c062fe485347a858f05297947ec53dbd8f9 Mon Sep 17 00:00:00 2001 From: Amm0ni4 Date: Thu, 18 Jan 2024 01:12:01 +0000 Subject: [PATCH] Upload files to "/" --- .gitignore | 3 ++ 1_download_untouched.py | 20 +++++++++++ 2_generate_includes.py | 74 +++++++++++++++++++++++++++++++++++++++++ 3_patch.py | 67 +++++++++++++++++++++++++++++++++++++ README.md | 18 ++++++++++ 5 files changed, 182 insertions(+) create mode 100644 .gitignore create mode 100644 1_download_untouched.py create mode 100644 2_generate_includes.py create mode 100644 3_patch.py create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc9ad8c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +untouched_Bypass_All_Shortlinks.user.js +includes.txt diff --git a/1_download_untouched.py b/1_download_untouched.py new file mode 100644 index 0000000..1502b6a --- /dev/null +++ b/1_download_untouched.py @@ -0,0 +1,20 @@ +import requests + +def download_file(url, destination): + try: + response = requests.get(url) + response.raise_for_status() # Check if the request was successful + + with open(destination, 'wb') as file: + file.write(response.content) + + print(f"OK: File downloaded successfully as {destination}") + + except requests.exceptions.RequestException as e: + print(f"Error downloading file: {e}") + +if __name__ == "__main__": + url = "https://update.greasyfork.org/scripts/431691/Bypass%20All%20Shortlinks.user.js" + destination = "untouched_Bypass_All_Shortlinks.user.js" + + download_file(url, destination) diff --git a/2_generate_includes.py b/2_generate_includes.py new file mode 100644 index 0000000..0f7507c --- /dev/null +++ b/2_generate_includes.py @@ -0,0 +1,74 @@ +import re + +def extract_regex_from_js(js_code): + pattern1 = r'BypassedByBloggerPemula\((.*?),' + matches1 = re.findall(pattern1, js_code) + matches1 = [match.strip('/') for match in matches1] + + pattern2 = r"BloggerPemula\('([^']+)'," + matches2 = re.findall(pattern2, js_code) + #matches2 = ['/' + s + '/' for s in matches2] + + pattern3 = r"RemoveBp\('([^']+)'," + matches3 = re.findall(pattern3, js_code) + + pattern4 = r'case \'(.*?)\':' + matches4 = re.findall(pattern4, js_code) + + pattern5 = r"h\.href\.includes\('(.*?)'\)" + matches5 = re.findall(pattern5, js_code) + + return matches1+matches2+matches3+matches4+matches5 + +def regex_to_include_line(regex): + #regex = regex.strip("/") + regex = '(' + regex + ')' + include_line = "// @include /^(https?:\/\/)(.+)?" + regex + "(\/.*)/" + include_line = include_line.replace( "\.*)(\/.*)/", "\.*)/" ) #clean excess in the 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') as file: + for line in lines: + file.write(line + '\n') + print(f"OK: Generated {filename}") + +def compile_and_print(regex_strings): + #for regex_string in regex_strings: print(regex_string) + #write_to_file('regexs.txt', regex_strings) + + include_lines = generate_include_lines(regex_strings) + print(f"OK: Generated {len(include_lines)} include lines.") + + #for line in include_lines: print(line) + write_to_file('includes.txt', include_lines) + +def filter_strings(input_list): + filtered_list = [string for string in input_list if "." in string and len(string) >= 4] + return filtered_list + +def main(): + file_path = 'untouched_Bypass_All_Shortlinks.user.js' + + try: + with open(file_path, 'r', encoding='utf-8') as file: + js_code = file.read() + regex_strings = extract_regex_from_js(js_code) + regex_strings = filter_strings(regex_strings) + compile_and_print(regex_strings) + except FileNotFoundError: + print(f"Error: File '{file_path}' not found.") + except Exception as e: + print(f"An error occurred: {e}") + +if __name__ == "__main__": + main() diff --git a/3_patch.py b/3_patch.py new file mode 100644 index 0000000..fe1b645 --- /dev/null +++ b/3_patch.py @@ -0,0 +1,67 @@ +def modify_script(input_script_path, includes_file_path, output_script_path): + # Read the content of the input script + with open(input_script_path, 'r') as input_file: + script_lines = input_file.readlines() + + # Find the last line that starts with "// @description:" + last_description_line_index = None + for i in range(len(script_lines) - 1, -1, -1): + if script_lines[i].startswith('// @description:'): + last_description_line_index = i + break + + # Read the content of the includes file + with open(includes_file_path, 'r') as includes_file: + includes_content = includes_file.read() + + # Remove lines starting with "// @include" + script_lines = [line for line in script_lines if not line.startswith('// @include')] + + # Insert includes content after the last description line + script_lines.insert(last_description_line_index + 1, includes_content) + + # Write the modified script to the output file + with open(output_script_path, 'w') as output_file: + output_file.writelines(script_lines) + + print(f"OK: @Include lines added. Script successfully modified and saved to {output_script_path}.") + + +def modify_script_extra(file_path): + try: + with open(file_path, 'r') as file: + content = file.read() + + #Change title + content = content.replace("// @name Bypass All Shortlinks", "// @name Bypass All Shortlinks Debloated") + + #Change source URL + content = content.replace("https://update.greasyfork.org/scripts/431691/Bypass%20All%20Shortlinks.user.js", + "https://codeberg.org/Amm0ni4/bypass-all-shortlinks-debloated/raw/branch/main/Bypass_All_Shortlinks.user.js") + content = content.replace("https://update.greasyfork.org/scripts/431691/Bypass%20All%20Shortlinks.meta.js", + "https://codeberg.org/Amm0ni4/bypass-all-shortlinks-debloated/raw/branch/main/Bypass_All_Shortlinks.user.js") + + #Remove tracking + content = content.replace("'https://rotator.nurul-huda.sch.id/?BypassResults=' + url", "'' + url") + content = content.replace("let respect = 'https://free4u.nurul-huda.or.id/?BypassResults=';", "let respect = '';") + content = content.replace("\n// @antifeature tracking", "") + + + # Write the modified content back to the file + with open(file_path, 'w') as file: + file.write(content) + + print("OK: Extra Modifications completed successfully.") + + except FileNotFoundError: + print(f"File '{file_path}' not found.") + except Exception as e: + print(f"An error occurred: {e}") + + +# Example usage +input_script_path = 'untouched_Bypass_All_Shortlinks.user.js' +includes_file_path = 'includes.txt' +output_script_path = 'Bypass_All_Shortlinks.user.js' +modify_script(input_script_path, includes_file_path, output_script_path) +modify_script_extra(output_script_path) diff --git a/README.md b/README.md new file mode 100644 index 0000000..d6826b7 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +Automatically bypass many shortlink sites to skip annoying link shorteners, such as AdFly and Linkvertise, without ads. Reach your destination link more directly. + +## Install +Install by clicking this link with the [raw text for the file Bypass_All_Shortlinks.user.js](https://codeberg.org/Amm0ni4/bypass-all-shortlinks-debloated/raw/branch/main/Bypass_All_Shortlinks.user.js) + +(you need a userscript manager like [Violentmonkey](https://violentmonkey.github.io/) installed in your web browser) + +## Improvements in this fork +- The script will be loaded only for the sites that are supported. (the original userscript is loaded in every site you visit which is not necessary) +- The script will not redirect to 'rotator.nurul-huda.sch.id' or 'free4u.nurul-huda.or.id' before your destination URL, which are intermediary sites set by the developer for [collecting analytics](https://i.ibb.co/D1zYG1v/topcountry17-04-2023.jpg) and showing ads. + +Original script by *bloggerpemula*: https://greasyfork.org/scripts/431691 + +## How I modify the original userscript +Executing these 3 python scripts in order: +- 1_download_untouched.py +- 2_generate_includes.py +- 3_patch.py