javascript - How can I grab script tag calling jquery's cdn in the body and remove it before jQuery loads? -
i have uncommon problem.
i don't have access head or database company's drupal website, however, i'm building "plugin" site using provided "js injector".
i hack away locally , copy/paste javascript right injector (i can't think of worse development environment think of it, product development takes forever).
in haste, accidentally put in call jquery need locally. killed page, mostly, because calling jquery twice bad. page paint/css renders can't access of management modules edit node updated can fix issue.
since "customize page" make ajax call initialize of drupal backend ui stuff. idea access js injector internal page i've setup , run script somehow "reach in" , remove call jquery before gets rendered.
i possible grab script it's source? can't use jquery remove second jquery script on page...can i? hurts asking.
here exact script i'm trying remove, there no type attribute. 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 possible?
td;dr removing call jquery before jquery loads.
solution (thanks 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 })
ok, here's try. install firefox, greasemonkey extension, allow inject js pages browser. greasemonkey scripts allow @run-at document-start
directive (read manuals), means gonna run before html loaded. now, have think of way magic jquery. tried this, , works:
// ==userscript== // @name test // @namespace test // @include http://manage/arena/* // @version 1 // @grant none // @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 })
as see, here capture first loaded jquery object , save it. in case tries reassign window.jquery
property (for example, new <script>
tag), script catches , returns old value.
included noconflict
call every time new jquery built. don't know if need (look source code of website know if .nocoflict()
), maybe have stuff window.$
instead of window.jquery
; maybe both. anyway, believe idea. hope helps. don't forget man window.watch
, works in firefox.
Comments
Post a Comment