tengwer Posted December 5, 2009 Share Posted December 5, 2009 I was given a script to use a while ago that inserts code into a web page. The script was from Dale as follows: #include <IE.au3> Global $oIE, $sScriptSrc $oIE = _IECreate("http://www.netbiblestudy.net/new_page_9.htm") ObjEvent($oIE, "evtWin_", "DWebBrowserEvents2") _IEAction($oIE, "refresh") ; Only needed for initial page to trigger downloadcomplete processing While True Sleep(1000) WEnd Exit ;------------------------------------------ ; Functions ;------------------------------------------ Func evtWin_onquit() ; Browser run down, exit Exit EndFunc ;==>evtWin_onquit Func evtWin_downloadcomplete() Local $s_script If $sScriptSrc = "" Then Local $o_XHR = ObjCreate("MSXML2.XMLHTTP") ; Init the Ajax object $o_XHR.open("GET", "http://bible.logos.com/jsapi/referencetagging.js", False) $o_XHR.Send() $sScriptSrc = $o_XHR.responseText EndIf IEHeadInsertScript($oIE, $sScriptSrc) $s_script = 'Logos.ReferenceTagging.lbsBibleVersion = "ESV";' $s_script &= 'Logos.ReferenceTagging.lbsLinksOpenNewWindow = true;' $s_script &= 'Logos.ReferenceTagging.lbsAddLibronixDLSLink = true;' $s_script &= 'Logos.ReferenceTagging.lbsLibronixBibleVersion = "NIV";' $s_script &= 'Logos.ReferenceTagging.lbsLibronixLinkIcon = "dark";' $s_script &= 'Logos.ReferenceTagging.lbsNoSearchTagNames = [ ];' $s_script &= 'Logos.ReferenceTagging.tag();' IEEval($oIE, $s_script) EndFunc ;==>evtWin_downloadcomplete Func IEEval($o_object, $s_eval) Return $o_object.document.parentwindow.eval($s_eval) EndFunc ;==>IEEval Func IEHeadInsertScript($o_object, $s_script) Local $o_head, $o_element $o_head = _IETagNameGetCollection($o_object, "head", 0) $o_element = $o_object.document.createElement('script') $o_element.type = 'text/javascript' $o_element.text = $s_script $o_head.appendChild($o_element) Return 1 EndFunc ;==>IEHeadInsertScript This is a wonderful script and works well for many web pages. By inserting the html within to the web page (namely the $s_script code) I am able to link to my bible study software from the web page. Once in a while, however, I find there is another script within the web page that overides mine. Is there a way to add some code to the above example to do the opposite- that is to remove some html from the page as oppossed to adding it? In many cases I can find out what html needs to be removed from the page in order for the script above to have the priority. A search and replace for html in the web page could even do the trick. Anyone have any ideas? Link to comment Share on other sites More sharing options...
DaleHohm Posted December 5, 2009 Share Posted December 5, 2009 It is possible, the technique to use varies based on the type of content you need to counteract. I have, for example, overridden the javascript built-in "prompt" function with my own script simply by using IEHeadInsertScript and adding the function I wanted called instead. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
tengwer Posted December 6, 2009 Author Share Posted December 6, 2009 It is possible, the technique to use varies based on the type of content you need to counteract. I have, for example, overridden the javascript built-in "prompt" function with my own script simply by using IEHeadInsertScript and adding the function I wanted called instead.DaleThe problem I have is that the script using IEHeadInsertScript does not overide some of the scripts. FOr instance, if the web page already has the Reference Tagger script in it then it takes precidence over my own Reference Tagger script. I have found that if I use Firebug in Firefox and maunally replace pieces of the script with "" then this effectively breaks the script and then when I insert my script it works. I'm looking for a way to do this search and replace on a live web site using a script. The Reference tagger script is as follows:<!-- RefTagger from Logos. Visit http://www.logos.com/reftagger. This code should appear directly before the </body> tag. --><script src="http://bible.logos.com/jsapi/referencetagging.js" type="text/javascript"></script><script type="text/javascript"> Logos.ReferenceTagging.lbsBibleVersion = "ESV"; Logos.ReferenceTagging.lbsLinksOpenNewWindow = true; Logos.ReferenceTagging.lbsLibronixLinkIcon = "dark"; Logos.ReferenceTagging.lbsNoSearchTagNames = [ "h1", "h2", "h3" ]; Logos.ReferenceTagging.tag();</script>This script is inserted into certain web sites and it varies dependcing on what the web designer wants it to do. Sometimes it is designed to not have a link to open my bible study prgram and sometimes it is designed with this link. If it is not designed to allow me to link to my program then when I use your script to as it to do so the internal script of the web site takes precidence and mine does nothing. The script you designed works great when there is no already existing Reference Tagger codee in the web page. What I did was manually replace the "logos.referencetagging" of the web page with "". This broke that script and then allowed mine to work. Can you demonstrate a way to add this search and replace functionality to the script you originally gave me? Link to comment Share on other sites More sharing options...
DaleHohm Posted December 8, 2009 Share Posted December 8, 2009 I presume that the javascript that is causing you trouble includes named functions. If you define a new function of the same name AFTER theirs is loaded, then yours will win. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now