Advertisement
Ssateneth

Untitled

Jul 6th, 2025
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         eBay Seller Orders - Message Buyer Shortcut
  3. // @namespace    ebay-message-buyer
  4. // @version      1.0
  5. // @description  Adds a legacy "Message Buyer" link to each eBay order block on the seller sold orders page
  6. // @match        https://www.ebay.com/sh/ord/*
  7. // @match        https://www.ebay.com/sh/ord
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12.     'use strict';
  13.  
  14.     function insertMessageBuyerLinks() {
  15.         const orderRows = document.querySelectorAll("tr[id^='orderid_']");
  16.         orderRows.forEach(row => {
  17.             try {
  18.                 const itemIdElem = row.querySelector(".order-line-actions");
  19.                 const buyerElem = row.querySelector(".buyer-modal-trigger-wrapper button span:last-child");
  20.  
  21.                 if (!itemIdElem || !buyerElem) return;
  22.  
  23.                 const itemId = itemIdElem.dataset.itemid;
  24.                 const username = buyerElem.textContent.trim();
  25.  
  26.                 if (!itemId || !username) return;
  27.  
  28.                 const messageUrl = `https://www.ebay.com/contact/sendmsg?recipient=${encodeURIComponent(username)}&message_type_id=14&item_id=${encodeURIComponent(itemId)}`;
  29.  
  30.                 // Create the link
  31.                 const link = document.createElement("a");
  32.                 link.href = messageUrl;
  33.                 link.textContent = "Message Buyer";
  34.                 link.target = "_blank";
  35.                 link.style.display = "inline-block";
  36.                 link.style.marginBottom = "6px";
  37.                 link.style.fontWeight = "bold";
  38.  
  39.                 // Insert above the order-status block
  40.                 const orderStatusDiv = row.querySelector(".order-status");
  41.                 if (orderStatusDiv) {
  42.                     orderStatusDiv.parentNode.insertBefore(link, orderStatusDiv);
  43.                 }
  44.             } catch (e) {
  45.                 console.error("Message Buyer Insert Error:", e);
  46.             }
  47.         });
  48.     }
  49.  
  50.     // Run once DOM is ready
  51.     const observer = new MutationObserver((_, obs) => {
  52.         if (document.querySelector("tr[id^='orderid_']")) {
  53.             insertMessageBuyerLinks();
  54.             obs.disconnect();
  55.         }
  56.     });
  57.  
  58.     observer.observe(document.body, { childList: true, subtree: true });
  59. })();
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement