Well, I'm trying to set an onClick event with jQuery on a image to open it on another tab after left click it. But it looks like because the website has lazy loading images, my script is not working. Even with the awesome waitForKeyElements script, which most of the times save me when the page has AJAX'ed content, I couldn't achieve what I'm looking for.
Please check my code below:
// ==UserScript==
// @include https://revista*.globo.com/*.html
// @version 1.0
// @require https://code.jquery.com/jquery-2.2.3.min.js
// @require https://gist.githubusercontent.com/BrockA/2625891/raw/9c97aa67ff9c5d56be34a55ad6c18a314e5eb548/waitForKeyElements.js
// @grant GM_openInTab
// @run-at document-idle
// ==/UserScript==
waitForKeyElements("image.lazy-loaded.lazy-loaded", clickableImage, false);
function clickableImage (jNode) {
jNode.each ( function () {
var jThis = $(this);
console.log( JSON.stringify( jThis ) );
var imgLink = jThis.prop ("data-src");
console.log( imgLink );
jThis.on( "click", function() {
GM_openInTab(imgLink);
});
} );
}
I'm using Firefox v68.0.1 with Tampermonkey v4.9.5941
Thanks in advance.
As this answer from the duplicate question explains and the comment, I achieved what I expected with the code below
waitForKeyElements("image.lazy-loaded.lazy-loaded", clickableImage, false);
function clickableImage (jNode) {
var imgLink = jNode.data ("src");
jNode.on( "click", function() {
GM_openInTab(imgLink);
});
};