Checklist Buttons

Adds a button to automatically copy page source, and open checklist pages

Fra 24.09.2021. Se den seneste versjonen.

// ==UserScript==
// @name         Checklist Buttons
// @namespace    Neopets
// @version      1.1.3
// @description  Adds a button to automatically copy page source, and open checklist pages
// @match        *://www.neopets.com/books_read.phtml?pet_name=*
// @match        *://items.jellyneo.net/tools/book-checklist/
// @match        *://www.neopets.com/moon/books_read.phtml?pet_name=*
// @match        *://items.jellyneo.net/tools/booktastic-checklist/
// @match        *://www.neopets.com/gourmet_club.phtml?pet_name=*
// @match        *://items.jellyneo.net/tools/gourmet-checklist/
// @match        *://www.neopets.com/dome/*
// @match        *://battlepedia.jellyneo.net/?go=challenger_checklist
// @match        *://www.neopets.com/neoboards/preferences.phtml
// @match        *://www.jellyneo.net/avatars/
// @grant        GM_openInTab
// @grant        GM_setValue
// @grant        GM_getValue
// @author       themagicteeth
// ==/UserScript==


function makeButton(text) {
  const copyButton = document.createElement("button")  // Create the button element
  copyButton.innerText = text // Button text
  copyButton.style.margin = "0 0.5em"  // Styling for the button
  return copyButton
}

// Set onClick of button to open the link in new tab
function setOnClick(button, url) {
  button.onclick = e => {
    GM_openInTab(url)
  }
}

if (!document.URL.includes("jellyneo")) {
  GM_setValue("source", document.documentElement.outerHTML)
}

// Booktastic books
if (document.URL.includes("moon")) {
  const beforeButton = document.querySelector("#content > table > tbody > tr > td.content > center:nth-child(11) > p > a > img")
  const newButton = makeButton("Check needed books!")
  newButton.style.display = "block"
  beforeButton.after(newButton)
  setOnClick(newButton, "https://items.jellyneo.net/tools/booktastic-checklist/")
}

// Book club
if (document.URL.includes("books_read") && !document.URL.includes("moon")) {
  const beforeButton = document.querySelector("#content > table > tbody > tr > td.content > center:nth-child(7) > p > a > img")
  const newButton = makeButton("Check needed books!")
  newButton.style.display = "block"
  newButton.style.margin = "1em  0.5em"
  beforeButton.after(newButton)
  setOnClick(newButton, "https://items.jellyneo.net/tools/book-checklist/")
}

// Book club and Booktastic books
if (document.URL.includes("book-checklist") || document.URL.includes("booktastic-checklist")) {
  document.getElementById("checklist-hide-boring").checked = true

  // Change this if you want
  // 10 DOES NOT WORK ON BOOKTASTICK BOOKS!!!
  // 1: name, 2: price, 3: release, 4: SDB order, 5: price, 9: added to item DB, 10: category/shop
  document.getElementById("checklist-sort-by").value = 2

  document.getElementById("checklist-code").value = GM_getValue("source")
}

// Gourmet club
if (document.URL.includes("gourmet_club")) {
  const beforeButton = document.querySelector("#content > table > tbody > tr > td.content > div > img")
  const newButton = makeButton("Check needed foods!")
  newButton.style.display = "block"
  newButton.style.margin = "1em  0.5em"
  beforeButton.after(newButton)
  setOnClick(newButton, "https://items.jellyneo.net/tools/gourmet-checklist/")
}

if (document.URL.includes("gourmet-checklist")) {
  document.getElementById("checklist-hide-yuck").checked = true

  // Change this if you want
  // 1: name, 2: rarity, 3: release, 4: SDB order, 5: price, 9: added to item DB, 10: category/shop
  document.getElementById("checklist-sort-by").value = 2

  document.getElementById("checklist-code").value = GM_getValue("source")
}

// Battledome
if (document.URL.includes("dome")) {
  const beforeButton = document.getElementById("bdNav")
  const newButton = makeButton("Check missing challengers!")
  newButton.style.display = "block"
  newButton.style.margin = "0 auto"
  beforeButton.after(newButton)
  setOnClick(newButton, "http://battlepedia.jellyneo.net/?go=challenger_checklist")
}

if (document.URL.includes("challenger_checklist")) {
  document.querySelector("textarea[name='challengerHTML']").value = GM_getValue("source")
}

// Avatars
if (document.URL.includes("neoboards")) {
  const beforeButton = document.querySelector("#content > table > tbody > tr > td.content > form > table:nth-child(4) > tbody > tr:nth-child(2) > td:nth-child(2) > select")
  const newButton = makeButton("Check missing avatars!")
  newButton.style.display = "block"
  newButton.style.margin = ".5em"
  beforeButton.after(newButton)
  setOnClick(newButton, "https://www.jellyneo.net/avatars/")
  
}

if (document.URL.includes("avatars")) {
  document.getElementById("avatarInput").value = GM_getValue("source")
  document.querySelector("input[name='excludeRetired'").checked = true
}