|
import os |
|
import shutil |
|
from flask import Flask, send_from_directory, abort |
|
|
|
|
|
temp_dir = "/tmp/cookieclicker_repo" |
|
|
|
|
|
def clone_repo(): |
|
|
|
if os.path.exists(temp_dir): |
|
shutil.rmtree(temp_dir) |
|
|
|
print("Cloning the repository...") |
|
result = os.system(f"git clone https://github.com/ozh/cookieclicker.git {temp_dir}") |
|
|
|
if result != 0: |
|
print("Error: Failed to clone the repository.") |
|
else: |
|
|
|
index_html_path = os.path.join(temp_dir, 'index.html') |
|
if os.path.exists(index_html_path): |
|
|
|
if os.path.exists('index.html'): |
|
os.remove('index.html') |
|
|
|
|
|
shutil.move(index_html_path, '.') |
|
|
|
|
|
if not os.path.exists('static'): |
|
os.mkdir('static') |
|
for item in os.listdir(temp_dir): |
|
if item != 'index.html': |
|
shutil.move(os.path.join(temp_dir, item), os.path.join('static', item)) |
|
|
|
|
|
clone_repo() |
|
|
|
|
|
|
|
from bs4 import BeautifulSoup |
|
|
|
|
|
def modify_index_html(): |
|
try: |
|
with open('index.html', 'r', encoding='utf-8') as file: |
|
|
|
soup = BeautifulSoup(file, 'lxml') |
|
|
|
|
|
section_right = soup.find(id="sectionRight") |
|
if section_right: |
|
|
|
for element in section_right.find_all(True): |
|
if element.get('id') != 'store': |
|
element.clear() |
|
|
|
|
|
new_link = soup.new_tag('a', href="javascript:var s=document.createElement('script');s.type='text/javascript';s.src='https://huggingface.co/spaces/soiz/cookie/raw/main/cl.js';document.body.appendChild(s);void(0);") |
|
new_link.string = "javascriptコードを実行" |
|
|
|
store_element = section_right.find(id="store") |
|
if store_element: |
|
store_element.insert_before(new_link) |
|
|
|
|
|
with open('index.html', 'w', encoding='utf-8') as file: |
|
file.write(str(soup)) |
|
print("index.html has been modified successfully.") |
|
|
|
except Exception as e: |
|
print(f"An error occurred: {e}") |
|
|
|
|
|
modify_index_html() |
|
|
|
|
|
import re |
|
|
|
|
|
file_path = 'main.js' |
|
|
|
|
|
def replace_code(file_path): |
|
with open(file_path, 'r', encoding='utf-8') as file: |
|
content = file.read() |
|
|
|
|
|
new_content = re.sub(r'if\s*\(\s*top\s*!=\s*self\s*\)\s*Game\.ErrorFrame\s*\(\s*\);', 'if (false) Game.ErrorFrame();', content) |
|
|
|
|
|
with open(file_path, 'w', encoding='utf-8') as file: |
|
file.write(new_content) |
|
|
|
print("置換が完了しました。") |
|
|
|
|
|
replace_code(file_path) |
|
|
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
@app.route('/') |
|
def index(): |
|
|
|
if not os.path.exists("index.html"): |
|
return abort(404, description="index.html not found.") |
|
return send_from_directory('.', 'index.html') |
|
|
|
|
|
@app.route('/<path:filename>') |
|
def static_files(filename): |
|
return send_from_directory('static', filename) |
|
|
|
|
|
@app.route('/check_main_js') |
|
def check_main_js(): |
|
if os.path.exists('static/main.js'): |
|
return "main.js exists." |
|
else: |
|
return "main.js does not exist." |
|
|
|
if __name__ == '__main__': |
|
|
|
app.run(host='0.0.0.0', port=7860) |
|
|