Product Availability Checker

Display Instagram icon with green dot on Amazon and Flipkart product pages based on data from Google Sheets

  1. // ==UserScript==
  2. // @name Product Availability Checker
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Display Instagram icon with green dot on Amazon and Flipkart product pages based on data from Google Sheets
  6. // @author Your Name
  7. // @license MIT
  8. // @match https://www.amazon.in/*
  9. // @match https://www.flipkart.com/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const googleApiKey = 'f9ef79943782659df6946a421bd6f67edf725395'; // Your Google API Key
  17. const spreadsheetId = '12n_Ze61eRoiqn6OFFp6hy5-4K85ecJiRQgX15d_l6YQ';
  18. const sheetName = 'mymart inventory - Sheet1';
  19. const instagramPageUrl = 'https://www.instagram.com/mym_mart/';
  20.  
  21. // Function to fetch data from Google Sheets
  22. async function fetchDataFromGoogleSheets() {
  23. const url = `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${sheetName}?key=${googleApiKey}`;
  24. const response = await fetch(url);
  25. const data = await response.json();
  26. return data.values;
  27. }
  28.  
  29. // Function to extract product name from Amazon or Flipkart page
  30. function extractProductName() {
  31. let productName = null;
  32. if (window.location.hostname === 'www.amazon.in') {
  33. // Logic to extract product name from Amazon page
  34. productName = document.querySelector('span#productTitle')?.textContent.trim();
  35. } else if (window.location.hostname === 'www.flipkart.com') {
  36. // Logic to extract product name from Flipkart page
  37. productName = document.querySelector('span[class="_35KyD6"]')?.textContent.trim();
  38. }
  39. return productName;
  40. }
  41.  
  42. // Function to display Instagram icon with or without green dot
  43. function displayInstagramIcon(available) {
  44. let icon = document.getElementById('instagramIcon');
  45. if (!icon) {
  46. icon = document.createElement('a');
  47. icon.id = 'instagramIcon';
  48. icon.href = instagramPageUrl;
  49. icon.target = '_blank';
  50. icon.style.position = 'fixed';
  51. icon.style.bottom = '20px'; // Adjust position as needed
  52. icon.style.left = '20px'; // Adjust position as needed
  53. icon.style.zIndex = '9999';
  54. icon.style.display = 'block';
  55. icon.style.width = '50px';
  56. icon.style.height = '50px';
  57. icon.style.background = `url('https://cdn-icons-png.flaticon.com/512/174/174855.png') no-repeat center center`;
  58. icon.style.backgroundSize = 'contain';
  59. icon.style.borderRadius = '50%';
  60. icon.style.textDecoration = 'none';
  61. icon.style.color = 'white';
  62. icon.style.textAlign = 'center';
  63. icon.style.lineHeight = '50px';
  64. icon.style.fontWeight = 'bold';
  65. document.body.appendChild(icon);
  66. }
  67.  
  68. if (available) {
  69. icon.style.backgroundColor = 'green';
  70. icon.textContent = '•'; // Green dot
  71. } else {
  72. icon.style.backgroundColor = 'transparent';
  73. icon.textContent = ''; // No dot
  74. }
  75. }
  76.  
  77. // Main function to check product availability and display Instagram icon
  78. async function main() {
  79. const productTitle = extractProductName();
  80. if (!productTitle) return; // Exit if product title not found
  81.  
  82. const data = await fetchDataFromGoogleSheets();
  83. for (const row of data) {
  84. const sheetProductTitle = row[0];
  85. const quantity = parseInt(row[1]);
  86. if (productTitle.toLowerCase().includes(sheetProductTitle.toLowerCase())) {
  87. // Display Instagram icon with or without green dot based on product availability
  88. displayInstagramIcon(quantity > 0);
  89. return;
  90. }
  91. }
  92. // If product not available or doesn't match criteria, display Instagram icon without dot
  93. displayInstagramIcon(false);
  94. }
  95.  
  96. // Run the script
  97. main();
  98. })();

QingJ © 2025

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