I have an uncommon problem.
I don't have access to the head or the database for the company's Drupal website, however, I'm building a "plugin" for the site using the provided "JS Injector".
I hack away locally and just copy/paste my javascript right into the injector (I can't think of a worse development environment now that I think of it, product development takes forever).
In my haste, I accidentally put in my call to jQuery that I need locally. This killed the page, mostly, because calling jQuery twice is bad. The page paint/CSS renders but I can't access any of the management modules to edit the node I updated so I can fix the issue.
Since the "Customize This Page" make an ajax call to initialize any of the Drupal backend UI stuff. My idea is to access the JS Injector from another internal page that I've setup and run a script that could somehow "reach in" and remove my call to jQuery before it gets rendered.
I it possible to grab a script by it's source? I can't use jQuery to remove a second jQuery script on the page...can I? That hurts just asking.
Here is the exact script I'm trying to remove, there is no type attribute. Just a src:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
function getScript()
{
var s;
s = document.getElementsByTagName('script');
if(s.querySelector('[src]') === "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"){
this.remove;
}
}
removeScript();
is something like this possible?
td;dr removing a call to jquery before jquery loads.
SOLUTION (thanks to Serge Seredenko):
// ==UserScript==
// @name test script
// @namespace test
// @include http://your.website.com/
// @version 1
// @grant unsafeWindow
// @run-at document-start
// ==/UserScript==
unsafeWindow.watch('jQuery', function(i, o, n) {
n.noConflict()
if (unsafeWindow.__old_jQuery)
return unsafeWindow.__old_jQuery
unsafeWindow.__old_jQuery = n
return n
})