Neopets: Shop Wizard Anchor Creator

Creates an anchor elements that opens the normal Shop Wizard if an user doesn't have Premium, or the Super Shop Wizard if they do.

Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta // @require https://update.greatest.deepsurf.us/scripts/567035/1759343/Neopets%3A%20Shop%20Wizard%20Anchor%20Creator.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

/*
•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•:•:•:•:•:•:•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•.•:•:•:•:•:•:•:•:•.•:•:•.•:•.••:•.•:•.••:
........................................................................................................................
☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦
    This isn't a script and it does nothing on its own. It was created to be @required. It allows an userscript to use:
        createSWLink(string itemName)
    To get an anchor element that opens the Shop Wizard in a new tab with a specific query if the user doesn't have
    Premium, or the SSW with identical search on if they do have premium.

    You don't need to install this. It's automatically used by other scripts.

    ✦ ⌇ saahphire
☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦
........................................................................................................................
•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•:•:•:•:•:•:•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•.•:•:•:•:•:•:•:•:•.•:•:•.•:•.••:•.•:•.••:
*/

const openOldSsw = (itemName, oldSsw) => {
    oldSsw.classList.add('panel_shown');
    oldSsw.classList.remove('panel_hidden');
    oldSsw.style.display = '';
    if(!oldSsw.querySelector('#ssw-tabs-2.ui-tabs-hide')) document.getElementById('button-new-search').click();
    document.getElementById('searchstr').value = itemName;
    document.getElementById('ssw-criteria').selectedIndex = 1;
}

const openNewSsw = (itemName, newSsw) => {
    newSsw.style.display = 'block';
    if(!newSsw.querySelector('#ssw-tabs-2.ssw-hide')) document.getElementById('ssw-button-new-search').click();
    document.getElementById('searchstr').value = itemName;
    document.getElementById('ssw-criteria').selectedIndex = 0;
}

const addAction = (a, itemName) => {
    const oldSsw = document.getElementsByClassName('sswdrop')[0];
    const newSsw = document.getElementById('ssw__2020');
    if(oldSsw || newSsw) {
        const callback = oldSsw ? () => openOldSsw(itemName, oldSsw) : () => openNewSsw(itemName, newSsw);
        a.addEventListener('click', callback);
        a.style.cursor = 'pointer';
    }
    else {
        a.href = `https://www.neopets.com/shops/wizard.phtml?string=${encodeURIComponent(itemName).replaceAll("%20", "+")}`;
        a.target = '_blank';
    }
}

const createSWLink = (itemName, children) => {
    const a = document.createElement('a');
    if(!children) a.textContent = itemName;
    else (children.length ? children : [children]).forEach(child => a.appendChild(child));
    addAction(a, itemName);
    return a;
}