Chrome Bookmarklet which open in new tab with specific action - prompt

I want to make a Chrome Bookmarklet which open a new tab with specific action.
To be more exact I want to have a fixed URL like "https://www.blablabla.com/search=" inside the bookmarklet and when I press it, I want a popup window to appear with an input field.
When I type something in the input field and press enter or OK/submit it should "run" the whole link plus my query.
For example, I press the bookmarklet, the input field appears and input the word "test" (without the quotes).
When I press submit the query, a new tab will open with the address of https://www.blablabla.com/search=test as the URL.
How do I do that?
I tried with prompt function but I can't get it work...
My question is a bit similar to How do I get JavaScript code in a bookmarklet to execute after I open a new webpage in a new tab?.

Although it remains unclear what exact issue you encounter, try the following bookmarklet:
javascript:(function() {
var targetUrl = "http://www.blablabla.com/search=";
new Promise (
(setQuery) => {var input = window.prompt("ENTER YOUR QUERY:"); if (input) setQuery(input);}
)
.then (
(query) => window.open(targetUrl + query)
);
})();
If it doesn't work, you should provide the problem description in more detail.

#Shugar's answer is mostly correct, but you don't need the promise.
javascript:(function() {
var targetUrl = "http://www.blablabla.com/search=";
var input = window.prompt("ENTER YOUR QUERY:");
if (input)
window.open(targetUrl + input)
})();

javascript:void(window.open('http://www.URL.com/'+prompt ('Enter your Query:')));
I hope this helps. Works for me and is much simpler code than I see above. (as long as we reach the end result, that is all that matters right?)

Related

PDFTron: What is the proper way to find date fields in a PDF form

[PdfTron 5.2]
I have a PDF form with text and date fields. I want to find the date fields.
I can get the actions of the field with getActions().
field.getActions()
returns
{"F":[{"yc":"JavaScript","Gt":"AFDate_FormatEx(\"dd.mm.yyyy\");"}],
"K":[{"yc":"JavaScript","Gt":"...);","ey":null}]}
As you can see, the date is in actions.F[0].Gt. But checking actions.F[0].Gt
for "AFDate" seems wrong, that's too low-level.
Is there a better API function to find out, that I have a date field?
Thank you.
You are correct. The Gt property is obfuscated and minified which is volatile and not meant to be used. If you require an API, you should refer to our documentation. Everything should be available there except a few (one of which will be used below), but feel free to contact us if you do need help!
Unfortunately, there is no API currently to get that type. From my limited understanding, the "type" of a field is determined by the attached actions and not simply a specific type or flag. This suggests all fields are just text fields with special formatting actions to make it look and feel like its a date or numeric field.
In this case, you will have to check the formatting action (F) as you have already noticed for the date formatting function (AFDate_FormatEx). To get the JavaScript from that action, you should use the javascript property on the action which was not in the documentation. However, you can see it if you console log the action.
Here is an example:
const dateActionJs = /.+:"AFDate_FormatEx\(.*/;
instance.docViewer.on('annotationsLoaded', () => {
const annotations = annotManager.getAnnotationsList();
annotations.forEach(annot => {
const actions = annot.getField().getActions();
if (actions.F && actions.F[0] && actions.F[0].javascript && dateActionJs.test(actions.F[0].javascript)) { // F = Format Action
console.log('Found Date');
}
});
});
Let me know if this helps!
EDIT: You can search for AFDate instead of AFDate_FormatEx which will be sufficient.

JS Puppeteer: enter multiple chars atomically

I'm trying to fill an html form with puppeteer using type. According to the docs:
page.type(selector, text[, options])
...
Sends a keydown, keypress/input, and keyup event for each character in the text.
I have an issue with other events interfering with my typing process. How can I type my text atomically? I.e. with a single keydown event?
you can do, page.keyboard.sendCharacter("text"), which will do something akin to pasting in the text all at once. Make sure to first focus the selector you want to type into.
await page.focus('selector');
await page.keyboard.sendCharacter('text');
I don't know if it fits your needs but if you want to avoid keyboard events you could set directly the input value
await page.evaluate(() => document.querySelector("YOUR_SELECTOR").value = "Puppeteer");
or, if you need just one keydown event, you can trick Puppeteer by setting the value to "almost" what you need
await page.evaluate(() => document.querySelector("YOUR_SELECTOR").value = "Puppetee");
and use type just for the last char
await page.type("YOUR_SELECTOR", "r");

How to send key combination to selenium chromedriver?

i am using uirecorder to create mocha test cases to test my web program. I want to send some key combination like "Metakey + R". But i couldn't accomplish that.
here is an example of ui recorder generated step:
it('sendKeys: {DOWN}', async function(){
await driver.sendKeys('{DOWN}');
});
this works perfectly. but i couldn't figure out how to send key combinations.
The question is how can i send key combinations like ctrl+a ( holding ctrl and pressing a then leaving ctrl)
SOLUTION THAT I USE:
i just did it like this, and works fine.
await driver.sendKeys('{CTRL}a{CTRL}');
i just did it like this, and works fine.
await driver.sendKeys('{CTRL}a{CTRL}');
You can use ActionSequence class to perform actions in selenium using Node.
For pressing Left control + a you can simulate mouse action like this :
new webdriver.ActionSequence(driver).keyDown(webdriver.Key.LEFT_CONTROL).sendKeys("a").keyUp(webdriver.Key.LEFT_CONTROL).perform();
More Reference :
Reference 1
Reference 2
Using Keys class:
String keypress = Keys.chord(Keys.CONTROL, "a");
driver.findElement(By.locator("value of locator")).sendKeys(keypress);
Using Actions class:
Actions action = new Actions(driver);
action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).perform();
To anyone who finds this in the future, here is a solution that worked for me:
const {Key} = require('selenium-webdriver');
...
await driver.actions()
.keyDown(Key.SHIFT)
.sendKeys(Key.TAB)
.keyUp(Key.SHIFT)
.perform();

How to get the name of the current layout?

symfony getLayout does not seem to work when layout is set via view.yml. Is there anyway to get this within the controller's action class method
I recently needed this. You can do it but you just need to return the entire view.yml contents as an array:
$view_array = sfViewConfigHandler::getConfiguration(array(sfConfig::get('sf_app_config_dir').'/‌​view.yml'));
Just adjust the relative path from sf_app_config_dir (or use another marker) to get what you need.
It's not a trivial task. The view.yml, is not in the "scope" of the action.
Maybe, you can use setLayout in your action rather then in view.yml.
if you can't, for some reasons... you can try this method to reach datas in view.yml:
Is it possible to get a value from view.yml in an action
Execute the following code in the action. It works for both cases, layout set in the action or in the view.yml.
$controller = $this->getContext()->getController();
$view = $controller->getView($this->getModuleName(), $this->getActionName(), 'Success'); // viewName == 'Success' (default)
$layout_name = $view->getDecoratorTemplate(); // e.g expected: layout.php
Let us know if it works for you.

CKEditor dialogs: referencing input fields by ID

Each input field in the CKEditor dialogs are renamed with a unique number, but the number changes depending on what options are visible.
I need to reference 'txtUrl' which has an id something like #35_textInput.
So far I have discovered that something like this should work:
alert(CKEDITOR.instances.myElement.document.$.body.getId('txtUrl'));
But it doesn't. Please help.
#Rio, your solution was really close! This was the final solution:
var dialog = CKEDITOR.dialog.getCurrent();
dialog.setValueof('info','txtUrl',"http://google.com");
return false;
var dialog = this.getDialog();
var elem = dialog.getContentElement('info','txtUrl');
within an onchange part of an element I now use
dialog = this.getDialog();
alert(dialog.getContentElement('info', 'grootte').getInputElement().$.id);
and it gives 'cke_117_select' as a result. (It's a selectbox)
alert(dialog.getContentElement('info', 'txtUrl').getInputElement().$.id);
gives 'cke_107_textInput'.
I think this is what you (or other visitors to this page) are looking for.
SetValueOf still doesn't provide the id, which you may need if you want to do more than fill a text field with a certain text.

Resources