[Pokeclicker] Synthetic Shiny Synapse

Allows you to adjust and modify the shiny rates of everything specifically, as well as set a global shiny rate.

当前为 2022-07-14 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        [Pokeclicker] Synthetic Shiny Synapse
// @namespace   Pokeclicker Scripts
// @match       https://www.pokeclicker.com/
// @grant       none
// @version     1.3
// @author      Ephenia
// @description Allows you to adjust and modify the shiny rates of everything specifically, as well as set a global shiny rate.
// ==/UserScript==

const genSource = ['generateWildPokemon', //Wild Pokemon
    'generateDungeonPokemon', //Dungeon Pokemon
    'evolve', //Evolution Pokemon
    'new', //Safari Pokemon
    'claimFunction', //Shop/Claim/Gift Pokemon
    'hatch', //Breeding/Eggs
    'generateWanderPokemon', //Wandering/Farm Pokemon
];
const genDesc = ['Wild Pokémon shiny odds:',
    'Dungeon Pokémon shiny odds:',
    'Evolution Stone Pokémon shiny odds:',
    'Safari Pokémon shiny odds:',
    'Gift/Claimed Pokémon shiny odds:',
    'Breeding/Hatchery Pokémon shiny odds:',
    'Wandering/Farm Pokémon shiny odds:'
];
var shinyTypes;
var shinyRates = [];
var prefShinyRates;
var globalShinyState;
var globalShinyRate;
var karmaMode;
var karmaRates;

function initShinySynapse() {
    getShinyRates();

    const profileModal = document.getElementById('profileModal');
    const profileDrop = document.getElementById('startMenu').querySelectorAll('ul li')[0];
    const shinyLi = document.createElement('li');
    const a = document.createElement('a');
    a.setAttribute('class', 'dropdown-item');
    a.setAttribute('href', '#shinyModal');
    a.setAttribute('data-toggle', 'modal');
    a.textContent = 'Shiny Modifier';
    a.addEventListener('click', () => { updateShinyModal(); });
    shinyLi.appendChild(a);
    profileDrop.before(shinyLi);
    const shinyMod = document.createElement('div');
    shinyMod.setAttribute("class", "modal noselect fade show");
    shinyMod.setAttribute("id", "shinyModal");
    shinyMod.setAttribute("tabindex", "-1");
    shinyMod.setAttribute("aria-labelledby", "shinyModal");
    shinyMod.setAttribute("aria-labelledby", "shinyModal");
    shinyMod.setAttribute("aria-modal", "true");
    shinyMod.setAttribute("role", "dialog");

    shinyMod.innerHTML = `<div class="modal-dialog modal-dialog-scrollable modal-dialog-centered modal-lg" role="document">
    <div class="modal-content">
        <div class="modal-header" style="justify-content: space-around;">
            <h5 class="modal-title">Shiny Modifier</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">×</span>
            </button>
        </div>
        <div class="modal-body">
        </div>
    </div>`

    profileModal.before(shinyMod);

    document.getElementById('shinyModal').querySelector('.modal-header').querySelector('h5').outerHTML += `
    <button id="shiny-rate-global" class="btn btn-${globalShinyState ? 'success' : 'danger'}" style="margin-left:20px;">
    Global Override [${globalShinyState ? 'ON' : 'OFF'}]
    </button>
    <button id="shiny-karma-mode" class="btn btn-${karmaMode ? 'success' : 'danger'}" style="margin-left:20px;">
    Karma Mode [${karmaMode ? 'ON' : 'OFF'}]
    </button>
    <button id="shiny-rates-reset" class="btn btn-primary" style="margin-left:20px;">
    Reset Rates
    </button>`
    document.getElementById('shiny-rate-global').addEventListener('click', event => { globalToggle(event); });
    document.getElementById('shiny-karma-mode').addEventListener('click', event => { toggleKarma(event); });
    document.getElementById('shiny-rates-reset').addEventListener('click', () => { resetRates(); });

    const modalBody = document.querySelector('[id=shinyModal] div div [class=modal-body]');
    const shinyMulti = App.game.multiplier.getBonus('shiny');
    const fragment = new DocumentFragment();

    const head = document.createElement('div');
    head.setAttribute('id', 'shiny-modifier-head');
    head.innerHTML = `<div>Category</div><div>✨Odds</div><div>✨Shiny Bonus</div><div></div>`;
    fragment.appendChild(head);

    const global = document.createElement('div');
    global.setAttribute('class', 'shiny-modifier-view');
    global.innerHTML = `<div>Global shiny odds:</div>`;
    const globalInput = document.createElement('input');
    globalInput.setAttribute('id', `shiny-modifier-global`);
    globalInput.setAttribute('type', 'text');
    globalInput.setAttribute('placeholder', `${globalShinyRate.toLocaleString('en-US')}`);
    globalInput.addEventListener('input', event => { checkInput(event); });
    global.appendChild(globalInput);
    const globalCharm = document.createElement('div');
    globalCharm.setAttribute('id', 'shiny-charm-rate-global');
    globalCharm.textContent = `${globalShinyRate / shinyMulti}`
    global.appendChild(globalCharm);
    const globalBtn = document.createElement('button');
    globalBtn.textContent = 'Modify';
    globalBtn.setAttribute('class', 'btn btn-sm btn-success');
    globalBtn.addEventListener('click', event => {
        const rate = +document.getElementById('shiny-modifier-global').value.replace(/[A-Za-z!@#$%^&*()]/g, '').replace(/[,]/g, "");
        const shinyMulti = App.game.multiplier.getBonus('shiny');
        globalShinyRate = rate;
        document.getElementById('shiny-charm-rate-global').textContent = (globalShinyRate / shinyMulti);
        localStorage.setItem("globalShinyRate", JSON.stringify(globalShinyRate));
    });
    global.appendChild(globalBtn);

    fragment.appendChild(global);

    for (let i = 0; i < shinyRates.length; i++) {
        const div = document.createElement('div');
        div.setAttribute('class', 'shiny-modifier-view');
        div.innerHTML = `<div>${genDesc[i]}</div>`;
        const input = document.createElement('input');
        input.setAttribute('id', `shiny-modifier-${i}`);
        input.setAttribute('type', 'text');
        input.setAttribute('placeholder', `${shinyRates[i].toLocaleString('en-US')}`);
        input.addEventListener('input', event => { checkInput(event); });
        div.appendChild(input);

        const charm = document.createElement('div');
        charm.setAttribute('id', `shiny-charm-rate-${i}`);
        charm.textContent = `${shinyRates[i] / shinyMulti}`
        div.appendChild(charm);

        const btn = document.createElement('button');
        btn.textContent = 'Modify';
        btn.setAttribute('class', 'btn btn-sm btn-success');
        btn.setAttribute('data-src', i);
        btn.addEventListener('click', event => {
            const index = +event.target.getAttribute('data-src');
            const rate = +document.getElementById(`shiny-modifier-${index}`).value.replace(/[A-Za-z!@#$%^&*()]/g, '').replace(/[,]/g, "");
            const shinyMulti = App.game.multiplier.getBonus('shiny');
            shinyRates[index] = rate;
            prefShinyRates[index] = rate;
            document.getElementById(`shiny-charm-rate-${index}`).textContent = (prefShinyRates[index] / shinyMulti);
            localStorage.setItem("shinySetRates", JSON.stringify(prefShinyRates));
        });
        div.appendChild(btn);

        fragment.appendChild(div);
    }
    modalBody.appendChild(fragment);

    PokemonFactory.generateShiny = function (chance, skipBonus = false) {
        let genType;
        try {
            const split = (new Error()).stack.split("\n")[2].trim().split(" ");
            genType = split[split.length - 2].replace(/^(.*?)[.]/, '');
        } catch (err) {
            genType = (new Error()).stack.split("\n")[1].trim().split(" ")[0].replace(/@(.*?)$/, '');
        }
        const index = genSource.indexOf(genType);

        let trueChance;
        if (karmaMode) {
            trueChance = karmaRates[index];
            karmaRates[index] = karmaRates[index] - 1;
            localStorage.setItem('shinyKarmaRates', JSON.stringify(karmaRates));
        }
        else if (globalShinyState) {
            trueChance = globalShinyRate;
        } else if (prefShinyRates[index]) {
            trueChance = prefShinyRates[index];
        } else {
            trueChance = chance;
        }

        const bonus = skipBonus ? 1 : App.game.multiplier.getBonus('shiny');

        if (Rand.chance(trueChance / bonus)) {
            if (karmaMode) {
                karmaRates[index] = GameConstants[shinyTypes[index]]
                localStorage.setItem('shinyKarmaRates', JSON.stringify(karmaRates));
            }
            App.game.oakItems.use(OakItemType.Shiny_Charm);
            return true;
        }
        return false;
    }

    addGlobalStyle('#shiny-modifier-head > div:nth-child(1) { width: 33% !important }');
    addGlobalStyle('#shiny-modifier-head * { width: 22% }');
    addGlobalStyle('#shiny-modifier-head { display: flex;flex-direction: row;margin-bottom: 14px;font-weight: bold;font-size: 1.1em; }');
    addGlobalStyle('.shiny-modifier-view { display: flex;flex-direction: row;justify-content: center;align-items: center;column-gap: 10px;margin-bottom: 2px; }');
    addGlobalStyle('.shiny-modifier-view > div:nth-child(1) { width: 33% !important }');
    addGlobalStyle('.shiny-modifier-view * { width: 22% }');

    function globalToggle(event) {
        const element = event.target;
        globalShinyState = !globalShinyState;
        element.setAttribute('class', `btn btn-${globalShinyState ? 'success' : 'danger'}`);
        element.textContent = `Global Override [${globalShinyState ? 'ON' : 'OFF'}`;
        localStorage.setItem("globalShinyState", JSON.stringify(globalShinyState));
    }

    function toggleKarma(event) {
        const element = event.target;
        karmaMode = !karmaMode;
        element.setAttribute('class', `btn btn-${karmaMode ? 'success' : 'danger'}`);
        element.textContent = `Karma Mode [${karmaMode ? 'ON' : 'OFF'}`;
        localStorage.setItem("shinyKarmaMode", JSON.stringify(karmaMode));
        $('#shinyModal').modal('hide');
    }

    function resetRates() {
        const shinyMulti = App.game.multiplier.getBonus('shiny');

        globalShinyRate = 8192;
        localStorage.setItem("globalShinyRate", JSON.stringify(globalShinyRate));

        const shinyView = document.getElementsByClassName('shiny-modifier-view');
        for (let i = 0; i <= prefShinyRates.length; i++) {
            if (i == 8) {
                break;
            }
            if (i < 7) {
                prefShinyRates[i] = null;
            }
            if (0 == i) {
                shinyView[i].querySelector('input').value = globalShinyRate.toLocaleString('en-US');
                document.getElementById('shiny-charm-rate-global').textContent = (globalShinyRate / shinyMulti);
            } else {
                shinyRates[i - 1] = GameConstants[shinyTypes[i - 1]];
                shinyView[i].querySelector('input').value = shinyRates[i - 1].toLocaleString('en-US');
                document.getElementById(`shiny-charm-rate-${i - 1}`).textContent = (shinyRates[i - 1] / shinyMulti);
            }
        }
        localStorage.setItem("shinySetRates", JSON.stringify(prefShinyRates));
    }

    function checkInput(input) {
        const value = +event.target.value.replace(/[A-Za-z!@#$%^&*()]/g, '').replace(/[,]/g, "");
        event.target.value = value.toLocaleString('en-US');
    }

    function updateShinyModal() {
        const modifyBtns = document.getElementsByClassName('shiny-modifier-view');
        document.getElementById('shiny-modifier-global').disabled = karmaMode ? true : false;
        document.getElementById('shiny-rates-reset').disabled = karmaMode ? true : false;
        modifyBtns[0].querySelector('button').disabled = karmaMode ? true : false;
        for (let i = 0; i < shinyRates.length; i++) {
            document.getElementById(`shiny-modifier-${i}`).disabled = karmaMode ? true : false;
            document.getElementById(`shiny-modifier-${i}`).setAttribute('placeholder', `${karmaMode ? karmaRates[i].toLocaleString('en-US') : shinyRates[i].toLocaleString('en-US')}`);
            modifyBtns[i + 1].querySelector('button').disabled = karmaMode ? true : false;
        }
        const shinyMulti = App.game.multiplier.getBonus('shiny');
        for (let ii = 0; ii < shinyRates.length; ii++) {
            document.getElementById(`shiny-charm-rate-${ii}`).textContent = karmaMode ? (karmaRates[ii] / shinyMulti) : (shinyRates[ii] / shinyMulti);
        }
    }
}

function getShinyTypes() {
    const shinyTypeData = Object.keys(GameConstants).filter(e => e.includes('SHINY_CHANCE'));
    return shinyTypeData;
}

function getShinyRates() {
    for (let i = 0; i < shinyTypes.length; i++) {
        if (prefShinyRates[i]) {
            shinyRates.push(prefShinyRates[i]);
        } else {
            shinyRates.push(GameConstants[shinyTypes[i]]);
        }
    }
}

shinyTypes = getShinyTypes();
if (!localStorage.getItem('globalShinyState')) {
    localStorage.setItem('globalShinyState', false);
}
if (!localStorage.getItem('globalShinyRate')) {
    localStorage.setItem('globalShinyRate', 8192);
}
if (!localStorage.getItem('shinySetRates')) {
    const prefArray = new Array(shinyTypes.length).fill(null, 0, shinyTypes.length);
    localStorage.setItem('shinySetRates', JSON.stringify(prefArray));
}
if (!localStorage.getItem('shinyKarmaMode')) {
    localStorage.setItem('shinyKarmaMode', false);
}
if (!localStorage.getItem('shinyKarmaRates')) {
    const karmaRates = [];
    shinyTypes.forEach(item => { karmaRates.push(GameConstants[item]) });
    localStorage.setItem('shinyKarmaRates', JSON.stringify(karmaRates));
}
globalShinyState = JSON.parse(localStorage.getItem('globalShinyState'));
globalShinyRate = JSON.parse(localStorage.getItem('globalShinyRate'));
prefShinyRates = JSON.parse(localStorage.getItem('shinySetRates'));
karmaMode = JSON.parse(localStorage.getItem('shinyKarmaMode'));
karmaRates = JSON.parse(localStorage.getItem('shinyKarmaRates'));

function loadScript() {
    var oldInit = Preload.hideSplashScreen

    Preload.hideSplashScreen = function () {
        var result = oldInit.apply(this, arguments)
        initShinySynapse()
        return result
    }
}

var scriptName = 'syntheticshinysynapse'

if (document.getElementById('scriptHandler') != undefined) {
    var scriptElement = document.createElement('div')
    scriptElement.id = scriptName
    document.getElementById('scriptHandler').appendChild(scriptElement)
    if (localStorage.getItem(scriptName) != null) {
        if (localStorage.getItem(scriptName) == 'true') {
            loadScript()
        }
    }
    else {
        localStorage.setItem(scriptName, 'true')
        loadScript()
    }
}
else {
    loadScript();
}

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}