[BROKEN] Show Amazon Questions button + context menu

Creates a "Show questions" button for Amazon. Once clicked it opens a new tab of the questions.

  1. // ==UserScript==
  2. // @name [BROKEN] Show Amazon Questions button + context menu
  3. // @author u/iNeedAProperAccount
  4. // @description Creates a "Show questions" button for Amazon. Once clicked it opens a new tab of the questions.
  5. // It also creates an "Open Questions tab" context menu entry, which also when clicked opens a new tab of the questions.
  6. // Thanks to u/CaptSkinny, u/lilgeeky, u/Sanpete_in_Utah and u/TTum.
  7. // How it looks like:
  8. // https://i.imgur.com/mZSLDun.png
  9. // https://i.imgur.com/GHmUuEM.png
  10. // Original thread at: https://old.reddit.com/r/AmazonVine/comments/14aynxt/are_product_question_and_answer_sections_gone/
  11. // @version 0.6
  12. // @license MIT
  13. // @match *://*.amazon.com/*
  14. // @match *://*.amazon.ca/*
  15. // @match *://*.amazon.com.mx/*
  16. // @match *://*.amazon.co.uk/*
  17. // @match *://*.amazon.fr/*
  18. // @match *://*.amazon.de/*
  19. // @match *://*.amazon.es/*
  20. // @match *://*.amazon.it/*
  21. // @match *://*.amazon.nl/*
  22. // @match *://*.amazon.se/*
  23. // @match *://*.amazon.pl/*
  24. // @match *://*.amazon.com.tr/*
  25. // @match *://*.amazon.ae/*
  26. // @match *://*.amazon.sa/*
  27. // @match *://*.amazon.co.jp/*
  28. // @match *://*.amazon.in/*
  29. // @match *://*.amazon.sg/*
  30. // @match *://*.amazon.com.au/*
  31. // @match *://*.amazon.com.br/*
  32. // @icon https://www.google.com/s2/favicons?sz=64&domain=amazon.ca
  33. // @grant GM_registerMenuCommand
  34. // @namespace https://gf.qytechs.cn/users/877912
  35. // ==/UserScript==
  36.  
  37. const PRODUCT_TITLE_SELECTOR = "span#productTitle";
  38. const REGEX_PATTERN = "^(http[s]?://[^/]+)/(?:.+?/)?(?:dp|gp/product|asin)/(?:.+?/)?([a-zA-Z0-9]{10})(?:[/?]|$)";
  39.  
  40. function getQuestionsUrl() {
  41. try {
  42. const url = document.URL;
  43. const regex = new RegExp(REGEX_PATTERN, "i");
  44. const matches = url.match(regex);
  45.  
  46. if (matches) {
  47. const scheme_and_host = matches[1];
  48. const asin = matches[2];
  49. if (scheme_and_host && asin) {
  50. return `${scheme_and_host}/ask/questions/asin/${asin}`;
  51. }
  52. }
  53. } catch (error) {
  54. console.error("Error in getQuestionsUrl:", error);
  55. }
  56. }
  57.  
  58. function contextOpenQuestionsTab() {
  59. try {
  60. const questions_url = getQuestionsUrl();
  61. if (questions_url) {
  62. window.open(questions_url, '_blank');
  63. }
  64. } catch (error) {
  65. console.error("Error in contextOpenQuestionsTab:", error);
  66. }
  67. }
  68.  
  69. function openQuestionsTab() {
  70. try {
  71. const questions_url = getQuestionsUrl();
  72.  
  73. if (questions_url) {
  74. const productTitle = document.querySelector(PRODUCT_TITLE_SELECTOR);
  75.  
  76. if (productTitle) {
  77. const button = document.createElement("button");
  78. button.innerHTML = "Show Questions";
  79. button.style.margin = '0.2rem 0.2rem 0.2rem 0rem';
  80. button.style.fontSize = '0.9rem';
  81. button.addEventListener("click", function () {
  82. window.open(questions_url, '_blank');
  83. });
  84.  
  85. const brElement = document.createElement("br");
  86. productTitle.parentNode.insertBefore(brElement, productTitle.nextSibling);
  87.  
  88. productTitle.parentNode.insertBefore(button, brElement.nextSibling);
  89.  
  90. const brAfter = document.createElement("br");
  91. productTitle.parentNode.insertBefore(brAfter, button.nextSibling);
  92.  
  93. GM_registerMenuCommand("Open Questions tab", contextOpenQuestionsTab, "a");
  94. }
  95. }
  96. } catch (error) {
  97. console.error("Error in openQuestionsTab:", error);
  98. }
  99. }
  100.  
  101. const observer = new MutationObserver(function (mutations) {
  102. try {
  103. mutations.forEach(function (mutation) {
  104. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  105. for (let i = 0; i < mutation.addedNodes.length; i++) {
  106. const addedNode = mutation.addedNodes[i];
  107. if (addedNode.nodeType === 1 && addedNode.matches && addedNode.matches(PRODUCT_TITLE_SELECTOR)) {
  108. openQuestionsTab();
  109. break;
  110. }
  111. }
  112. }
  113. });
  114. } catch (error) {
  115. console.error("Error in MutationObserver:", error);
  116. }
  117. });
  118.  
  119. const observerConfig = {
  120. childList: true,
  121. subtree: true
  122. };
  123.  
  124. try {
  125. observer.observe(document.body, observerConfig);
  126. openQuestionsTab();
  127. } catch (error) {
  128. console.error("Error in script initialization:", error);
  129. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址