Jump to content

Code to remove hyperlinks from a doc/webpage.


 Share

Recommended Posts

I am not even sure what I am asking here is possible, but what command/function could I use so that when you selected Remove Hyperlinks from the drop down menu from the tray icon it would do just that, and the same for reinstate hyperlinks.

Or what better way to go about this?

Any ideas?

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)

$prefsitem  = TrayCreateItem("Remove Hyperlinks")
TrayCreateItem("")
$aboutitem  = TrayCreateItem("Reinstate Hyperlinks")
TrayCreateItem("")
$exititem   = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $prefsitem
            Msgbox(64, "Remove Hyperlinks:", "???" & @COMMAND to remove hyperlinks)
        Case $msg = $aboutitem
            Msgbox(64, "Reinstate Hyperlinks:", "!!!" & reinstate hyperlinks function)
        Case $msg = $exititem
            ExitLoop
    EndSelect
WEnd

Exit

P.S. My AutoIt tags never work so I have been using plain code tags.

Edited by schilbiz
Link to comment
Share on other sites

I would use RegExp for this task. Something like:

$output_text = StringRegExpReplace($input_text, "(?s)<a.+?</a>", "")

But what you mean as "reinstate"?

BTW: for me tags don't work as well. But you can just type it manually.

[autoit][/autoit]
Edited by Lazycat
Link to comment
Share on other sites

I am not even sure what I am asking here is possible, but what command/function could I use so that when you selected Remove Hyperlinks from the drop down menu from the tray icon it would do just that, and the same for reinstate hyperlinks.

Or what better way to go about this?

Any ideas?

If you want to do that to an open Word Doc, then work with the Word COM interface. If you want it for IE, work with the IE DOM. If you want it for Firefox... give up now.

Wouldn't that be applications specific? You want an AutoIt script that will do that to anything?

<_<

P.S. My AutoIt tags never work so I have been using plain code tags.

Known bug. Upon hearing that Jon intended to eliminate the AutoIt Forum Edit Bug, the World Wildlife Federation, Friends Of The Earth, PETA, and an even dozen Gaia worshippers sued him and received an injunction from a Judge (whom they threated to picket and throw fake blood upon). Jon is now attending court-mandated Endangered Bug Sensitivity Training, and when that is complete, will be required to protect and preserve the remaining population of Forum Bugs.

Donation to the newly established Save The Forum Bug foundation can be made online.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I would use RegExp for this task. Something like:

$output_text = StringRegExpReplace($input_text, "(?s)<a.+?</a>", "")

But what you mean as "reinstate"?

BTW: for me tags don't work as well. But you can just type it manually.

[autoit][/autoit]

Thanks for the tip on the code tag, what i mean by reinstate is that when you click on "Reinstate Hyperlinks" they would reappear (underlined etc). The issue is that I look at documents that have a lot of hyperlinks with comments assocaited with them so as I am reading documents/webpages I get these annoying popup messages.

If you could somehow remove them while you are reading that would be nice, I would use it all the time. For work and pleasure.

With the command you are suggesting how would you know what is a hyperlink?

Thanks

Link to comment
Share on other sites

If you want to do that to an open Word Doc, then work with the Word COM interface. If you want it for IE, work with the IE DOM. If you want it for Firefox... give up now.

Wouldn't that be applications specific? You want an AutoIt script that will do that to anything?

<_<

Known bug. Upon hearing that Jon intended to eliminate the AutoIt Forum Edit Bug, the World Wildlife Federation, Friends Of The Earth, PETA, and an even dozen Gaia worshippers sued him and received an injunction from a Judge (whom they threated to picket and throw fake blood upon). Jon is now attending court-mandated Endangered Bug Sensitivity Training, and when that is complete, will be required to protect and preserve the remaining population of Forum Bugs.

Donation to the newly established Save The Forum Bug foundation can be made online.

:)

Wouldn't that be applications specific? You want an AutoIt script that will do that to anything?

Yes if it is possible because I use multiple apps like most people, Excel, Word, Email, E-books, Webpages etc that have stinking hyperlinks.

I have looked at - _WordDocAddLink, $oLinks = _WordDocLinkGetCollection ($oDoc) $oLinks = _IELinkGetCollection ($oIE) etc so there is a way to add links you would think there would be a way to remove links as well. I am very new to AutoIt so my understanding of the funcs is limited.

Link to comment
Share on other sites

Yes if it is possible because I use multiple apps like most people, Excel, Word, Email, E-books, Webpages etc that have stinking hyperlinks.

I have looked at - _WordDocAddLink, $oLinks = _WordDocLinkGetCollection ($oDoc) $oLinks = _IELinkGetCollection ($oIE) etc so there is a way to add links you would think there would be a way to remove links as well. I am very new to AutoIt so my understanding of the funcs is limited.

That's the point. _WordDocAddLink will only function on a Word doc. And _IELinkGetCollection only works on IE. They are very application specific. You would have to research a separate method for each application. Some apps, like Firefox, don't expose that type of COM interface at all. So a catch-all solution is likely impossible.

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks for the tip on the code tag, what i mean by reinstate is that when you click on "Reinstate Hyperlinks" they would reappear (underlined etc). The issue is that I look at documents that have a lot of hyperlinks with comments assocaited with them so as I am reading documents/webpages I get these annoying popup messages.

If you could somehow remove them while you are reading that would be nice, I would use it all the time. For work and pleasure.

With the command you are suggesting how would you know what is a hyperlink?

Thanks

Right, like PsaltyDS say, this depends.

This simple, if you have HTML file saved somewhere. In this case you can use StringRegExpReplace to hide hyperlinks and then then open clean document in any browser. Then you can revert hyperlinks back.

A more complicated if you want use this function with pages directly loaded from internet, probably IE.au3 UDF can help - in script controlled IE window of course. Seems firefox have some COM wrapper too. With Opera - looks like no way, maybe only with some user Javascript.

With docs this maybe a tricky (not sure, I'm not expert with Word object model). But I think the biggest problem here: you can find and remove link, but you also should in some way remember where the link was and which of removed links was here.

Link to comment
Share on other sites

For a webpage in IE it is as simple as

$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
    $oLink.href = ""
Next

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

Try this for removing the links.

#include <IE.au3>

$sURL = "www.msn.com"

_IEErrorHandlerRegister()
$oIE = _IECreate($sURL)
$oLinks = _IELinkGetCollection($oIE)

For $oLink In $oLinks
    $oLink.removeNode
Next

MsgBox(0, "", "The links should now be gone.")

Interesting, it does remove the links for the specified url and the annoying popup comments.

All I have to do now is set it up so that when I execute the script it will ask for a url and insert it into "$sURL = "www.???.com"".

That will cover the webpage aspect of it.

Thanks

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...