PDA

View Full Version : Small trouble with W35l3y's Pyramids Player GM script.. Help fixing/modifying?



ylfogdrib
10-04-2017, 08:55 AM
Hello!

W35l3y's pyramids player GM script ([Only registered and activated users can see links]) works great, except for sometimes the inner content frame just goes blank. Like the neopets top, bottom, and side bars are all there, just where "Pyramids" and the actual game should be is just all white. All I have to do is refresh and it brings me back to "continue game" and the script starts right back up, but I usually let it run while I do things away from the computer, and it's annoying to come back to find a blank screen and barely any neopoints!

I don't know enough about JS to figure out what's actually going wrong, (so if anyone could figure that out, that would be great!), but with the teeny tiny bit I do know, I was able to modify the script so that it automatically refreshes the page every 5 or so minutes, which essentially fixes the problem. However, the script originally stops running when you reach your neopoint limit. With my modification, the page eventually refreshes and the script starts again, which I would rather it not do... So, I was hoping someone could help me figure out how to make the refreshing function stop once the neopoint limit is reached. Hopefully this was the right place to post this.

Here's what I have so far.. the refreshing works, the stopping of refreshing does not. My modifications are in red; if you remove those it should be the original W35l3y script.



AjaxUpdate.init({
[Only registered and activated users can see links]
[Only registered and activated users can see links]
onsuccess : function (obj) {
[Only registered and activated users can see links]
next = function (p) {
return setTimeout(obj.next, 564 + Math.ceil(239 * Math.random()), p);
};

if (x) {
var start = -1;

[Only registered and activated users can see links]
var waitFive = Math.floor(Math.random() * 60001 + 300000);
var phresh = setInterval(function(){ location.reload(); }, waitFive);

if (!xpath("boolean(.//div[2]/p[3]/b[2]/text())", obj.document)) {
start = 0;
}
} else if (xpath("boolean(.//div[2]/p[1]/b[8]/text())", obj.document)) { // reached daily limit
start = 1;
function clearPhresh() {
clearInterval(phresh);
}
[Only registered and activated users can see links]
// x.href = x.href.replace("/pyramids.phtml?action=collect", "/index.phtml?action=cancel");
}

if (start) {
GM_deleteValue("cards");
}

if (1 != start) {
next(x);
}
} else {
[Only registered and activated users can see links]
var value = parseInt(RegExp.$1, 10),
pile = "cdhs".indexOf(RegExp.$2[0]) + 4 * (value - 2),
cards = JSON.parse(GM_getValue("cards", "{}")),
[Only registered and activated users can see links]
acards = [],
choices = [];

cards[pile] = {
type : 2, // pile
value : value,
};

[Only registered and activated users can see links]
if (/\/(\d+)_(\w)/.test(card.src)) {
value = parseInt(RegExp.$1, 10);

var index = "cdhs".indexOf(RegExp.$2[0]) + 4 * (value - 2),
left = card.parentNode.previousElementSibling && card.parentNode.previousElementSibling,
right = card.parentNode.nextElementSibling && card.parentNode.nextElementSibling,
freed = 0;

if (left && /blank/.test(left.src)) {
++freed;
}
if (right && /blank/.test(right.src)) {
++freed;
}

acards.push(index);
cards[index] = {
link : card.parentNode.href,
type : 1, // face-up
level : xpath("./ancestor::tr[1]", card)[0].rowIndex,
freed : freed,
value : value,
};
}
}

for (var ai = 8, at = (52 + 4 * Math.floor((pile - 4) / 4)) % 52;ai;--ai,++at) {
if (4 == ai) {
at += 4;
at %= 52;
}

if (cards[at] && 1 == cards[at].type) {
choices.push(at);
}
}

if (!choices.length) {
next(draw || {
action : cards[acards[Math.floor(acards.length * Math.random())]].link,
});
} else if (1 == choices.length) {
var card = cards[choices[0]];
card.type = -1; // play
next({
action : card.link,
});
} else {
for (var ai in choices) {
var same = [0, 0];

for (var bi in cards) {
if (cards[choices[ai]].value == cards[bi].value) {
++same[~~(2 == cards[choices[ai]].type)];
}
}

cards[choices[ai]].same = same;
}

choices.sort(function (a, b) {
var cA = cards[a],
cB = cards[b];

// this can be improved to select a better option to form a greater sequence of cards
if (cA.freed == cB.freed) { // same freed cards
if (cA.same[1] == cB.same[1]) { // same number (pile)
if (cA.same[0] == cB.same[0]) { // same number
if (cA.level == cB.level) { // same card level
return 0;
} else {
return (cA.level > cB.level?-1:1); // desc
}
} else {
return (cA.same[0] > cB.same[0]?-1:1); // desc
}
} else {
return (cA.same[1] > cB.same[1]?1:-1); // asc
}
} else {
return (cA.freed > cB.freed?-1:1); // desc
}
});

var card = cards[choices.shift()];
card.type = -1; // play
next({
action : card.link,
});
}

GM_setValue("cards", JSON.stringify(cards));
}
}
},
});


It's not a big deal, so if it's a difficult thing to do, then no worries! I just figured I was doing something dumb and someone who actually understood Javascript could probably fix it up for me real quick.

Thank you!!

npm
10-04-2017, 10:08 AM
AjaxUpdate.init({
[Only registered and activated users can see links]
[Only registered and activated users can see links]
onsuccess : function (obj) {
[Only registered and activated users can see links]
next = function (p) {
return setTimeout(obj.next, 564 + Math.ceil(239 * Math.random()), p);
};

if (x) {
var start = -1;

[Only registered and activated users can see links]
var waitFive = Math.floor(Math.random() * 60001 + 300000);
var phresh = setInterval(function(){ location.reload(); }, waitFive);

if (!xpath("boolean(.//div[2]/p[3]/b[2]/text())", obj.document)) {
start = 0;
}
} else if (xpath("boolean(.//div[2]/p[1]/b[8]/text())", obj.document)) { // reached daily limit
start = 1;
// function clearPhresh() {
clearInterval(phresh);
// }
[Only registered and activated users can see links]
// x.href = x.href.replace("/pyramids.phtml?action=collect", "/index.phtml?action=cancel");
}

if (start) {
GM_deleteValue("cards");
}

if (1 != start) {
next(x);
}
} else {
[Only registered and activated users can see links]
var value = parseInt(RegExp.$1, 10),
pile = "cdhs".indexOf(RegExp.$2[0]) + 4 * (value - 2),
cards = JSON.parse(GM_getValue("cards", "{}")),
[Only registered and activated users can see links]
acards = [],
choices = [];

cards[pile] = {
type : 2, // pile
value : value,
};

[Only registered and activated users can see links]
if (/\/(\d+)_(\w)/.test(card.src)) {
value = parseInt(RegExp.$1, 10);

var index = "cdhs".indexOf(RegExp.$2[0]) + 4 * (value - 2),
left = card.parentNode.previousElementSibling && card.parentNode.previousElementSibling,
right = card.parentNode.nextElementSibling && card.parentNode.nextElementSibling,
freed = 0;

if (left && /blank/.test(left.src)) {
++freed;
}
if (right && /blank/.test(right.src)) {
++freed;
}

acards.push(index);
cards[index] = {
link : card.parentNode.href,
type : 1, // face-up
level : xpath("./ancestor::tr[1]", card)[0].rowIndex,
freed : freed,
value : value,
};
}
}

for (var ai = 8, at = (52 + 4 * Math.floor((pile - 4) / 4)) % 52;ai;--ai,++at) {
if (4 == ai) {
at += 4;
at %= 52;
}

if (cards[at] && 1 == cards[at].type) {
choices.push(at);
}
}

if (!choices.length) {
next(draw || {
action : cards[acards[Math.floor(acards.length * Math.random())]].link,
});
} else if (1 == choices.length) {
var card = cards[choices[0]];
card.type = -1; // play
next({
action : card.link,
});
} else {
for (var ai in choices) {
var same = [0, 0];

for (var bi in cards) {
if (cards[choices[ai]].value == cards[bi].value) {
++same[~~(2 == cards[choices[ai]].type)];
}
}

cards[choices[ai]].same = same;
}

choices.sort(function (a, b) {
var cA = cards[a],
cB = cards[b];

// this can be improved to select a better option to form a greater sequence of cards
if (cA.freed == cB.freed) { // same freed cards
if (cA.same[1] == cB.same[1]) { // same number (pile)
if (cA.same[0] == cB.same[0]) { // same number
if (cA.level == cB.level) { // same card level
return 0;
} else {
return (cA.level > cB.level?-1:1); // desc
}
} else {
return (cA.same[0] > cB.same[0]?-1:1); // desc
}
} else {
return (cA.same[1] > cB.same[1]?1:-1); // asc
}
} else {
return (cA.freed > cB.freed?-1:1); // desc
}
});

var card = cards[choices.shift()];
card.type = -1; // play
next({
action : card.link,
});
}

GM_setValue("cards", JSON.stringify(cards));
}
}
},
});


Right now im at work, but with a quickly look your function to clear the interval its defined but never actually called so that's why it keeps refreshing, you can try this two approaches:

add comment lines to your function and call the clearInterval function directly.


// function clearPhresh() {
clearInterval(phresh);
// }


Instead of a normal function you can use an anonymous function:


(function(){
clearInterval(phresh);
})(this);


Let me know if this fix the problem, if not to take a deep look into the code.

ylfogdrib
10-04-2017, 02:38 PM
Let me know if this fix the problem, if not to take a deep look into the code.

Oh duh, thank you!!

Unfortunately, that does not appear to have fixed the problem (I tried both ways). I also tried changing it from Interval to Timeout, and from the variable time (waitFive) to a static number of MS, neither of which worked.

I also tried this instead:


AjaxUpdate.init({
[Only registered and activated users can see links]
[Only registered and activated users can see links]
onsuccess : function (obj) {
[Only registered and activated users can see links]
next = function (p) {
return setTimeout(obj.next, 564 + Math.ceil(239 * Math.random()), p);
};

setInterval(phresh(), 1000);

function phresh() {
if (!xpath("boolean(.//div[2]/p[1]/b[8]/text())", obj.document)) {
var waitFive = Math.floor(Math.random() * 5001 + 30000);
var rephresh = setTimeout(function(){ location.reload(); }, waitFive);
} else if (xpath("boolean(.//div[2]/p[1]/b[8]/text())", obj.document)) {
clearTimeout(rephresh);
clearInterval(phresh);
}
};


if (x) {
var start = -1;

[Only registered and activated users can see links]
if (!xpath("boolean(.//div[2]/p[3]/b[2]/text())", obj.document)) {
start = 0;
}
} else if (xpath("boolean(.//div[2]/p[1]/b[8]/text())", obj.document)) { // reached daily limit
start = 1;
[Only registered and activated users can see links]
// x.href = x.href.replace("/pyramids.phtml?action=collect", "/index.phtml?action=cancel");
}

if (start) {
GM_deleteValue("cards");
}

if (1 != start) {
next(x);
}
} else {
[Only registered and activated users can see links]
var value = parseInt(RegExp.$1, 10),
pile = "cdhs".indexOf(RegExp.$2[0]) + 4 * (value - 2),
cards = JSON.parse(GM_getValue("cards", "{}")),
[Only registered and activated users can see links]
acards = [],
choices = [];

cards[pile] = {
type : 2, // pile
value : value,
};

[Only registered and activated users can see links]
if (/\/(\d+)_(\w)/.test(card.src)) {
value = parseInt(RegExp.$1, 10);

var index = "cdhs".indexOf(RegExp.$2[0]) + 4 * (value - 2),
left = card.parentNode.previousElementSibling && card.parentNode.previousElementSibling,
right = card.parentNode.nextElementSibling && card.parentNode.nextElementSibling,
freed = 0;

if (left && /blank/.test(left.src)) {
++freed;
}
if (right && /blank/.test(right.src)) {
++freed;
}

acards.push(index);
cards[index] = {
link : card.parentNode.href,
type : 1, // face-up
level : xpath("./ancestor::tr[1]", card)[0].rowIndex,
freed : freed,
value : value,
};
}
}

for (var ai = 8, at = (52 + 4 * Math.floor((pile - 4) / 4)) % 52;ai;--ai,++at) {
if (4 == ai) {
at += 4;
at %= 52;
}

if (cards[at] && 1 == cards[at].type) {
choices.push(at);
}
}

if (!choices.length) {
next(draw || {
action : cards[acards[Math.floor(acards.length * Math.random())]].link,
});
} else if (1 == choices.length) {
var card = cards[choices[0]];
card.type = -1; // play
next({
action : card.link,
});
} else {
for (var ai in choices) {
var same = [0, 0];

for (var bi in cards) {
if (cards[choices[ai]].value == cards[bi].value) {
++same[~~(2 == cards[choices[ai]].type)];
}
}

cards[choices[ai]].same = same;
}

choices.sort(function (a, b) {
var cA = cards[a],
cB = cards[b];

// this can be improved to select a better option to form a greater sequence of cards
if (cA.freed == cB.freed) { // same freed cards
if (cA.same[1] == cB.same[1]) { // same number (pile)
if (cA.same[0] == cB.same[0]) { // same number
if (cA.level == cB.level) { // same card level
return 0;
} else {
return (cA.level > cB.level?-1:1); // desc
}
} else {
return (cA.same[0] > cB.same[0]?-1:1); // desc
}
} else {
return (cA.same[1] > cB.same[1]?1:-1); // asc
}
} else {
return (cA.freed > cB.freed?-1:1); // desc
}
});

var card = cards[choices.shift()];
card.type = -1; // play
next({
action : card.link,
});
}

GM_setValue("cards", JSON.stringify(cards));
}
}
},
});

But no luck.

It's really not a big deal, so I don't want anyone spending much time on it! I'm just frustrated that I can't figure it out, lol.

Thanks again!!