Unable to open a javascript bookmarklet I created in new window or tab - bookmarklet

First off I know very little about code and learn from looking at how other example work.
I've created a bookmarklet that works fine, but I really want it to open in a new tab or window.
Here is the code currently being used:
<a href='javascript:q = "" +(window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text); if (!q) q = prompt("Find the QSR of a search phrase, Simply enter a phrase wrapped in Quotes", ""); if (q!=null) location="http://www.google.com/search?q= " + escape(q).replace(/ /g, ""+"")+"&start=900#" ; void 0' ;
<font color="#000000">QSR</font></a>
So the idea behind this bookmarklet is to find the total number of search results Google has has a phrase wrapped in quotes. Clicking on QSR you would enter the phrase in quotes, What I'd like is when you click OK, it opens in a new tab or window.
I also noticed that if I highlight some text on a page and then press my QSR bookmarklet it will use the highlighted text to perform the search, but again I need this to open in a new tab or window.
I've been trying to figure this out but not having any luck, is this even possible?
Any help is greatly appreciated.
Craig

Change
location="http://www.google.com/search?q= " + escape(q).replace(/ /g, ""+"")+"&start=900#"
to
window.open("http://www.google.com/search?q= " + escape(q).replace(/ /g, ""+"")+"&start=900#")

Related

Is there an option to add equals and parenthesis when using autocomplete in an XML document?

I've been working in an XML editor and I'm also working on adding XML autocomplete support in Ace editor.
I'm trying to find if there's an option to automatically add the equals sign and parenthesis and then set the cursor inside the parenthesis when using autocomplete suggestion. I've seen this feature in the other XML editor.
For example, if I'm typing the following word, "lab":
<s:Button lab| />
and then press CTRL+space it will invoke suggestions. Then if I choose "label" from the suggestions list the suggested word, "label" is written for me, an equals sign and parenthesis' are placed after it and the cursor is placed inside as shown below:
<s:Button label="|" />
Is there a way to do this?
I have to set the type property to "snippet" and then set the snippet property to what I want to autocomplete:
var autoCompleteObject = new Object();
autoCompleteObject.value = "Greetings";
autoCompleteObject.type = "snippet";
autoCompleteObject.snippet = "Hello ${1:World}. Welcome to ${2:Earth}";
When your editor uses the object shown above then when the user is using your editor and selects, "Greetings" from the auto complete menu, the text "Hello World. Welcome to Earth" is inserted into the document.
The word "World" is selected and the user can change it or leave it as is. When the user presses tab again the word, "Earth" is selected and shklhee has the same option as before. You can use an empty object to just place the cursor "${3}".
The numbering is the order that the tokens are selected in.

Searching on pressing enter button using selenium not working with Firefox

I have the below code. What I actually want to do is enter a string in text field and click on enter. Then search results should be displayed.
But here on 'element.sendKeys(Keys.ENTER);' application logs out. I checked with URLs. URLs should be same after searching.But it changes here.
This code works for Chrome and IE. Issue only with Firefox only.I checked the element type to confirm the clicking. It was text box only.
public static void pressEnterKey(WebDriver driver,WebElement element){
System.out.println("Current URL1" + driver.getCurrentUrl());
WebElementType elementType = WebElementHelper.findElementType(element);
System.out.println("Element Type = " + elementType);
element.sendKeys(Keys.ENTER);
System.out.println("Current URL2" + driver.getCurrentUrl());
}
There is a bug report regarding this issue, it seems to be specific with .NET and FireFox.
See here:
https://code.google.com/p/selenium/issues/detail?id=2079
The result would be to use
element.sendKeys(Keys.Return);
If the sole purpose is to click on the "Enter" button, instead of sending "Enter" keys why not click on the respective element.
Just replace the code element.sendKeys(Keys.ENTER); in your code above with either of the below code(s):
element.click();
OR
element.submit();
On another note, as per the definition, sendKeys method is used to type into an element. And, I am pretty sure you can't type into a button. :)

IF Statements and Conditions for iMacros Firefox

So I'm trying to make a macro to catch Pokemon from maps in this game but there if you encounter a Turf War it will show this image:
As you can see the click button says "Lets Battle!" and it redirects you to a battle link.
However, I want to make an if statement that if I encounter this battle link I would refresh the page instead and let me go here.
Does anybody know how to code if statements for this?
So here's how I want it to work:
if (it encounters the Turf Battle)
will click another link
else
keep clicking the map to catch using the click x and y
EDIT: I tried this syntax:
if (TAG POS=1 TYPE=H2 ATTR=TXT:You<SP>Don't<SP>Belong<SP>Here!)
{
REFRESH
}
but it won't work. Any help maybe?
Giving me this error:
SyntaxError: unknown command: IF, line: 1 (Error code: -910)
You can try by *.js file (not *.iim file) :
open notepad
copy my code
edit YOUR-URL to your url
save this to your-file.js ( path= imacro path )
open firefox & run your-file.js
good luck
CODE:
iimPlay("Code:URL GOTO=YOUR-URL")
var macro;
macro+="SET !REPLAYSPEED FAST\n";
macro+="TAG POS=1 TYPE=H2 ATTR=TXT:* EXTRACT=TXT\n";
iimPlay(macro_var);
var result=iimGetLastExtract();
if(result=="You<SP>Don't<SP>Belong<SP>Here!")
{
iimDisplay("success");
REFRESH
}

How to open and handle richtext editor in javascript in sitecore 6.5?

I've been working on a custom field, which contains a list.
I have to be able to edit the selected item on the list in a richtext editor. (this is the only missing part).
I've read the topic on opening from c# code Opening Rich Text Editor in custom field of Sitecore Content Editor .
This works nice for the "add" button, since i have to open the RTE empty(with default text...), but not for the Edit button.
My aproaches are:
Somehow in the Edit button's message field list:edit(id=$Target) pass the selected index (like list:edit(id=$Target,index=$SelectedIndex), but i don't know how to populate $SelectedIndex
Somehow in the overridden HandleMessage method get the list's selected index. I'm able to get the selected value Sitecore.Context.ClientPage.ClientRequest.Form[ID of list], but thats alone not much of a help, since i won't be able to decide which one to edit if two listitem equals.
Do the richtext editor opening and handling fully in javascript. As i saw at some script in content editor, i tried to do that, but i can't understand it clearly:
richtext editor url:
var page = "/sitecore/shell/Controls/Rich Text Editor/EditorPage.aspx";
some params :
var params = "?da=core&id&ed=" + id + "&vs=1&la=en&fld=" + id + "&so&di=0&hdl=H14074466&us=sitecore%5cadmin&mo";
and the part where i'm not sure:
var result = scForm.browser.showModalDialog(page + params, new Array(window), "dialogHeight:650px; dialogWidth:900px;");
This way the RTE opens as expected (i guess i could get the selected index from javascript and pass it as a parameter later). However when i click ok, i get exception from EditorPage.js saveRichText function: Cannot read property 'ownerDocument' of null. Am i missing some parameter?
Either of the three aproaches is fine for me(also i'm open for new better ones) as soon as i'm able to do it.
Thanks in advance!
Tamas
I was able to enter some javascript into the message:
list:Edit(id=$Target,index='+document.getElementById(ID of the select using $Target ).selectedIndex+')
this way i got the index in HandleMessage.
I'm waiting for better solutions now.

Matching tag in HTML keyboard shortcut

Is there a shortcut in Visual Studio (2008) that will allow me to jump to matching HTML tag... as CTRL+] does for matching braces when you are in code view?
Example:
<table>
<tr>
<td>
</td>
</tr>
</table|>
Cursor is on closing table tag and I would like to press something like CTRL+] to jump to opening table tag.
Any ideas?
I search and couldn't found direct short cut. But you can use..
If you want to go starting matching HTML tag, then follow below steps.
Place cursor at ending matching HTML tag.
Press Ctrl+M+M [To Collapse entire tag]
Press Home Key [To place cursor at before starting tag]
Press Ctrl+M+M [To Expand entire tag]
If you want to go ending matching HTML tag, then follow below steps.
Place cursor at starting matching HTML tag.
Press Ctrl+M+M [To Collapse entire tag]
Press End Key [To place cursor next to ending tag]
Press Ctrl+M+M [To Expand entire tag]
In Visual Studio 2015, this is now supported with the usual bracket matching keystrokes;
ctrl+] jumps from the start tag to the end tag.
ctrl+shift+] selects everything between the start tag and the end tag.
It seems pretty sensitive, though, and to select an entire tag and its contents you need to start right on the < that opens the tag.
After http://www.jetbrains.com/resharper/ is installed CTRL+] for matching braces works in HTML edit mode...
Ok here is the answer as macro which i've built which does it (toggle ) including go to focus :
Here is the demo :
And here is the code , enjoy !
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports System.Windows.Forms
Public Module Module2
Sub beginToEnd()
'Place cursor somewhere in beginning tag, run macro, to select from beginning to End Tag
DTE.ActiveDocument.Selection.SelectLine()
Dim objSel As TextSelection = DTE.ActiveDocument.Selection
Dim topPoint As TextPoint = objSel.TopPoint
Dim lTopLine As Long = topPoint.Line
objSel.GotoLine(lTopLine, False)
' DTE.ActiveDocument.Selection.StartOfLine()
DTE.ActiveDocument.Selection.SelectLine()
Dim line1 As String = DTE.ActiveDocument.Selection.Text()
If InStr(line1, "</") Then
' MsgBox(line1)
DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, True)
objSel.GotoLine(lTopLine, False)
DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
Else
DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
DTE.ActiveDocument.Selection.EndOfLine(False)
DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
End If
DTE.ActiveDocument.Selection.SelectLine()
Dim line2 As String = DTE.ActiveDocument.Selection.Text()
Dim objSel3 As TextSelection = DTE.ActiveDocument.Selection
Dim topPoint3 As TextPoint = objSel3.TopPoint
Dim lTopLine3 As Long = topPoint3.Line
objSel.GotoLine(lTopLine3, False)
DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, False)
End Sub
End Module
In Visual Studio 2012, in 'source' view, right at the bottom of the document window, there is a breadcrumb-trail-style description of the DOM. You can click at any point to select.
It's not a keyboard shortcut, but it does give you the selection behaviour you're looking for, and you don't need to match tags by eye any more.
(Edit) If you hover over the breadcrumb, you will see a dropdown arrow. Click the down arrow and click "Select Tag Content". Then you can just scroll up or down until you find text that is not highlighted.
This totally works when you open a HTML file with the XML Editor (Right click -> Open With... -> XML Editor).
I am using Visual Studio Code in Windows 10. Currently version 1.34.0. To jump to the matching html tag, I set it up through File -> Preferences -> Keyboard Shortcuts. Look for "Matching Tag: Jump to matching tag" .. There's a + when you hover it, then I set keybinding Shift + ] .. you can set your own as long as it isn't used for another function. So now I am able to jump to the closing HTML tag. Hope this helps.
SOLUTION WORK FOR ME:
press ctrl+shift+p this opens command pallete , after that write emmet:go to matching pair in search bar.
Click on setting icon and set your shortcut key(if you want). I uses ctrl+shift+/ and press enter.
It definitely works.
No, you can't do that in Visual Studio 2010, not in the current version or in older ones. Maybe the next version will have this feature.
Jump to matching tag functionality is easily achieved with this simple extension: VSCode Highlight Matching Tag
Once installed, you may use Command Palette (Win/Linux: Ctrl+Shift+P; Mac: Cmd+Shift+P) and search command name: Jump to matching tag. Or configure keyboard shortcut for that command. Here is my example of key binding for shift+5 in my case:
{
"key": "shift+5",
"command": "highlight-matching-tag.jumpToMatchingTag",
"when": "editorLangId == html"
}

Resources