Untitled
unknown
javascript
a year ago
2.1 kB
35
Indexable
javascript:(function() {
/* Book getter code written by u/halffast */
var title = '';
var author = '';
/* Check the URL to determine which script 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 */
if (document.querySelector('#productTitle') != null) {
title = document.querySelector('#productTitle').textContent.trim();
} else if (document.querySelector('#ebooksTitle') != null) {
title = document.querySelector('#ebooksTitle').textContent.trim();
} else if (document.querySelector('#title') != null) {
title = document.querySelector('#title').textContent.trim();
} else {
alert('Error copying from Amazon. Please try a different site.');
}
author = Array.from(document.querySelectorAll('#bylineInfo a')).map(a => a.textContent.trim()).join(', ');
}
/* Remove extra spaces */
author=author.replace(/\s+/g,' ');
/* Create the result string */
var result = `{${title} by ${author}}`;
/* Copy the result to the clipboard and show alert with result */
navigator.clipboard.writeText(result).then(function() {
alert('Copied to clipboard: ' + result);
});
})();Editor is loading...
Leave a Comment