I'm running into issues with an existing userscript that works few months ago but not anymore.
// ==UserScript==
// @namespace http://www.mysite.com
// @author Vadorequest
// @license GNU GPL v3
// @include mysite.com/index.php (I had to remove the http:// because of SO security)
// @include www.mysite.com/index.php
// @include mysite.com/*
// @include www.mysite.com/*
// @version 1.6
// @require https://code.jquery.com/jquery-1.11.0.min.js
// ==/UserScript==
// Inject a custom script from one of my servers, allow me to change the source code without changing the userscript itself. Use jQuery.
My old way to use jQuery was to copy/paste jQuery script iself inside my user script, at the time I didn't find any other solution. But it's not what I should do.
The biggest problem now is that the script is loaded in all pages, in facebook, google, etc. Not only on the targeted website. Before, it worked. so I don't really get it. Maybe something changed in chrome. I guess so.
I'm currently reading Manually adding a Userscript to Google Chrome at the same time I'm writing this thread, it looks like things changed few months ago.
But it's confusing, should I use the manifest.json
?
Anyway, I'll explain how my script works because it's a bit tricky:
- Userscript contains jQuery and create a DOM element in the
head
that import my custom script. - My custom script is imported and run as if it was imported by the original webpage, not in some weird sub frame part.
Why? It allows me to dev quite quickly, because I don't need to change the userscript itself, just the script injected. My changes are applied on a simple save & upload
, much better than distribute the userscript to all users. (Because it's not a public userscript and I won't add it on userscript.com or whatever)
I had issues at the time to make it work with jQuery, and later with jQuery.ui, I need both. (I wrote it 4 years ago)
So, is there a better efficient way to do this now? I guess I need to be updated on this, if you have any advice or good tutorial, don't hesitate! I'll try the way with the manifest.json
.