Have Greasemonkey click a button at first load and then in intervals? - firefox

I'm trying to make Greasemonkey script that clicks on a button at intervals and also clicks on it at the first load without wait.
I made this code which clicks every 120 seconds but the first time the page loads I have to wait 120 seconds for the code to click the GO button or I have to manually do it. :
window.setTimeout(function(){document.getElementById("masterPage_cphPageBody_btnGo").click()},120000)
and here is the source code related to it from the website
<input id="masterPage_cphPageBody_btnGo" name="masterPage$cphPageBody$btnGo" value="Go" onclick="SetSearchDate();showWaitpage();" class="btn2" type="submit">
How can I add a line to click on the GO the first time the page loads and 120 seconds there after?
the webpage before and after pressing the GO button has the same exact URL so adding the click on GO button without wait time will send hte page into a loop of
URL loaded GO clicked
URL Loaded GO clicked
URL Loaded GO clicked
...
checked the differences of the page before and after the first time GO button is clicked...
so I need the script to click Go button immidiately only if the following page does NOT show on the page
<span id="masterPage_cphPageBody_lblSelectAvailableTime" class="bodyBold">Select an available time</span>
but if "Select an available time" text show on page the script should wait 120 secon
I'm running: Greasemonkey, Windows 8 64, Firefox

Use a named function instead on an anonymous one (Often a good idea anyway).
Then use document.querySelector to check if that element is present. (That function has much more flexibility than getElementById.)
So your code becomes:
if (null === document.querySelector ("#masterPage_cphPageBody_lblSelectAvailableTime") ) {
clickGoButton (); //-- Initial, immediate click.
}
window.setTimeout (clickGoButton, 120000);
function clickGoButton () {
document.getElementById ("masterPage_cphPageBody_btnGo").click ();
}

Considering the post and pre Go button URL are the same to avoid the boot loop I found a textual difference between post and pre click and used it to avoid the loop
here is the code that worked for me at last
if (/Select an available time/i.test (document.body.innerHTML) )
{
window.setTimeout (clickGoButton, 120000);
}
else {
clickGoButton ();
}
function clickGoButton () {
document.getElementById ("masterPage_cphPageBody_btnGo").click ();
}

Related

Mocha, chai, webdriverio testing: How can I click out of a modal pop up dialog and continue on with the regular web flow

For a web page I am trying to write a test for, a modal appears sometimes. I'll like to write the test case such that if that does happen, I'll click the x to exit out of it and continue on with the test, else just do the test.
So far I have this:
client
.init()
.url('https://www.mywebsite.com/')
.isExisting('#simple-modal.auth-modal.open.visible').then(function(value){
// Select the X button: would like to client.click('#xbutton')
//when modal finishes loading
})
.click('#mybutton')
.getText('.browse-header').then(function(value) {
console.log('Title is : ' + value);
})
.end();
It seems that if I try to split the client object into 2 sections such that I init() and declare the url, then add a semicolon, then figure if the modal exist, add semicolon, then complete the rest of the test, the client doesn't complete the test. What can I do?

Get page number on click of page number datatable 1.9

I am using datatable version 1.9.x.
I want to get the page number if the user directly clicks on the page number, like 3 or 4.
I am able to get page number when he clicks next button using fnPagingInfo , but I am not able to get page number when he clicks the page directly.
This is my code :
$('#xyz').on('page dt', function () {
var info = bill_ov_np.selected.table.fnPagingInfo();
console.log(info);
});
I can get the page number from above function, but only when user clicks next button, not when the page number is directly selected.
Thanks in advance.
$(document).bind('click',"div.pagination li",function(evt){
var info = bill_ov_np.selected.table.fnPagingInfo();
});
This is the solution which I found and it is working for me.

Javascript "Click" event on disabled input type:file in Firefox

I want to make input type="file" becomes available and clicked only when I click on some element, which is also activated it (for example, stylized span).
For this I have the Javascript parameters on span:
onclick="document.getElementById('upload_hidden').Disabled = false;
document.getElementById('upload_hidden').Click();"
But the trouble is that in Firefox only first click removes the input attribute disabled and second - opens the file selection window. In Chrome - all OK: input become enabled and clicked by first span click.
Why, first click in Firefox does not work ? :(
http://jsfiddle.net/ey47G/
P.S. In firefox v21 - all OK. Firefox v25 and v26 - have this trouble.
I could imagine that the script is already ahead when it tries to click the button - but the button is still disabled
var f = document.getElementById('f');
var s = document.getElementById('s');
s.onclick = function () {
f.removeAttribute('disabled');
setTimeout(function(){ f.click(); }, 100); // run the explorer after 100 ms
}
This does work.
http://plnkr.co/edit/9syOfSJHaJ4b3bhRufpv?p=preview

Can Sitecore's rich text editor's internal link manager remember your last location?

Question
Is it possible to remember the last item linked and have that one be selected the next time the Insert a Link dialog box is used?
Background
Our Sitecore content editors use the rich text editor (Telerik RadEditor) to edit HTML content on our website. Sometimes they need to create several links on the same page that are in similar areas (e.g. several different related articles). Currently, when they click on the Insert Link button, they are brought to the Insert a Link dialog box with the current item selected in the content tree. They browse to the item they'd like to link and click Link. Then they go to create another link, and it opens the Insert a Link dialog box to the current item again, instead of the item they just linked.
The solution which I found requires changes in Website\sitecore\shell\Controls\Rich Text Editor\RichText Commands.js file and works as long as you don't reload the page. You may easily extend it to work when some other page is edited by storing the information in a cookie instead of using the variable prevId.
First of all you need to define variable at the beginning of your file:
var prevId = null;
We will assign the last chosen item id to this variable every time we insert Sitecore link.
Second step is to extend scInsertSitecoreLink function to assign the prevId variable after the link is chosen:
function scInsertSitecoreLink(sender, returnValue) {
if (!returnValue) {
return;
}
prevId = returnValue.url.match(/id\=[a-fA-F0-9]{32}/g);
if (prevId) {
prevId = prevId[0].substr(3);
}
... rest of the scInsertSitecoreLink goes here
And the last step is to amend RadEditorCommandList["InsertSitecoreLink"] function that it uses the prevId variable value if it is set before it tries to assign scItemID which holds current item id:
RadEditorCommandList["InsertSitecoreLink"] = function(commandName, editor, args) {\
... here goes the original code of the function up to
if (!id) {
... and the code in the bracket
}
... and now we try to assign the prevId which was set after the last link was chosen
if(!id && prevId) {
id = prevId;
}
... and here goes the rest of the function
if (!id) {
id = scItemID;
}

how to have another event on second click of button (not double click)

This seems like a really easy question, but I can't seem to find the answer.
Now that toggle() is deprecated for click events, how would I have say a button add DOM elements on the first click, then remove those same DOM elements on the second click?
Also.... how do I remove contents from a div I have inserted content into (using load()) without removing the div itself? Using remove() removes the div.
use empty() to clear an elements inner html
As for the toggle issue, you can toggle a class on the element and test for that class:
$('#myDiv').on('click', function(){
if(! $(this).hasClass('clicked') ){
/* code for first click*/
}else{
/* code for second click*/
}
$(this).toggleClass('clicked')
})
your click would first check for the presence of the dom elements that get added (use an id perhaps).
if $('div#id of the stuff you add')
$('element exists...').remove();
else
$('div#id of where you want to add stuff').add( new code );
You can clear a div contents with:
divSomeDiv.html("");
or
divSomeDiv.empty();

Resources