Greasy Fork 支持简体中文。

Etsy URL Cleaner

Removes specified query parameters from Etsy URLs

  1. // ==UserScript==
  2. // @name Etsy URL Cleaner
  3. // @namespace https://greasyfork.org/en/scripts/456795-etsy-url-cleaner
  4. // @version 1.0.4
  5. // @description Removes specified query parameters from Etsy URLs
  6. // @match https://www.etsy.com/listing/*
  7. // @match https://www.etsy.com/shop/*
  8. // @match https://i.etsystatic.com/*
  9. // @grant none
  10. // @icon https://www.etsy.com/favicon.ico
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Danh sách các query parameters cần xóa
  18. // Bạn có thể dễ dàng thêm mới bằng cách thêm vào mảng này
  19. const QUERY_PARAMS_TO_REMOVE = [
  20. '?ref',
  21. '?click_key',
  22. '?ga_order',
  23. '?ref=simple-shop-header',
  24. '?ls'
  25. ];
  26.  
  27. /**
  28. * Xóa các query parameters không mong muốn khỏi URL
  29. * @param {string} url - URL cần xử lý
  30. * @returns {string} URL đã được làm sạch
  31. */
  32. function cleanQueryParams(url) {
  33. let maxIndex = -1;
  34.  
  35. // Tìm vị trí cuối cùng của bất kỳ parameter nào trong danh sách
  36. QUERY_PARAMS_TO_REMOVE.forEach(param => {
  37. const index = url.indexOf(param);
  38. if (index !== -1 && index > maxIndex) {
  39. maxIndex = index;
  40. }
  41. });
  42.  
  43. // Nếu tìm thấy parameter, cắt bỏ từ vị trí đó trở đi
  44. if (maxIndex !== -1) {
  45. return url.substring(0, maxIndex);
  46. }
  47. return url;
  48. }
  49.  
  50. /**
  51. * Xử lý URL hình ảnh để chuyển sang chất lượng đầy đủ
  52. * @param {string} url - URL cần xử lý
  53. * @returns {string} URL đã được xử lý hoặc null nếu không cần thay đổi
  54. */
  55. function processImageUrl(url) {
  56. if (url.indexOf('/il_fullxfull') !== -1) {
  57. return null;
  58. }
  59.  
  60. if (url.indexOf('/il_') !== -1) {
  61. const ilIndex = url.indexOf('/il_');
  62. const dotIndex = url.indexOf('.', ilIndex);
  63. return url.substring(0, ilIndex) + '/il_fullxfull' + url.substring(dotIndex);
  64. }
  65. return null;
  66. }
  67.  
  68. // Main execution
  69. let currentUrl = window.location.href;
  70.  
  71. // Xử lý query parameters
  72. const cleanedUrl = cleanQueryParams(currentUrl);
  73. if (cleanedUrl !== currentUrl) {
  74. window.history.pushState({}, '', cleanedUrl);
  75. currentUrl = cleanedUrl;
  76. }
  77.  
  78. // Xử lý URL hình ảnh
  79. const processedImageUrl = processImageUrl(currentUrl);
  80. if (processedImageUrl) {
  81. window.location.href = processedImageUrl;
  82. }
  83. })();