ebay - Mark sponsored item

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

目前為 2025-07-02 提交的版本,檢視 最新版本

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

//console.info('us()');

function init() {
  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') ) {
        //console.info('fixing');
        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) {
  //ul.srp-results li .s-item__details-section--primary > .s-item__detail--primary:last-child .s-item__sep > [role="text"]
  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);
    //if (!s) s=x.style.backgroundImage;
    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();

})();