🏠 Home 

Amazon Books to Z-library and Anna's Archive updated

Adds buttons to Amazon book pages to redirect to Z-library and Annas Archive pages based on ISBN-13


Install this script?
  1. // ==UserScript==
  2. // @name Amazon Books to Z-library and Anna's Archive updated
  3. // @namespace open-in-z-library-annasarchive
  4. // @version 1.0
  5. // @description Adds buttons to Amazon book pages to redirect to Z-library and Annas Archive pages based on ISBN-13
  6. // @author EndS0uls
  7. // @match https://*.amazon.*/*/dp/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11. (function () {
  12. 'use strict';
  13. function redirectToSingleLogin() {
  14. var isbn13 = getISBN13();
  15. if (!isbn13) {
  16. alert("No ISBN-13 Found.");
  17. } else {
  18. window.open('https://singlelogin.re/s/' + isbn13);
  19. }
  20. }
  21. function redirectToAnnasArchive() {
  22. var isbn13 = getISBN13();
  23. if (!isbn13) {
  24. alert("No ISBN-13 Found.");
  25. } else {
  26. window.open('https://annas-archive.org/search?index=&page=1&q=' + isbn13);
  27. }
  28. }
  29. function getISBN13() {
  30. var detailBullets = document.getElementById('detailBulletsWrapper_feature_div');
  31. var isbn13 = null;
  32. if (detailBullets) {
  33. var listItems = detailBullets.querySelectorAll('ul li span.a-list-item');
  34. for (var i = 0; i < listItems.length; i++) {
  35. if (listItems[i].textContent.includes('ISBN-13')) {
  36. isbn13 = listItems[i].textContent.match(/(\d{3}-\d{10}|\d{13})/)[0];
  37. break;
  38. }
  39. }
  40. }
  41. return isbn13;
  42. }
  43. function addButton() {
  44. var imageBlockNew = document.getElementById('imageBlockNew_feature_div');
  45. var imageBlock = document.getElementById('imageBlock_feature_div');
  46. var booksImageBlock = document.getElementById('booksImageBlock_feature_div');
  47. var askWidgetQuestions = document.getElementById('ask-btf_feature_div');
  48. // Check if either of the div tags is present and ask-btf_feature_div is not present
  49. if ((imageBlockNew || booksImageBlock || imageBlock) && !askWidgetQuestions) {
  50. var singleLoginButton = createButton('Open in Z-Library', redirectToSingleLogin, '#377458');
  51. var annasArchiveButton = createButton('Open in Anna\'s Archive', redirectToAnnasArchive, '#0056b3');
  52. var buttonContainer = document.createElement('div');
  53. buttonContainer.style.marginTop = '20px';
  54. buttonContainer.style.textAlign = 'center';
  55. // Apply responsive styles
  56. var buttonsCSS = `
  57. display: inline-block;
  58. margin: 10px;
  59. padding: 8px 12px;
  60. font-family: Arial, sans-serif;
  61. font-size: 14px;
  62. font-weight: bold;
  63. text-decoration: none;
  64. cursor: pointer;
  65. color: #ffffff;
  66. border: none;
  67. border-radius: 4px;
  68. background-color: transparent;
  69. transition: background-color 0.3s ease, transform 0.3s ease;
  70. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  71. `;
  72. singleLoginButton.style.cssText = buttonsCSS + `
  73. background-color: #377458;
  74. `;
  75. annasArchiveButton.style.cssText = buttonsCSS + `
  76. background-color: #0056b3;
  77. `;
  78. // Hover effects
  79. singleLoginButton.addEventListener('mouseover', function() {
  80. singleLoginButton.style.transform = 'scale(1.05)';
  81. });
  82. singleLoginButton.addEventListener('mouseout', function() {
  83. singleLoginButton.style.transform = 'scale(1)';
  84. });
  85. annasArchiveButton.addEventListener('mouseover', function() {
  86. annasArchiveButton.style.transform = 'scale(1.05)';
  87. });
  88. annasArchiveButton.addEventListener('mouseout', function() {
  89. annasArchiveButton.style.transform = 'scale(1)';
  90. });
  91. buttonContainer.appendChild(singleLoginButton);
  92. buttonContainer.appendChild(annasArchiveButton);
  93. // Insert the buttons after either of the div tags
  94. if (imageBlockNew) {
  95. imageBlockNew.parentNode.insertBefore(buttonContainer, imageBlockNew.nextSibling);
  96. } else if (booksImageBlock) {
  97. booksImageBlock.parentNode.insertBefore(buttonContainer, booksImageBlock.nextSibling);
  98. } else if (imageBlock) {
  99. imageBlock.parentNode.insertBefore(buttonContainer, imageBlock.nextSibling);
  100. }
  101. }
  102. }
  103. function createButton(text, onClickFunction, backgroundColor) {
  104. var button = document.createElement('button');
  105. button.innerText = text;
  106. button.onclick = onClickFunction;
  107. return button;
  108. }
  109. function shadeColor(color, percent) {
  110. var f = parseInt(color.slice(1), 16),
  111. t = percent < 0 ? 0 : 255,
  112. p = percent < 0 ? percent * -1 : percent,
  113. R = f >> 16,
  114. G = (f >> 8) & 0x00FF,
  115. B = f & 0x0000FF;
  116. return "#" + (0x1000000 + (Math.round((t - R) * p) + R) * 0x10000 + (Math.round((t - G) * p) + G) * 0x100 + (Math.round((t - B) * p) + B)).toString(16).slice(1);
  117. }
  118. addButton();
  119. })();