Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I donot know javascript. I have to do some edits.
I want to know what does the below code does
$(window).load(function(){
setTimeout(function(){
$("#gmbox div").animate({'top':60},1500,"easeOutElastic");
},1500);
});
function trackLink(link, category, action) {
try {
_gaq.push(['_trackEvent', 'tracklink' ,'click',link.href ]);
setTimeout('document.location = "' + link.href + '"', 100)
}catch(err){}
}
$('[rel="outbound"]').click(function(e){
try {
_gaq.push(['_trackEvent','outbound','click',this.href]);
}catch(err){}
});
});
Here is your code with comments added to describe what's going on
// wait for the document to finish loading then...
$(window).load(function(){
// wait a while and then...
setTimeout(function(){
// animate out a the div element whose id is 'gmbox' (look up the jquery animate API to understaind the specifics)
$("#gmbox div").animate({'top':60},1500,"easeOutElastic");
},1500); // how long to wait (1.5 seconds)
});
// this function isn't actually called anywhere in the code you provided but it could be called from elsewhere
function trackLink(link, category, action) {
try {
// tell google analytics that the user clicked on a link
_gaq.push(['_trackEvent', 'tracklink' ,'click',link.href ]);
// wait 0.1 seconds then change the url in the address bar
setTimeout('document.location = "' + link.href + '"', 100)
}catch(err){} // don't worry if this code caused an error
}
// when the user clicks on an element with a rel='outbound' attribute...
$('[rel="outbound"]').click(function(e){
try {
// report this to google analytics
_gaq.push(['_trackEvent','outbound','click',this.href]);
}catch(err){} // don't worry if this code caused an error
});
});
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
What code do I have to write to restart this script? I want to totally reset / update the script via a code in order to let it process new / updated information. Maybe best way to just stop it and start it again. But how?
<script type="text/javascript">
var _myplug = _myplug || {};
_myplug.key = '12e9u349u43098j8r940rjciocjo';
_myplug.renderTo = '';
window.myplug||(function(d) {
var s,c,o=myplug=function(){ o._.push(arguments)};o._=[];
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
c.type='text/javascript';c.charset='utf-8';c.async=true;
c.src='js/loader.js?';s.parentNode.insertBefore(c,s);
})(document);
</script>
Well, without knowing enough info about the script, here's a hacky method that will be sure to reload the script:
function reloadScript() {
with(document) {
var newscr = createElement('script');
newscr.id = 'reloadMe';
newscr.appendChild(createTextNode(getElementById('reloadMe').innerHTML));
body.removeChild(getElementById('reloadMe'));
body.appendChild(newscr);
}
}
You'll need an ID on your script tag:
<script type="text/javascript" id="reloadMe">
UPDATE:
The above method isn't enough to refresh your code, because your code also appends another script tag in the document, called loader.js.
Here's a special version for your situation:
<script type="text/javascript" id="notTheScriptYouWannaRefresh">
var _myplug = _myplug || {};
_myplug.key = '12e9u349u43098j8r940rjciocjo';
_myplug.renderTo = '';
window.myplug||(function(d) {
var s,c,o=myplug=function(){ o._.push(arguments)};o._=[];
c=d.createElement('script');
c.type='text/javascript';c.charset='utf-8';
c.async=true;c.id='reloadMe'; //<-- CUSTOM ID SET!
c.src='js/loader.js?';d.body.appendChild(c);
})(document);
function reloadScript() {
with(document) {
var newscr = createElement('script');
newscr.id = 'reloadMe';
newscr.appendChild(createTextNode(getElementById('reloadMe').innerHTML));
body.removeChild(getElementById('reloadMe'));
body.appendChild(newscr);
}
}
window.setTimeout(reloadScript, 10000); //Reload after 10 seconds
</script>
Hope this solves the problem.
I know something more.
I found another method, which maybe does the same as what #AaronGillion suggested. Only the trigger differs (it restarts every x seconds).
This is the method:
http://jsfiddle.net/mendesjuan/LPFYB/
I replaced the scriptTag.innerText with my script codes. Since I see that this starts my script succesfully, I also understand that the script is removed and reinserted every x seconds. And since this doesn't update the script, it proves that there is another thing loaded that keeps the script continuing in the old state. Might be the loader.js.
Unfortunately my JS knowledge is limited. How to restart loader.js from my code?
For clarity I paste the code from this topic again below, including the loader.js:
<script type="text/javascript">
var _myplug = _myplug || {};
_myplug.key = '12e9u349u43098j8r940rjciocjo';
_myplug.renderTo = '';
window.myplug||(function(d) {
var s,c,o=myplug=function(){ o._.push(arguments)};o._=[];
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
c.type='text/javascript';c.charset='utf-8';c.async=true;
c.src='js/loader.js?';s.parentNode.insertBefore(c,s);
})(document);
</script>
Question is how to restart loader.js.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to remove the cookie from the site. Somebody told me to use this code. But I do not know the functionality of the code. Please tell me.
Here ref is the cookie name which is generating in the site.
var referrer = document.referrer; //returns the URL of the document that loaded the current document.
if (referrer.indexOf(location.host) == -1) {
console.log('1');
jQuery.removeCookie('ref');
if (jQuery.cookie('ref') === undefined) {
jQuery.cookie('ref', referrer, {
expires: .5,
path: '/'
});
referrer = jQuery.cookie('ref');
console.log('2');
} else {
console.log('3');
jQuery.removeCookie('ref');
referrer = jQuery.cookie('ref');
}
} else {
console.log('4');
referrer = jQuery.cookie('ref');
}
When a user to your website, say:
http://example.com/
Now, the document.referrer is "" (blank) as it was not "referred" by any link. The user typed it. The document.referrer holds the link from which the page has been opened.
Now, when the home page has a link like http://example.com/signup, and the user clicks it, and goes to the page, and the page has the following code:
document.referrer; // This would give http://example.com/ as the referrer.
When you are checking this:
referrer.indexOf(location.host) == -1
What exactly happens is:
"http://example.com/".indexOf("http://example.com/") == -1
Where, both have the content. This shows that the link has been clicked from the local page available in the same domain. When the referrer is not the local page, then add the referrer in the cookie and do some process is what the if condition does.
There are a lot of conditions in the code. They are the cases from where the user might have come from.
Case 1: User has not come from anywhere. It returns undefined. You will get 2 logged in the console.
Case 2: If he comes from a different page, You will get 3 logged in the console.
Case 3: If he comes from the same page, You will get 4 logged in the console.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I need to develop a sort of calculator which show a set of images and the client can select and depending on the choice he moves to next step of choices. At the end of all the choices he will be given a package depending on the choices of all steps chosen.
A working example of something similar can be found in this link: http://store.virginmedia.com/big-bundles.html and then clicking on the 'help me choose' popup on the left hand side.
Can anyone suggest any methods or libraries I can start from in achieving something like this ?
Okay. So this is pretty basic, but I created a JSFiddle just to get you started. I is not pretty, but it should give you some indication of what is required.
Here is the code, if there is something about it that is unclear, google it:
var selections = {
"opt1": false,
"opt2": false,
"opt3": false,
"opt4": false,
"opt5": false,
"opt6": false
};
$(document).ready(function() {
$('.option').click(function(event) {
var id = event.target.id;
if (selections[id]) {
$('#' + id).removeClass('checked-option');
selections[id] = false;
} else {
$('#' + id).addClass('checked-option');
selections[id] = true;
}
});
$('#btn1').click(function() {
$('#grp1').hide();
$('#grp2').show();
});
$('#btn2').click(function() {
$('#grp2').hide();
$('#grp1').show();
});
$('#btn3').click(function() {
var content = 'Selected:<ul>';
for (var i in selections) {
if (selections[i]) {
content += '<li>' + i + '</li>';
}
}
content += '</ul>';
$('#grp2').hide();
$('#done').html(content);
$('#grp3').show();
});
$('#btn4').click(function() {
$('#grp3').hide();
$('#grp2').show();
});
});
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to link to a page like (domain.com/page#loadThickBox1) and have it run jquery function that loads a thickbox by default. What code do I need to run to accomplish this?
For instance, these might be a few links:
domain.com/page#loadThickBox1
domain.com/page#loadThickBox2
domain.com/page#loadThickBox3
NOT like this:
domain.com/page/loadThickBox1
domain.com/page/loadThickBox2
domain.com/page/loadThickBox3
Use location.hash
$(function() {
switch( location.hash.replace('#','') ){
case 'loadThickBox1':
//do something!
loadThickBox1();
break;
case 'loadThickBox2':
//do something!
loadThickBox2();
break;
case 'loadThickBox3':
//do something!
loadThickBox3();
break;
}
});
location.href.split('#')[1]
This will get you the words after the #. Load the appropriate box given this value.
You can listen to the hashchange event, parse the hash and run your function accordingly.
DEMO
function handleHash(hash) {
var hash = hash.replace('#', '');
if (!hash) return;
console.log('Loading thick box ' + hash.slice(-1));
}
window.addEventListener('hashchange', function () {
handleHash(location.hash);
});
//handle initial hash when page loads
handleHash(location.hash);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm on https://twitter.com/#!/username/followers ; is there any greasemonkey script to follow all the twitter users on that page?
Here's a new one which also employs a delay to prevent spam issues.
var FOLLOW_PAUSE = 1250;
var FOLLOW_RAND = 250;
var PAGE_WAIT = 2000;
__cnt__ = 0;
var f;
f = function() {
var eles;
var __lcnt__ = 0;
eles = jQuery('.Grid-cell .not-following .follow-text').each(function(i, ele) {
ele = jQuery(ele);
if (ele.css('display') != 'block') {
console.trace('Already following: ' + i);
return;
}
setTimeout(function() {
console.trace("Following " + i + " of " + eles.length);
ele.click();
if ((eles.length - 1) == i) {
console.trace("Scrolling...");
window.scrollTo(0, document.body.scrollHeight);
setTimeout(function() {
f();
}, PAGE_WAIT);
}
}, __lcnt__++ * FOLLOW_PAUSE + Math.random()*(FOLLOW_RAND) - FOLLOW_RAND/2);
__cnt__++;
});
}
f();
What it does:
Looks for follow buttons
Checks that you aren't already following or pending (display: block check)
Sets a timer to click the FOLLOW buttons every 500ms to prevent spam issues.
NEW! When it's done them all, scrolls the page and waits a couple seconds for the next loads to appear, then repeats the whole process!
Notes for hackers:
Works on Chrome latest version and Twitter as of the 30th of Sep 2016.
You seem to need to "click" the DIV inside the A tag, not the A tag itself.
HOMEWORK: Maybe try jQuery's live() function to auto-click any new buttons which show up after the initial page load :)
Disclaimer: This is not a hack...just a technique to save some wrist and finger RSI :) Regardless, use cautiously and respectfully.
UPDATE: Improved for latest twitter. Now employs randomness in the timing to make you look less like a bot
Twitter uses JQuery, so a way to do this, assuming that you aren't doing this so much as to trigger the rate limits (the rate limits will apply more aggressively to web client users as compared to API users) is to do the equivalent of:
$('.button.follow-button').click()
You can accomplish this in GreaseMonkey if you'd like, or setting it as a JavaScript bookmarklet, or by copy-pasting this into your address bar and hitting enter:
javascript:$('.button.follow-button').click()
I modified the code that Hari Karam Singh posted earlier to work to the to-date Twitter.
__cnt__=0; jQuery('.stream button.follow-button > span.follow-text').each(function (i, ele) { ele = jQuery(ele); if (ele.css('display')!='block') {console.log('already following:', i); return;} setTimeout(function () {ele.click();}, __cnt__++*500); });
It doesn´t work anymore, but if you use the object instead of the alias i´ll do javascript:jQuery('.button.follow-button').click();.
You can also use the in-built debugger in chrome or firebug to add a button that cam do this for you, and add a settimeout to avoid interference with the api's restrictions.
<input type="button" onclick="javascript:jQuery('.button.follow-button').click();" value="follow!
">