Greasy Fork 还支持 简体中文。

Show Amazon Questions button + Show Amazon Questions 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-11-23 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Show Amazon Questions button + Show Amazon Questions 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: https://i.imgur.com/XJYWiQ4.png
  8. // Original thread at: https://old.reddit.com/r/AmazonVine/comments/14aynxt/are_product_question_and_answer_sections_gone/
  9. // @version 0.1
  10. // @license MIT License
  11. // @match *://*.amazon.com/*
  12. // @match *://*.amazon.ca/*
  13. // @match *://*.amazon.com.mx/*
  14. // @match *://*.amazon.co.uk/*
  15. // @match *://*.amazon.fr/*
  16. // @match *://*.amazon.de/*
  17. // @match *://*.amazon.es/*
  18. // @match *://*.amazon.it/*
  19. // @match *://*.amazon.nl/*
  20. // @match *://*.amazon.be/*
  21. // @match *://*.amazon.lu/*
  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://greasyfork.org/users/877912
  35. // ==/UserScript==
  36.  
  37. GM_registerMenuCommand("Open Questions tab", contextOpenQuestionsTab, "q");
  38.  
  39. const ASK_LINK_ID = "askATFLink";
  40. const REGEX_PATTERN = "^(http[s]?://[^/]+)/(?:.+?/)?(?:dp|gp/product|asin)/(?:.+?/)?([a-zA-Z0-9]{10})(?:[/?]|$)";
  41.  
  42. function getQuestionsUrl() {
  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. }
  55.  
  56. function contextOpenQuestionsTab() {
  57. const questions_url = getQuestionsUrl();
  58. if (questions_url) {
  59. window.open(questions_url, '_blank');
  60. }
  61. };
  62.  
  63. function openQuestionsTab() {
  64. const questions_url = getQuestionsUrl();
  65.  
  66. if (questions_url) {
  67. const askATFLink = document.getElementById(ASK_LINK_ID);
  68. if (askATFLink) {
  69. const button = document.createElement("button");
  70. button.innerHTML = "Show Questions";
  71. button.addEventListener("click", function () {
  72. window.open(questions_url, '_blank');
  73. });
  74.  
  75. askATFLink.parentNode.insertBefore(button, askATFLink.nextSibling);
  76. }
  77. }
  78. }
  79.  
  80. const observer = new MutationObserver(function (mutations) {
  81. mutations.forEach(function (mutation) {
  82. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  83. for (let i = 0; i < mutation.addedNodes.length; i++) {
  84. const addedNode = mutation.addedNodes[i];
  85. if (addedNode.id === ASK_LINK_ID) {
  86. openQuestionsTab();
  87. break;
  88. }
  89. }
  90. }
  91. });
  92. });
  93.  
  94. const observerConfig = {
  95. childList: true,
  96. subtree: true
  97. };
  98.  
  99. observer.observe(document.body, observerConfig);
  100.  
  101. openQuestionsTab();