Skip navigation.

Combining VBScript, Opera and Javascript for effective functions.

, , ,

Although VBScript is seemed to be a language only windows users can use, it can come in useful when automating commands in Opera can be a pain.

DIM Wsh,ArgObj,var1
Set ArgObj = WScript.Arguments
Set Wsh = WScript.CreateObject("WScript.Shell")
var1 = ArgObj(0) 
if var1 = "source" then
Do Until Wsh.AppActivate ("Selection source for")
WScript.Sleep 500
Loop
Wsh.SendKeys "^a"
Wsh.SendKeys "^c"
Wsh.SendKeys "^{F4}"
else 
Do Until Wsh.AppActivate ("Links Selected for")
WScript.Sleep 500
Loop
Wsh.SendKeys "^a"
Wsh.SendKeys "^c"
Wsh.SendKeys "^{F4}"
end if
Set Wsh = nothing
WScript.Quit


Here is example code of a VBScript,save this as copy.vbs and save it in your main program files > opera folder, what the script does is it looks for the active window title, then sends the key commands to copy the content and close the tab creating the content. One is for the selection source bookmarklet which is found here: http://my.opera.com/community/forums/topic.dml?id=140523

Here is an example to put in menu.ini file to run the VBScript first then run the javascript code.

Item, "Copy selected links/All links" = Execute Program, "copy.vbs","selectlinks" & Go to page, "javascript:(function(){ var html_selection=document.createElement('div'); var yay=[];  if(document.getSelection()){ html_selection.appendChild(window.getSelection().getRangeAt(0).cloneContents()); } if(!html_selection.getElementsByTagName('a')[0]) { document.designMode='on';document.execCommand('selectall', false, null);html_selection.appendChild(window.getSelection().getRangeAt(0).cloneContents());document.links[0].focus();document.designMode='off'; } var hmm=html_selection.getElementsByTagName('a'); for(var i=0;i<hmm.length;i++) {yay[i]=hmm[i].href};var ty=window.open();ty.document.write('<title>Links Selected for '+location.href+'</title>'+yay.toString().replace(/\,/g,'
'));ty.document.close();})(); "


This javascript function copies selected links to the clipboard, or copies all links of the page if no selection or the selection contains no links.

These are just examples of how VBScript can help Windows Opera users extend Opera's functionalities a tiny bit more :smile:

Sidebar InspectingPutting those spare mouse buttons to use(and then some..)

Comments

ilyabirman 19. December 2006, 18:38

I read your post several times and still cannot get what this thing does :-)

shoust 17. January 2007, 20:37

Well it copies all links to clibpboard using a combo of vbscript(called via external program) and javascript.

Lex1 27. January 2007, 09:19

The similar is used in oGet
Platform Windows, Item, "Download Selection with oGet"="Execute program, "D:\Opera\scripts\clip2txt.exe","%u",,"Save" & Go to Page, "javascript:(function(){var lnks, text, re, rearray; var a_links=''; var t_links=''; var html_selection=document.createElement('div'); html_selection.appendChild(window.getSelection().getRangeAt(0).cloneContents()); lnks = html_selection.getElementsByTagName('a'); for(var i=0, li; li=lnks[i]; i++){a_links+= '<a href=\''+li.href+'\'>'+li.innerText+'</a>'}; text=html_selection.innerText.replace(/h..p:\/\//gi,'http://').replace(/f.p:\/\//gi,'ftp://'); re=/((?:https|http|ftp|mms|rtsp):\/\/[^\s\x22<>\{\}\'\(\)]+)/gi; while(rearray=re.exec(text)){t_links+= '<a href=\''+rearray[1]+'\'></a>'}; prompt('Please wait...', a_links+t_links);})()"" 

And vbs (This simple send Ctrl+C and Esc)
DIM Wsh 
Set Wsh = WScript.CreateObject("WScript.Shell")
Do Until Wsh.AppActivate ("JavaScript")
WScript.Sleep 100
Loop
Wsh.SendKeys "^c"
Wsh.SendKeys "{esc}"
Set Wsh = nothing
WScript.Quit

AyushJ 5. March 2007, 08:02

Why VBS ? You can do this with JS(not tested) :

arg1 = WScript.Arguments(0)
Wsh = new ActiveXObject("WScript.Shell")
if(arg1=="source"){
do{ WScript.Sleep(100) }while(!Wsh.AppActivate ("Selection source for"))
Wsh.SendKeys("^a")
Wsh.SendKeys("^c")
Wsh.SendKeys("^{F4}")
}else{
do{ WScript.Sleep(100) }while(!Wsh.AppActivate("Links Selected for"))
Wsh.SendKeys("^a")
Wsh.SendKeys("^c")
Wsh.SendKeys("^{F4}")
}


btw, you can combine the keys in one line:
Wsh.SendKeys("^a^c^{F4}")

shoust 5. March 2007, 19:54

Opera doesn't support activeX. So the example won't work in Opera

AyushJ 6. March 2007, 05:28

I know but because most people here know about JS so it is better to provide something in js. You can execute the js in same way as vbs(using wscript or cscript).

hallvors 23. July 2007, 16:04

Wow, that's creative use of the Windows scripting host :-)

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.