ebay - Mark sponsored item

In search result listing, detect which items are sponsored and mark them with a red outline and opacity

当前为 2025-06-16 提交的版本,查看 最新版本

// ==UserScript==
// @name         ebay - Mark sponsored item
// @namespace    https://github.com/Procyon-b
// @version      0.1
// @description  In search result listing, detect which items are sponsored and mark them with a red outline and opacity
// @author       Achernar
// @match        https://www.ebay.com/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
"use strict";

var cfg={childList:true, subtree:true}, obs=new MutationObserver(function(mutL){
  //console.info({mutL});
  for(let mut of mutL) {
    if (mut.target && (mut.target.id == 'srp-river-main') ) {
      fix(mut.target);
      return;
      }
    }
  });
obs.observe(document, cfg);


function isIn(e) {
  var p=e.closest('li');
  var re = e.getBoundingClientRect();
  var rp = p.getBoundingClientRect();

  //console.info(   re.top >= rp.top , re.left >= rp.left , re.bottom <= rp.bottom , re.right <= rp.right );

  return (re.top >= rp.top) && (re.left >= rp.left) && (re.bottom <= rp.bottom) && (re.right <= rp.right);
}

function fix(r=document) {
  r.querySelectorAll('li .s-item__details-section--primary > .s-item__detail--primary:last-child span[role="text"] div[aria-hidden="true"]').forEach( function(x){
    var R=isIn(x);
    //console.info(R);
    if (R) {
      x.closest('li').style='outline: 2px solid red; opacity: .4;';
      }
    });
  }


})();