// ==UserScript== // @name Modify Bundle.js and HTML // @namespace…
- User
// ==UserScript== // @name Modify Bundle.js and HTML // @namespace http://yourwebsite.com // @version 0.1 // @description Modify bundle.js to replace var Config with window.Config and overwrite HTML with grabbed HTML and JS file // @author Your Name // @match http://example.com/* // Replace with the URL of the site you want to modify // @grant none // ==/UserScript==
(function() { 'use strict';
code// Function to replace var Config with window.Config function modifyBundleJS() { const scriptElements = document.querySelectorAll('script'); scriptElements.forEach(script => { if (script.src.endsWith('bundle.js')) { fetch(script.src) .then(response => response.text()) .then(data => { const modifiedData = data.replace(/var Config =/g, 'window.Config ='); const blob = new Blob([modifiedData], { type: 'application/javascript' }); const url = URL.createObjectURL(blob); const newScript = document.createElement('script'); newScript.src = url; document.body.appendChild(newScript); }); } }); } // Function to replace HTML content with grabbed HTML and JS file contents function overwriteHTML() { fetch('index.html') // Replace 'index.html' with the path to your grabbed HTML file .then(response => response.text()) .then(html => { document.open(); document.write(html); document.close(); }); } // Call the functions to modify bundle.js and overwrite HTML modifyBundleJS(); overwriteHTML(); - Assistant
- User
Im trying to delete a script the site is using and replace it with my onw
- Assistant
- User
There is a local variable inside bundle.js called config, and I want to be able to somehow access it from console. How can I do that?
- Assistant
- User
if I do debugging in the browser and set the config variable to something else, will it save?
- Assistant
When you use the browser's debugger to set a variable during a debugging session, any changes you make will only persist for the duration of that page load. As soon as you refresh the page or navigate away, all your changes will be lost, and the script will execute again as it was originally written.
Here's what happens when you modify variables through the browser's debugging tools:
- Modifications to the variable are temporary and only apply to the current state of the running JavaScript environment in the browser.
- They allow you to test changes and see their immediate effects on the current page state without permanently altering the script's source code.
- Once the page reloads or a new page is loaded, the script re-executes in its original form, and the variable will be reset to whatever value the script initially gives it.
If you need the changes to be persistent across page reloads, you will need to permanently alter the JavaScript source code, either on the server or by using a Userscript that runs each time the page loads and applies your changes automatically. Userscripts, as discussed previously, can modify or replace parts of the JavaScript loaded by a web page, effectively letting you set the variable to something else each time the page is loaded.