Untitled

mail@pastecode.io avatar
unknown
javascript
5 months ago
1.6 kB
7
Indexable
javascript:(function() {
    /* Book getter code written by u/halffast */
    var title = '';
    var author = '';
    
    /* Check the URL to determine which variation to run */
    if (window.location.href.includes('romance.io')) {
        /* Get the title element */
        var titleElement = document.querySelector('.book-info h1');
       
        /* Remove any <a> tags inside the title element (strips out series name) */
        var links = titleElement.querySelectorAll('a');
        links.forEach(function(link) {
            link.remove();
        });
       
        /* Get the title and authors, trimming any empty spaces */
        title = titleElement.textContent.trim();
        author = document.querySelector('.book-info h2.author').textContent.trim();
    } else if (window.location.href.includes('goodreads')) {
        /* Get the title and authors, trimming any empty spaces */
        title = document.querySelector('.Text__title1').textContent.trim();
        author = document.querySelector('.ContributorLinksList').textContent.trim();
    } else if (window.location.href.includes('amazon')) {
        /* Get the title and authors, trimming any empty spaces */
        title = document.querySelector('#productTitle').textContent.trim();
    	author = Array.from(document.querySelectorAll('#bylineInfo .author a')).map(a => a.textContent.trim()).join(', ');
    }
    
    /* Create the result string */
    var result = `{${title} by ${author}}`;
    
    /* Copy the result to the clipboard */
    navigator.clipboard.writeText(result);
})();
Leave a Comment