Results 1 to 3 of 3

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

  1. #1

    Joined
    Sep 2017
    Posts
    11
    Userbars
    0
    Thanks
    18
    Thanked
    19/3
    DL/UL
    1/0
    Mentioned
    5 times
    Time Online
    17h 4m
    Avg. Time Online
    N/A

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

    Hello!

    (you need an account to 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.

    Code:
    AjaxUpdate.init({
    	root		: "id('content')/table/tbody/tr/td[2]/div/div[@class = 'frame']",
    	triggers	: ".//a[contains(@href, '?action=')]|.//form[contains(@action, 'pyramids')]",
    	onsuccess	: function (obj) {
    		var x = xpath(".//a[contains(@href, 'action=collect')]|.//form[contains(@action, 'pyramids.phtml')]", obj.document)[0],
    		next = function (p) {
    			return setTimeout(obj.next, 564 + Math.ceil(239 * Math.random()), p);
    		};
    
    		if (x) {
    			var start = -1;
    
    			if (xpath("boolean(.//div/div[1]/p/img[contains(@src, 'pyramids_front')])", obj.document)) {
    			        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);
    				}
    //			} else if (x.href && !xpath("boolean(.//center/table/tbody/tr[1]/td/img[contains(@src, '/images/blank.gif')])", obj.document)) { // not cleared = cancel
    //				x.href = x.href.replace("/pyramids.phtml?action=collect", "/index.phtml?action=cancel");
    			}
    
    			if (start) {
    				GM_deleteValue("cards");
    			}
    
    			if (1 != start) {
    				next(x);
    			}
    		} else {
    			if (/\/(\d+)_(\w)/.test(xpath("string(.//tr[2]/td/table/tbody/tr[1]/td/img[position() = last()]/@src)", obj.document))) {
    				var value = parseInt(RegExp.$1, 10),
    				pile = "cdhs".indexOf(RegExp.$2[0]) + 4 * (value - 2),
    				cards = JSON.parse(GM_getValue("cards", "{}")),
    				draw = xpath(".//a[contains(@href, 'action=draw')]", obj.document)[0],
    				acards = [],
    				choices = [];
    
    				cards[pile] = {
    					type	: 2,	// pile
    					value	: value,
    				};
    
    				for each (var card in xpath(".//tr[2]/td/center/table/tbody/tr/td/a/img[contains(@src, '_')]", obj.document)) {
    					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!!

  2. #2
    npm's Avatar
    Joined
    Dec 2011
    Posts
    813
    Userbars
    15
    Thanks
    735
    Thanked
    564/219
    DL/UL
    84/3
    Mentioned
    109 times
    Time Online
    83d 21h 28m
    Avg. Time Online
    28m
    Quote Originally Posted by ylfogdrib View Post

    Code:
    AjaxUpdate.init({
        root        : "id('content')/table/tbody/tr/td[2]/div/div[@class = 'frame']",
        triggers    : ".//a[contains(@href, '?action=')]|.//form[contains(@action, 'pyramids')]",
        onsuccess    : function (obj) {
            var x = xpath(".//a[contains(@href, 'action=collect')]|.//form[contains(@action, 'pyramids.phtml')]", obj.document)[0],
            next = function (p) {
                return setTimeout(obj.next, 564 + Math.ceil(239 * Math.random()), p);
            };
    
            if (x) {
                var start = -1;
    
                if (xpath("boolean(.//div/div[1]/p/img[contains(@src, 'pyramids_front')])", obj.document)) {
                        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);
                    // }
    //            } else if (x.href && !xpath("boolean(.//center/table/tbody/tr[1]/td/img[contains(@src, '/images/blank.gif')])", obj.document)) { // not cleared = cancel
    //                x.href = x.href.replace("/pyramids.phtml?action=collect", "/index.phtml?action=cancel");
                }
    
                if (start) {
                    GM_deleteValue("cards");
                }
    
                if (1 != start) {
                    next(x);
                }
            } else {
                if (/\/(\d+)_(\w)/.test(xpath("string(.//tr[2]/td/table/tbody/tr[1]/td/img[position() = last()]/@src)", obj.document))) {
                    var value = parseInt(RegExp.$1, 10),
                    pile = "cdhs".indexOf(RegExp.$2[0]) + 4 * (value - 2),
                    cards = JSON.parse(GM_getValue("cards", "{}")),
                    draw = xpath(".//a[contains(@href, 'action=draw')]", obj.document)[0],
                    acards = [],
                    choices = [];
    
                    cards[pile] = {
                        type    : 2,    // pile
                        value    : value,
                    };
    
                    for each (var card in xpath(".//tr[2]/td/center/table/tbody/tr/td/a/img[contains(@src, '_')]", obj.document)) {
                        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.
    Code:
    // function clearPhresh() {
                        clearInterval(phresh);
     // }
    Instead of a normal function you can use an anonymous function:
    Code:
    (function(){
    clearInterval(phresh);
    })(this);
    Let me know if this fix the problem, if not to take a deep look into the code.
    Last edited by npm; 10-04-2017 at 10:23 AM.

  3. The Following User Says Thank You to npm For This Useful Post:

    ylfogdrib (10-04-2017)

  4. #3

    Joined
    Sep 2017
    Posts
    11
    Userbars
    0
    Thanks
    18
    Thanked
    19/3
    DL/UL
    1/0
    Mentioned
    5 times
    Time Online
    17h 4m
    Avg. Time Online
    N/A
    Quote Originally Posted by hectorvazc View Post
    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:

    Code:
    AjaxUpdate.init({
    	root		: "id('content')/table/tbody/tr/td[2]/div/div[@class = 'frame']",
    	triggers	: ".//a[contains(@href, '?action=')]|.//form[contains(@action, 'pyramids')]",
    	onsuccess	: function (obj) {
    		var x = xpath(".//a[contains(@href, 'action=collect')]|.//form[contains(@action, 'pyramids.phtml')]", obj.document)[0],
    		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;
    
    			if (xpath("boolean(.//div/div[1]/p/img[contains(@src, 'pyramids_front')])", obj.document)) {
    				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;
    //			} else if (x.href && !xpath("boolean(.//center/table/tbody/tr[1]/td/img[contains(@src, '/images/blank.gif')])", obj.document)) { // not cleared = cancel
    //				x.href = x.href.replace("/pyramids.phtml?action=collect", "/index.phtml?action=cancel");
    			}
    
    			if (start) {
    				GM_deleteValue("cards");
    			}
    
    			if (1 != start) {
    				next(x);
    			}
    		} else {
    			if (/\/(\d+)_(\w)/.test(xpath("string(.//tr[2]/td/table/tbody/tr[1]/td/img[position() = last()]/@src)", obj.document))) {
    				var value = parseInt(RegExp.$1, 10),
    				pile = "cdhs".indexOf(RegExp.$2[0]) + 4 * (value - 2),
    				cards = JSON.parse(GM_getValue("cards", "{}")),
    				draw = xpath(".//a[contains(@href, 'action=draw')]", obj.document)[0],
    				acards = [],
    				choices = [];
    
    				cards[pile] = {
    					type	: 2,	// pile
    					value	: value,
    				};
    
    				for each (var card in xpath(".//tr[2]/td/center/table/tbody/tr/td/a/img[contains(@src, '_')]", obj.document)) {
    					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!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •