PDA

View Full Version : Neopets Stockmarket Sidebar



omg.UFOs
07-02-2020, 04:07 AM
The author of this script hasn't been around for 2 yrs now so I cant get help from him on it.. The issue is this script should be a sidebar that shows a listing of my stocks. usually its under my active pets sidebar, tonight it stopped working properly and started fixing to the top center on my screen..
36316
If you dont mind, can someone look at it?


// ==UserScript==
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
[Only registered and activated users can see links]
// ==/UserScript==

/************************************************** ************************

Author's NOTE

This script was made from scratch.

Based on [Only registered and activated users can see links] (by nungryscpro)

************************************************** *************************

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <[Only registered and activated users can see links]>.

************************************************** ************************/

//GM_getValue("prepend", 1);

/** stockmarket_default **/
var Stocks = {
"Negative" : 2,
"NonPositive" : 3,
"Positive" : 4,
"NonNegative" : 5,
"All" : 7
};
/** /stockmarket_default **/

/** php **/
function time() {
return Math.round(new Date().getTime() / 1000);
}

function strftime(format, ts) {
if (!ts) ts = time();
ts = new Date(ts * 1000);
var out = "", re = /[^%]?%([aAbBcCdDegGhHIjmMnprRStTuUVwWxXyYzZ%])/g;
for (var match, i = 0 ; match = re.exec(format) ; i += 3) {
out += format.substring(Math.max(i - 1, 0), i = match.index+match[0].length - 2);
switch (match[1])
{
// case "h":
case "b":
break;
case "D":
format = format.replace("%D", " %m/%d/%y");
break;
case "T":
format = format.replace("%T"," %H:%M:%S");
break;
case "Y":
out += ts.getFullYear();
break;
case "m":
if (ts.getMonth() < 9) out += "0";
out += 1+ts.getMonth();
break;
case "d":
if (ts.getDate() < 10) out += "0";
out += ts.getDate();
break;
case "H":
if (ts.getHours() < 10) out += "0";
out += ts.getHours();
break;
case "M":
if (ts.getMinutes() < 10) out += "0";
out += ts.getMinutes();
break;
case "S":
if (ts.getSeconds() < 10) out += "0";
out += ts.getSeconds();
break;
case "%":
out += "%";
break;
}
}
return out;
}

function trim(pstr) {
return pstr.replace(/^ \t\n\r\0\x0B| \t\n\r\0\x0B$/g, "");
}

function strip_tags(pstr) {
return pstr.replace(/<(?:\/[^<].*?|[^<].*?(?: \/)?)>/g, "");
}
/** /php **/

/** neopets_default **/
function attachModule(module, prepend) {
var oldElem = xpath('.//td[1]/div[contains(string(table/tbody/tr[1]/td), "' + strip_tags(module.title) + '")]')[0];

var newElem = document.createElement("div");
newElem.setAttribute("class", "sidebarModule");
if (prepend) {
newElem.setAttribute("style", "margin-bottom: 7px;");
} else {
newElem.setAttribute('style','margin-top: 7px;');
}
newElem.innerHTML = '<table width="158" cellpadding="0" cellspacing="0" border="0" class="sidebarTable"><tr><td valign="middle" class="sidebarHeader medText">__TITLE__</td></tr>__CONTENT__</table>'.replace("__TITLE__", module.title || "").replace("__CONTENT__", module.content || "");

if (oldElem) {
xpath("id('content')/table/tbody/tr/td[1]")[0].replaceChild(newElem, oldElem);
} else if (prepend) {
xpath("id('content')/table/tbody/tr/td[1]")[0].insertBefore(newElem, xpath(".//table/tbody/tr/td[1]/div[1]")[0]);
} else {
xpath('id("content")/table/tbody/tr/td[1]')[0].appendChild(newElem);
}
}
/** /neopets_default**/

(function() { // script scope

var user = {
"increment" : GM_getValue("increment", 30000), // miliseconds
"image" : GM_getValue("image", "sell.gif"),
"translate" : JSON.parse(GM_getValue("translate", JSON.stringify(["Stock Summary", "Buys", "Sells", "Ticker", "Price", "Holdings", "Refreshing...", "Options", "Buy Price", "Sell Price", "Close", "Minimum", "Maximum"])))
};

GM_addStyle(".activePetInfo TD {background-color: inherit;};");

function executeContent(cont)
{
var content = cont.replace(/(?:<\/(?:a|td|font|b|nobr)>| [a-z]+="[#a-z0-9]+"|<(?:b|br|nobr|font)(?:\s*\/)?>|\s+)/gim, "");

var portfolio = [],
matches = content.match(/=([a-z]+)">\1<ahref="stockmarket.+?%<\/tr>/gi);
for (var i = 0, t = matches.length ; i < t ; ++i) {
var match = matches[i].match(/>([a-z]+)<ahref="stockmarket\.phtml\?type=profile&(?:amp;)?company_id=(\d+)">.+?<td>(\d+)<td>(\d+)<td><font>([+-]?\d+)<td>(\d+(?:[,.]\d+)*)<td>(\d+(?:[,.]\d+)*)<td>(-?\d+(?:[,.]\d+)*)<td><font>([+-]?\d+[,.]\d+)%/i);
match.shift();
portfolio.push(match);
}
GM_setValue("portfolio", JSON.stringify(portfolio));

var companies = [];

var matches = content.match(/company_id=\d+">.+?>[a-z]+\d+[-+]\d+/gi);
for (var i = 0 , t = matches.length ; i < t ; ++i) {
var match = matches[i].match(/company_id=(\d+)">.+?>([a-z]+)(\d+)([-+]\d+)/i);
match.shift();
if (companies[0] && companies[0][1] == match[1]) {
break;
}

Flordibel
07-02-2020, 11:45 AM
Greasemonkey with Firefox, right?

omg.UFOs
07-02-2020, 06:23 PM
Greasemonkey with Firefox, right?

Tampermonkey, Firefox Nightly. (Nightly works best on neopet flash games.)

It seems to have fixed itself somehow, Thank you for the reply though :)