Uso este script para abrir un enlace específico en un div de una página web:
// ==UserScript== // @name New Userscript // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match https://www.tampermonkey.net/index.php?version=4.13&ext=dhdg&updated=true // @icon https://www.google.com/s2/favicons?domain=tampermonkey.net // @grant none // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js // ==/UserScript== $(document).ready(function() { let url = $(".cta-button-container__item").attr('href'); window.location.href = url; });los elementos de inspección para el enlace en la página son:
<div class="cta-button-container__item"> <a href="/content/pdf/xxxx.pdf" title="Download this book in PDF format" target="_blank" rel="noopener" class="c-button c-button--blue c-button__icon-right test-bookpdf-link" data-track="click" data-track-action="Book download - pdf" data-track-label=""> <svg width="12" height="14" viewBox="0 0 12 14" xmlns="http://www.w3.org/2000/svg"><path d="M7 7.269v-6.271c0-.551-.448-.998-1-.998-.556 0-1 .447-1 .998v6.271l-1.5-1.547c-.375-.387-1.01-.397-1.401-.006l.016-.016c-.397.397-.391 1.025-.001 1.416l3.178 3.178c.392.392 1.024.391 1.415 0l3.178-3.178c.392-.392.391-1.025-.001-1.416l.016.016c-.397-.397-1.018-.388-1.401.006l-1.5 1.547zm-7 5.731c0-.552.456-1 1.002-1h9.995c.554 0 1.002.444 1.002 1 0 .552-.456 1-1.002 1h-9.995c-.554 0-1.002-.444-1.002-1z" fill="#fff"></path></svg> <span>Download book PDF</span> </a> </div>Desafortunadamente, tampermonkey dice que no se está ejecutando ningún script.
después de más búsquedas, edité el script y funciona perfectamente:
// ==UserScript== // @name New Userscript // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match https://link.springer.com/book/*/* // @icon https://www.google.com/s2/favicons?domain=tampermonkey.net // @grant none // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js // ==/UserScript== $(document).ready(function() { let url = $(".cta-button-container__item a").attr('href'); window.location.href = url; }); Olvidé agregar la a que es equivalente a .find("a") . Cambié la URL del filtro a https://link.springer.com/book/*/* . el ( / ) solo significa cualquier dirección que comience con el enlace anterior.