User:TheMcr/common.js: Difference between revisions

Boobpedia - Encyclopedia of big boobs
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
(function () {
    const tooltip = document.createElement('div');
    tooltip.style.position = 'absolute';
    tooltip.style.maxWidth = '300px';
    tooltip.style.padding = '10px';
    tooltip.style.background = '#fff';
    tooltip.style.border = '1px solid #aaa';
    tooltip.style.borderRadius = '6px';
    tooltip.style.boxShadow = '0 4px 12px rgba(0,0,0,0.2)';
    tooltip.style.fontSize = '14px';
    tooltip.style.zIndex = '9999';
    tooltip.style.display = 'none';
    document.body.appendChild(tooltip);


const tooltip = document.createElement('div');
    function showTooltip(event, content) {
tooltip.className = 'tooltip';
        tooltip.innerHTML = content;
tooltip.style.display = 'none';
        tooltip.style.left = `${event.pageX + 15}px`;
tooltip.style.width = '300px';
        tooltip.style.top = `${event.pageY + 15}px`;
tooltip.style.z-index = '1000';
        tooltip.style.display = 'block';
document.body.appendChild(tooltip);
    }


document.querySelectorAll('a').forEach(link => {
    function hideTooltip() {
  link.addEventListener('mouseenter', async (e) => {
        tooltip.style.display = 'none';
    const url = new URL(link.href);
     }
     const title = decodeURIComponent(url.pathname.split('/').pop());


     tooltip.style.display = 'block';
     function fetchPreview(title, event) {
    tooltip.innerHTML = 'Loading...';
        $.getJSON(
            mw.util.wikiScript('api'), {
                action: 'query',
                prop: 'extracts|pageimages',
                exintro: true,
                explaintext: true,
                titles: title,
                format: 'json',
                pithumbsize: 120
            }
        ).done(function (data) {
            const page = data.query.pages[Object.keys(data.query.pages)[0]];
            let content = `<strong>${page.title}</strong><br>`;
            if (page.thumbnail && page.thumbnail.source) {
                content += `<img src="${page.thumbnail.source}" style="float:left; margin-right:10px;" />`;
            }
            content += `<div>${page.extract || 'No summary available.'}</div>`;
            showTooltip(event, content);
        });
    }


     const response = await fetch(`https://www.boobpedia.com/${title}`);
     function initPreviews() {
    const data = await response.json();
        $('#bodyContent a').each(function () {
            const $link = $(this);
            const href = $link.attr('href');


    tooltip.innerHTML = `
            if (!href || href.indexOf('/wiki/') !== 0 || href.indexOf(':') !== -1) return; // skip special pages
      <strong>${data.title}</strong><br>
      ${data.thumbnail ? `<img src="${data.thumbnail.source}" alt="${data.title}">` : ''}
      <p>${data.extract}</p>
    `;


    const rect = link.getBoundingClientRect();
            const title = decodeURIComponent(href.replace(/^\/wiki\//, '')).replace(/_/g, ' ');
    tooltip.style.left = `${rect.right + 10 + window.scrollX}px`;
    tooltip.style.top = `${rect.top + window.scrollY}px`;
  });


  link.addEventListener('mouseleave', () => {
            $link.hover(
    tooltip.style.display = 'none';
                function (e) {
  });
                    fetchPreview(title, e);
});
                },
                function () {
                    hideTooltip();
                }
            ).mousemove(function (e) {
                tooltip.style.left = `${e.pageX + 15}px`;
                tooltip.style.top = `${e.pageY + 15}px`;
            });
        });
    }
 
    $(initPreviews);
})();

Revision as of 15:05, 5 April 2025

(function () {
    const tooltip = document.createElement('div');
    tooltip.style.position = 'absolute';
    tooltip.style.maxWidth = '300px';
    tooltip.style.padding = '10px';
    tooltip.style.background = '#fff';
    tooltip.style.border = '1px solid #aaa';
    tooltip.style.borderRadius = '6px';
    tooltip.style.boxShadow = '0 4px 12px rgba(0,0,0,0.2)';
    tooltip.style.fontSize = '14px';
    tooltip.style.zIndex = '9999';
    tooltip.style.display = 'none';
    document.body.appendChild(tooltip);

    function showTooltip(event, content) {
        tooltip.innerHTML = content;
        tooltip.style.left = `${event.pageX + 15}px`;
        tooltip.style.top = `${event.pageY + 15}px`;
        tooltip.style.display = 'block';
    }

    function hideTooltip() {
        tooltip.style.display = 'none';
    }

    function fetchPreview(title, event) {
        $.getJSON(
            mw.util.wikiScript('api'), {
                action: 'query',
                prop: 'extracts|pageimages',
                exintro: true,
                explaintext: true,
                titles: title,
                format: 'json',
                pithumbsize: 120
            }
        ).done(function (data) {
            const page = data.query.pages[Object.keys(data.query.pages)[0]];
            let content = `<strong>${page.title}</strong><br>`;
            if (page.thumbnail && page.thumbnail.source) {
                content += `<img src="${page.thumbnail.source}" style="float:left; margin-right:10px;" />`;
            }
            content += `<div>${page.extract || 'No summary available.'}</div>`;
            showTooltip(event, content);
        });
    }

    function initPreviews() {
        $('#bodyContent a').each(function () {
            const $link = $(this);
            const href = $link.attr('href');

            if (!href || href.indexOf('/wiki/') !== 0 || href.indexOf(':') !== -1) return; // skip special pages

            const title = decodeURIComponent(href.replace(/^\/wiki\//, '')).replace(/_/g, ' ');

            $link.hover(
                function (e) {
                    fetchPreview(title, e);
                },
                function () {
                    hideTooltip();
                }
            ).mousemove(function (e) {
                tooltip.style.left = `${e.pageX + 15}px`;
                tooltip.style.top = `${e.pageY + 15}px`;
            });
        });
    }

    $(initPreviews);
})();