Untitled

 avatar
unknown
plain_text
2 years ago
7.6 kB
3
Indexable
// ==UserScript==
// @name         Mannco.Store Giveway Enhancer
// @namespace    https://github.com/LucasHenriqueDiniz
// @version      0.1
// @description  ...
// @author       Lucas Diniz
// @match        https://mannco.store/giveaways
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mannco.store
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @grant        none
// ==/UserScript==



(function () {
  // join and leave giveway functions
  function join(url) {
    let raffle = url;
    $.ajax({
      method: "GET",
      xhrFields: {
        withCredentials: true
      },
      url: `/requests/raffle.php?mode=join&url=${url}`
    }).done(function (response) {
      if (response.indexOf('ok') != -1) {
        console.log('.rafflejoined')
        $('.rafflejoined').show();
        $('.raffleenter').hide();
      } else {
        Type.alert.error('Error', "This is full");
      }
    });
  }
  function leave(url) {
    let raffle = url;
    $.ajax({
      method: "GET",
      xhrFields: {
        withCredentials: true
      },
      url: `/requests/raffle.php?mode=leave&url=${url}`
    }).done(function (response) {
      if (response.indexOf('ok') != -1) {
        console.log('.raffleenter')
        $('.raffleenter').show();
        $('.rafflejoined').hide();
      } else {

      }
    });
  }

// Seleciona o elemento onde o texto será adicionado
const header = document.querySelector("#wrapper > div.page-header > div > div");

// Cria o elemento span e adiciona o texto inicial
const missingText = document.createElement("span");
missingText.textContent = "Missing 0 giveaways!";
missingText.color = 'red';
missingText.padding = '5px';
missingText.fontSize = '15px';

// Adiciona o elemento span ao header
header.appendChild(missingText);

// Variável para controlar o número de giveaways faltando
let missingGiveaways = 0;

// Função para atualizar o valor de missingGiveaways e o texto do span
function updateMissingGiveaways(newNumber) {
  missingGiveaways = newNumber;
  missingText.textContent = "Missing " + missingGiveaways + " giveaways!";
}

  // create the buttons
  window.addEventListener('load', function () {
    function EXECUTADA(raffles) {

      for (let i = 0; i < referenceElements.length; i++) {
          const href = referenceElements[i].href;
          const giveawayId = href.split("/giveaways/details/").pop();
          if (raffles.indexOf(giveawayId) != -1){
              referenceElements[i].style.border = 'none';

          } else {
              referenceElements[i].style.border = '2px solid red';
              referenceElements[i].style.boxSizing = 'border-box';
              updateMissingGiveaways =+ 1
          }
      }
  }
    fetch("https://mannco.store/requests/raffle.php?mode=getJoined")
    .then(response => response.text())
    .then(data => {
     const raffles = data.split(',');
     EXECUTADA(raffles);
    })
    .catch(error => console.error(error));

    Type.alert.success('Welcome', '')
    Type.createPagination(1000, 1, 'raffleitem', '')
    document.querySelector("#main > div > nav").remove()

    // Cache DOM queries
    const parentElement = document.querySelector("#main > div > div").parentElement;
    const referenceElements = document.querySelectorAll("#main > div > div > a");

    // Define the CSS display property of the parent element as flex
    parentElement.style.display = "flex";

    // Create a new div element
    const newElement = document.createElement("div");
    // Set some properties for the new div element
    newElement.classList.add("raffle-buttons");
    newElement.style.flexGrow = "1";
    newElement.style.flexShrink = "1";
    // Add the new element to the parent element
    parentElement.appendChild(newElement);

    // Loop through reference elements
    for (let i = 0; i < referenceElements.length; i++) {


      const button = document.createElement('button');
      button.textContent = 'Enter';
      button.value = false
      button.style.cssText =
        `border-radius: 0;
              font-family: inherit;
              overflow: visible;
              text-transform: none;
              -webkit-appearance: button;
              cursor: pointer;
              line-height: 1.5;
              -webkit-font-smoothing: antialiased;
              text-rendering: optimizeLegibility;
              font-weight: 500;
              transition: color .125s ease-in-out;
              width: 25%;
              border: none;
              background-color: #3a3c5f;
              color: #fff;
              align-content: space-around;
              display: flex;
              justify-content: space-between;
              box-sizing: border-box;
              border-bottom: 1px solid #232439;
              margin: 0;
              padding: 1.5rem 4.5rem 1.5rem 2rem;
              text-align: inherit;
              position: relative;
              `;

      if (i === 0) {
        button.style.borderTopLeftRadius = '1rem';
        button.style.borderTopRightRadius = '1rem';
        button.style.borderTop = 'solid';
        button.style.borderColor = '#161726';
        button.style.borderWidth = "thin";
      } else if (i === referenceElements.length - 1) {
        button.style.borderBottomRightRadius = '1rem';
        button.style.borderBottomLeftRadius = '1rem';
        button.style.borderBottom = 'solid';
        button.style.borderColor = '#161726';
        button.style.borderWidth = "thin";
      }

      const reference = referenceElements[i];
      const referenceRectX = reference.getBoundingClientRect();
      const buttonRect = button.getBoundingClientRect();
      const widthDiff = referenceRectX.width - buttonRect.width;
      button.style.height = `${buttonRect.height + widthDiff}px`;

      const referenceRect = parentElement.getBoundingClientRect();

      // Set the dimensions of the new element
      newElement.style.width = '5%';
      newElement.style.justifyContent = 'space-between';
      newElement.style.display = 'flex';
      newElement.style.flexDirection = 'column';
      newElement.style.height = `${referenceRect.height}px`;
      newElement.appendChild(button);

      function activateButton() {
        Type.alert.success('Sucess!', 'You entered the giveway')
        console.log('Leave');
        if (button.value === false) { // verifica se o valor atual do botão é correto
          button.textContent = 'Leave';
          button.style.backgroundColor = 'red';
          button.value = true; // atualiza o valor do botão
        }
      }

      function deactivateButton() {
        Type.alert.error(':(', 'You left the giveway')
        console.log('Enter');
        if (button.value === true) { // verifica se o valor atual do botão é correto
          button.textContent = 'Enter';
          button.style.backgroundColor = 'green';
          button.value = false; // atualiza o valor do botão
        }
      }

      button.onclick = function (event) {
        //var currentHTML = parentElement[i].href.replace('https://mannco.store/giveaways/details/', '')
        if (button.value === false) {
          //join(currentHTML)
          activateButton();
          button.value = true;
        } else {
          //leave(currentHMTL)
          deactivateButton();
          button.value = false;
        }

      };
    };
  })
})();
Editor is loading...