Show Amazon Questions button + context menu

Creates a "Show questions" button next to the "answered questions" text, if any. Once pressed it opens a new tab of the questions.

当前为 2023-12-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Show Amazon Questions button + context menu
  3. // @author u/iNeedAProperAccount
  4. // @description Creates a "Show questions" button next to the "answered questions" text, if any. Once pressed it opens a new tab of the questions.
  5. // It also creates a "Open questions tab" context menu entry.
  6. // Thanks to u/CaptSkinny, u/lilgeeky, u/Sanpete_in_Utah and u/TTum.
  7. // How it looks like:
  8. // https://i.imgur.com/9vGioai.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.3
  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.be/*
  23. // @match *://*.amazon.se/*
  24. // @match *://*.amazon.pl/*
  25. // @match *://*.amazon.com.tr/*
  26. // @match *://*.amazon.ae/*
  27. // @match *://*.amazon.sa/*
  28. // @match *://*.amazon.co.jp/*
  29. // @match *://*.amazon.in/*
  30. // @match *://*.amazon.sg/*
  31. // @match *://*.amazon.com.au/*
  32. // @match *://*.amazon.com.br/*
  33. // @icon https://www.google.com/s2/favicons?sz=64&domain=amazon.ca
  34. // @grant GM_registerMenuCommand
  35. // @namespace https://gf.qytechs.cn/users/877912
  36. // ==/UserScript==
  37.  
  38. const REVIEW_DIV_SELECTOR = "div#averageCustomerReviews_feature_div.celwidget > div#averageCustomerReviews";
  39. const REGEX_PATTERN = "^(http[s]?://[^/]+)/(?:.+?/)?(?:dp|gp/product|asin)/(?:.+?/)?([a-zA-Z0-9]{10})(?:[/?]|$)";
  40.  
  41. function getQuestionsUrl() {
  42. try {
  43. const url = document.URL;
  44. const regex = new RegExp(REGEX_PATTERN, "i");
  45. const matches = url.match(regex);
  46.  
  47. if (matches) {
  48. const scheme_and_host = matches[1];
  49. const asin = matches[2];
  50. if (scheme_and_host && asin) {
  51. return `${scheme_and_host}/ask/questions/asin/${asin}`;
  52. }
  53. }
  54. } catch (error) {
  55. console.error("Error in getQuestionsUrl:", error);
  56. }
  57. }
  58.  
  59. function contextOpenQuestionsTab() {
  60. try {
  61. const questions_url = getQuestionsUrl();
  62. if (questions_url) {
  63. window.open(questions_url, '_blank');
  64. }
  65. } catch (error) {
  66. console.error("Error in contextOpenQuestionsTab:", error);
  67. }
  68. }
  69.  
  70. function openQuestionsTab() {
  71. try {
  72. const questions_url = getQuestionsUrl();
  73.  
  74. if (questions_url) {
  75. const reviewDiv = document.querySelector(REVIEW_DIV_SELECTOR);
  76.  
  77. if (reviewDiv) {
  78. const button = document.createElement("button");
  79. button.innerHTML = "Show Questions";
  80. button.style.margin = '0.2rem';
  81. button.addEventListener("click", function () {
  82. window.open(questions_url, '_blank');
  83. });
  84.  
  85. reviewDiv.parentNode.insertBefore(button, reviewDiv.nextSibling);
  86.  
  87. GM_registerMenuCommand("Open Questions tab", contextOpenQuestionsTab, "a");
  88. }
  89. }
  90. } catch (error) {
  91. console.error("Error in openQuestionsTab:", error);
  92. }
  93. }
  94.  
  95. const observer = new MutationObserver(function (mutations) {
  96. try {
  97. mutations.forEach(function (mutation) {
  98. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  99. for (let i = 0; i < mutation.addedNodes.length; i++) {
  100. const addedNode = mutation.addedNodes[i];
  101. if (addedNode.nodeType === 1 && addedNode.matches && addedNode.matches(REVIEW_DIV_SELECTOR)) {
  102. openQuestionsTab();
  103. break;
  104. }
  105. }
  106. }
  107. });
  108. } catch (error) {
  109. console.error("Error in MutationObserver:", error);
  110. }
  111. });
  112.  
  113. const observerConfig = {
  114. childList: true,
  115. subtree: true
  116. };
  117.  
  118. try {
  119. observer.observe(document.body, observerConfig);
  120. openQuestionsTab();
  121. } catch (error) {
  122. console.error("Error in script initialization:", error);
  123. }

QingJ © 2025

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