I just want to be able to save, refresh the page, and have my changes show up like I do in Firefox. Having to drag it over and install it every time gets annoying.
Any ideas?
Yes, there is a way to do this. Using the method adopted from this brilliant answer (^_^), you can edit scripts -- in place -- and just hit a "Reload" link for the changes to take effect.
This method has the added bonus that Chrome's Extensions folder1 doesn't get cluttered with indecipherable folder and file names, and you can easily find the script you want to tweak.
Here's how to set up your work environment to allow easy script updating:
Create a directory that's convenient to you, and not where Chrome normally looks for extensions1. For example, Create: C:\MyChromeScripts\
.
This will be where all your scripts will reside in the future.
For each script create its own subdirectory. For example, Script_1
, Script_2
, etc.
Each subdirectory should contain its script, EG MyScript1.user.js
, and any files used by that script.
Now for the secret sauce... You must also create a manifest file in that subdirectory, and it must be named: manifest.json
.
Sample contents, at a minimum:
{
"manifest_version": 2,
"content_scripts": [ {
"exclude_globs": [ ],
"include_globs": [ "*" ],
"js": [ "MyScript1.user.js" ],
"matches": [ "https://stackoverflow.com/*",
"https://stackoverflow.com/*"
]
} ],
"description": "This script does X, Y, and Z.",
"name": "My script number 1",
"version": "1"
}
Now, in Chrome's Extension manager (URL = chrome://extensions/), Expand Developer mode.
Click the Load unpacked extension... button.
For the folder, paste in the folder for your script, For example:C:\MyChromeScripts\Script_1
.
Your script will be installed and operational.
Keep the Extensions page open. Now, when you save any changes to your *.js file, Hit the Reload link for them to take effect immediately.
Enjoy!
1 The extensions folder defaults to:
Windows XP: C:\Documents and Settings\***{username}***\Local Settings\Application Data\Google\Chrome\User Data\Default Windows Vista: C:\Users\***{username}***\AppData\Local\Google\Chrome\User Data\Default Windows 7: C:\Users\***{username}***\AppData\Local\Google\Chrome\User Data\Default
Although you can change it by running Chrome with the --user-data-dir=
option.
You can do that if you have somewhere server where you can import your changed file.
Like this
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://server.url/Custom/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function addScript(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://server.url/Custom/Custom script.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
// load jQuery and execute the init function
addJQuery(addScript);
This loads first jQuery then my custom script, when i run the webpage it always reloads the whole script.
Maybe this helps you too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With