ebay - Mark sponsored item

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

// ==UserScript==
// @name         ebay - Mark sponsored item
// @namespace    https://github.com/Procyon-b
// @version      0.3.3
// @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";


function init() {
  var cfg={childList:true, subtree:true}, obs=new MutationObserver(function(mutL){
    for(let mut of mutL) {
      if (mut.target && (mut.target.id == 'srp-river-main') ) {
        fix(mut.target);
        return;
        }
      }
    });
  try {
    obs.observe(document, cfg);
    document.addEventListener('load', function(){fix();} );
    window.addEventListener('load', function(){fix();} );
    }
  catch(e) { setTimeout(init, 0); }
  }

function isIn(e) {
  var p=e.closest('li');
  var re = e.getBoundingClientRect();
  var rp = p.getBoundingClientRect();
  return (re.top >= rp.top) && (re.left >= rp.left) && (re.bottom <= rp.bottom) && (re.right <= rp.right);
}

var s;

function fix(r=document) {
  let i,e=r.querySelector('ul.srp-results li.s-item [aria-labelledby]');
  if (e && (i=e.style.backgroundImage)) {
    i=i.substr(-30);
    r.querySelectorAll(`ul.srp-results li.s-item:has( .s-item__detail .s-item__sep div[style^="background-image:"][style*='${i}'])`).forEach( function(x){
      x.style='outline: 2px solid red; opacity: .4;';
      });
    e=!e;
    }
  if (e) {
    r.querySelectorAll('ul.srp-results li.s-item:has([aria-labelledby="'+e.attributes['aria-labelledby'].value+'"]').forEach( function(x){
      x.style='outline: 2px solid red; opacity: .4;';
      });
    }
  
  r.querySelectorAll('ul.srp-results li .s-item__details-section--primary > .s-item__detail--primary:last-child [role="text"] :only-child').forEach( function(x){
    var cs, cs1, R=isIn(x);
    cs=getComputedStyle(x);
    cs1=getComputedStyle(x.parentNode);
    R=( ((cs.filter == 'none') != (cs1.filter == 'none')) && cs.color == 'white')
     || ( ((cs.filter == 'none') != (cs1.filter == 'none')) && cs.color == 'rgb(255, 255, 255)')

     || ( ((cs.filter == 'none') == (cs1.filter == 'none')) && cs.color == 'black')
     || ( ((cs.filter == 'none') == (cs1.filter == 'none')) && cs.color == 'rgb(0, 0, 0)');
    
    if (R) {
      x.closest('li').style='outline: 2px solid red; opacity: .4;';
      }
    });
  }


init();

})();

QingJ © 2025

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