Search code examples
javascriptwebbrowser-controlbookmarkletbrowser-cache

Detect the referral/s of Url/s using JavaScript or PHP from inside a Bookmarklet


Let's think out of the box!

Without any programming skills, how can you say/detect if you are on a web page that lists products, and not on the page that prints specific details of a product?

The Bookmarklet is inserted using JavaScript in right after the body tag of a website ( eBay, Bloomingdales, Macy's, toys'r'us ... )

Now, my story is: (programming skills needed now)

I have a bookmarklet and my main problem is how to detect if I am on a page that lists products or if i am on the page that prints the product detail.

The best way that I could think, to detect if I am on the detail page of a product is to detect the referral(s) of the current URL. (maybe all the referrals, the entire click history)

Possible problem: a user adds the URL as favorite and does not use my bookmarklet, and closes the browser; then the user uses the browser again, clicks the favorite link and uses my bookmaklet and I think that I can't detect the referral in this case; it's OK, not all the cases are covered or possible;

Can I detect the referral of this link using the cache in this case? (many browsers cache systems involved here, I know)


Solution

  • how can you say/detect if you are on a web page that lists products, and not on the page that prints specific details of a product

    I'd setup Brain.js (a neural net implemented in javascript) and train it up on a (necessarily broad and varied) sample set of DOMs and then pick a threshold product:details ratio to 'detect' (as near as possible) what type of page I'm on.

    This will require some trial and error, but is the best approach I can think of (neural nets can get to "good enough" results pretty quickly - try it, you'll be surprised at the results).