I made this fairly simple userscript to download videos on gametrailers.com without having to navigate to each page individually (see comments for clarification, because the code is ugly, jQuery, and unreadable):
var doIt = function(){
// Look for video list container
var results = $(".line_listing_results");
// Iterate through each listed video
results.children().each(function(key, vidElem) {
// get url to individual video page
var url = $(vidElem).find('.thumbnail').attr('href');
// some style for the download button
var styles = 'width: 4.875em; height: 1.5em; cursor: pointer; background-color: #3a8eb7; color: white; padding: 0.3em; font-size: 1.5em;'
// Append a download button to each thumbnail and bind a click
$(vidElem).append('<a id="dl-'+key+'" style="'+styles+'">Download</a>').click(function(clickElem){
// Create iFrame (problem is here)
var iframe = $('<iframe src="'+url+'#mod_j8j95m" frameborder="0" scrolling="no" id="iframe-'+key+'"></iframe>')
// Insert iFrame
iframe.appendTo('#dl-'+key)
// Bind 'onReady' to iFrame
$('#iframe-'+key).load(function(iElem){
// Click the download button
$('#iframe-'+key).contents().find(".download_button").trigger("click");
}.bind(this))
}.bind(this))
}.bind(this));
};
$(document).ready(function(){
doIt();
})
The problem is that the main video page keeps snapping to the iFrame when I include the #mod_j8j95m in the url, when I scroll down to click another video/download button. The thing I can't explain, is that this happens multiple times (Chrome). So when I scroll down it will snap back to the iFrame in a certain interval (1 or 2 seconds, not clear).
The reason why I'm including the #mod_j8j95m is I want to lighten the load on the page, because it is heavy as it is (especially since they embedded a youtube video (which I blocked the frame for with adBlock, which fixes dozens of bogus requests to chromecast, which would slow down the loading of the website to snail-speed)). But it seems it actually loads the whole page anyways, just filters out that id
So, a couple of questions:
- Why is it snapping/triggering the
idmultiple times? - Is there a way to only load a part of an iFrame? (even just the download button would be enough in this case, or just the download
url) - And why does the snapping stop, once the
clickhas been fired?
Aucun commentaire:
Enregistrer un commentaire