Modifies the active pet sayings, how often they appear, and who says what (automatically detecting active pet by name).
当前为
// ==UserScript==
// @name Neopets - Custom Active Pet Sayings (Ver.1)
// @namespace http://www.neopets.com/
// @include http://www.neopets.com/*
// @include https://www.neopets.com/*
// @description Modifies the active pet sayings, how often they appear, and who says what (automatically detecting active pet by name).
// @copyright baffleblend
// @grant none
// @version 0.0.1.20191130165949
// ==/UserScript==
function id(el,id) {return el.getElementById(id);}
function cl(el,cls) {return el.getElementsByClassName(cls);}
function tg(el,tag) {return el.getElementsByTagName(tag);}
function at(el,att) {return el.getAttribute(att);}
function rnd(limit) {return Math.ceil(Math.random() * limit)}
function hide(el){el.style.display="none";}
//Grabs where phrase box will go
var activePetInfo = tg(cl(document,"sidebarTable")[0],"tr"); //Grabs the module where the active pet's information is stored
var insertionPoint = activePetInfo[2];//This grabs the point where the dialog box would appear
//Inserts the custom phrase as HTML
function insertPhrase(insertPoint,petName,currentPhrase){
var HTMLPhrase = "<tr><td class=\"neopetPhrase sf myPhrase\" align=\"center\"><b>" + petName + " says:</b><br>" + currentPhrase + "</td></tr>";
insertPoint.insertAdjacentHTML('beforebegin',HTMLPhrase);
}
//After the pet's been chosen and the phrases have been narrowed down, this picks the specific one.
function grabFromList(list,limit){
var phrID = Math.ceil(Math.random() * limit);
if (phrID == null || phrID == 0 || phrID == undefined){ //Error handler
return "You haven\'t set any phrases for me yet!";
}
else {
return list[phrID];
}
}
function randomlyActivate(){//The rest of the script gets ignored unless this function returns True (the amount which is set below)
/////////////////////////////////////////////////
//CONFIGURATION - FREQUENCY
/////////////////////////////////////////////////
var phraseFrequency = 18;//% of page refreshes will have the pet speak; default is 18%
/////////////////////////////////////////////////
var check = rnd(100);
if (check <= phraseFrequency) {
return true;
}
else {
return false;
}
}
function mainScript() {//Separate function so that it can be ignored if randomlyActivate returns false
var actpetname = tg(cl(document,"sidebartable")[0],"b")[0].textContent;
//Detects current active pet's name
function selectPhrases(list,currentName){ //Hunts through pet list and grabs phrase, along with error trap.
var finalPhrase = "";
var errorTrap = "You haven\'t set any phrases for me yet!"; //If pet is not found, they'll say this by default
var i;
var limit = list.length - 1;
for (i = 0, limit = list.length - 1; i < limit; ++i){ //Look for the active pet's name until the end of the list
var result = i;
if (list[result][0] == currentName) {
var newLimit = list[result].length-1;
finalPhrase = grabFromList(list[result],newLimit);
break;
}
else {
finalPhrase = errorTrap;
}
}
return finalPhrase;
}
//Creates array with all pets and their phrases
var petList = [
/////////////////////////////////////////////////
//CONFIGURATION - YOUR PETS
/////////////////////////////////////////////////
//Type all of your pets' names,
//followed by the phrases you want them to say, with a comma after each until the end of the list.
//Don't forget to put a "\" before apostrophes or quote marks if you want them to appear.
//See the following example for what I mean.
["Your_First_Main_Account_Pet",
"A Tiki Tour sounds good right about now!",
"Why don\'t you just paint me grey if you're gonna leave me like this?",
]//,
//["Your_Second_Main_Account_Pet",
// "Seen any good concerts lately?",
// "I think some strength training is in order, don\'t you?",
// ],
//["Your_Third_Main_Account_Pet",
// "Destruct-O-Match sounds like fun right about now.",
// "AH! BEHIND YOU!<br>Just kidding!"
//["Your_First_Side_Account_Pet",
// "When\'s the last time we visited the Techo Master?",
// "Today doesn\'t seem to be a very good day."
// ]
/////////////////////////////////////////////////];
];
var thePhrase = selectPhrases(petList,actpetname);
insertPhrase(insertionPoint,actpetname,thePhrase);
}
var runFlag = randomlyActivate();
var existingPhrase = cl(document,"neopetPhrase");//Check if a phrase is already being generated site-side; if it is, then removes it
if (existingPhrase[0] != undefined) {//If the site hasn't generated a phrase, do nothing
existingPhrase[0].remove();
}
if (runFlag == true){
mainScript();}