Copy Image SRC from Taobao

Copy image source from Taobao product pages

  1. // ==UserScript==
  2. // @name Copy Image SRC from Taobao
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Copy image source from Taobao product pages
  6. // @author max5555
  7. // @license MIT
  8. // @match https://item.taobao.com/*
  9. // @grant GM_setClipboard
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to create and show the notification
  16. function showNotification(message) {
  17. var notification = document.createElement('div');
  18. notification.innerText = message;
  19. notification.style.position = 'fixed';
  20. notification.style.bottom = '80px';
  21. notification.style.left = '20px';
  22. notification.style.backgroundColor = 'lightgreen';
  23. notification.style.padding = '10px';
  24. notification.style.zIndex = '1000';
  25. document.body.appendChild(notification);
  26. setTimeout(() => notification.remove(), 3000); // Auto-hide after 3 seconds
  27. }
  28.  
  29. // Function to copy image SRC
  30. function copyImageSrc() {
  31. var image = document.querySelector('.ks-imagezoom-wrap img');
  32. if (image && image.src) {
  33. GM_setClipboard(image.src);
  34. showNotification('Image source copied!');
  35. } else {
  36. showNotification('Image not found!');
  37. }
  38. }
  39.  
  40. // Create and place the button
  41. var button = document.createElement('button');
  42. button.innerText = 'Copy Image Src';
  43. button.style.position = 'fixed';
  44. button.style.bottom = '40px'; // Modified position
  45. button.style.left = '20px'; // Modified position
  46. button.style.padding = '5px';
  47. button.style.background = 'rgba(0, 0, 0, 0.7)';
  48. button.style.color = 'white';
  49. button.style.zIndex = '10000';
  50. button.onclick = copyImageSrc;
  51. document.body.appendChild(button);
  52. })();