JSFiddle - React, Tailwind, and code Playground

by Stev Peifer

HTML

<a href="http://www.tip.it/runescape/?rs2item_id=123"></a>
<a href="items/view/items/view/1234"></a>
<a href="items/view/items/view/1234"></a>
<a href="items/view/12345-item-name"></a>
<a href="hello/world/123456-item-name"></a>
<p></p>

JavaScript

(
    function($){
        $.itemTooltip=function(){

//~ -------------- NOTE -------------
//~ Create the item object which will
//~ contain all elements that contain
//~ valid item URLs and a list of
//~ each specific item number found
//~ ---------------------------------

            var item=new Object();
            item.element=new Array();
            item.number=new Array();
            item.result=new Array();

//~ -------------- NOTE -------------
//~ Create the memory object which
//~ will be used to build the qTips
//~ and hold item information
//~ ---------------------------------

            var memory=new Object();

//~ -------------- NOTE -------------
//~ Iterate through all <A> elements
//~ to build the item object
//~ ---------------------------------

            $('a').each(
                function(){

//~ -------------- NOTE -------------
//~ If the element doesn't contain a
//~ valid item URL, then skip it
//~ ---------------------------------

                    if(!(this.itemNumber=this.href.extractItem()))
                        return true;

//~ -------------- NOTE -------------
//~ Add the element to our array of
//~ elements containing valid item
//~ URLs
//~ ---------------------------------

                    item.element.push($(this));

//~ -------------- NOTE -------------
//~ If the current item number isn't
//~ in our list of items then add it
//~ ---------------------------------

                    if($.inArray(this.itemNumber,item.number)==-1)
                        item.number.push(this.itemNumber);
                }  //~ CLOSE: function()
            );  //~ CLOSE: each()

//~ -------------- NOTE -------------
//~ If no elements linking to an
//~ item were found then don't
//~ bother going any further
//~ ---------------------------------
            
            if(!item.element&&!item.number)
                return false;

//~ -------------- NOTE -------------
//~ Map our item.element array into a
//~ jQuery...