Onetwo
03-11-2024, 09:20 PM
I'm attempting to bypass having to open the shop pages from the shop wizard and having to click the item link to buy the item. I'm using tampermonkey. Currently I'm getting the link the the user shop, find the item I want to buy and extracting the link. The link looks something like this
[Only registered and activated users can see links]
When I attempt to submit, fetch, ect that link I get this error
Error: You have been directed to this page from the wrong place! If you KEEP getting this error, chances are you have some security settings enabled that are not letting you play Neopets correctly.
These are three of my attempts:
// 1) Open the URL in the current tab
window.location.href = fullUrl;
// 2) Create a temporary anchor element
const tempAnchor = document.createElement('a');
tempAnchor.href = fullUrl;
// Simulate a click event on the temporary anchor element
tempAnchor.click();
// 3) Open the URL in a new tab using GM_openInTab
GM_openInTab(link, { active: true });
But all of them result in the same error. My next idea was to directly open the link it a background tab/instance and simulate some kind of a manual click on the item.... But I don't know why I need to do it this way or if it will even work. I'm not sure what security feature this is and I don't know how the link on the shop page is supposed to work. Even when I'm ON that exact page if I inspect the link and directly click the link I get the error.
I assume that when I inspect the HTML of the page and manually click on the link, I might be bypassing certain checks or conditions that the website has put in place.
Can someone help me solve this issue or have any insights on how to get around this error?
(30 mintues later)
I noticed that if I print tempAnchor element I get this
<a href="buy_item.phtml?lower=0&owner=unwaanted&obj_info_id =77146&g=1&xhs=65rso632&old_price=2&feat=77146,2,1 &_ref_ck=681aab1d676214dcbb6b240bbd52786c" onclick="if ( !confirm ('Are you sure you wish to buy Checkered Faerie Blumaroo Plushie at 2 NP?') ) { return false; }"><img src="[Only registered and activated users can see links]" width="80" height="80" title="This delightfully soft Checkered Faerie Blumaroo Plushie is a pleasure to cuddle with." border="1"></a>
Notice the confirmation event handler! That seems interesting...
So I tried this
// Step 1: Programmatically click the anchor element within the fetched document's context
firstAnchor.click();
// Step 2: Monitor for the confirmation dialog and programmatically confirm it within the fetched document's context
firstAnchor.ownerDocument.defaultView.addEventList ener('beforeunload', function(e) {
// Check if the event is triggered by the confirmation dialog
if (e.target.activeElement.tagName === 'BODY') {
// Programmatically confirm the dialog
return true;
}
});
An it gives the error "TypeError: Cannot read properties of null (reading 'addEventListener')"
[Only registered and activated users can see links]
When I attempt to submit, fetch, ect that link I get this error
Error: You have been directed to this page from the wrong place! If you KEEP getting this error, chances are you have some security settings enabled that are not letting you play Neopets correctly.
These are three of my attempts:
// 1) Open the URL in the current tab
window.location.href = fullUrl;
// 2) Create a temporary anchor element
const tempAnchor = document.createElement('a');
tempAnchor.href = fullUrl;
// Simulate a click event on the temporary anchor element
tempAnchor.click();
// 3) Open the URL in a new tab using GM_openInTab
GM_openInTab(link, { active: true });
But all of them result in the same error. My next idea was to directly open the link it a background tab/instance and simulate some kind of a manual click on the item.... But I don't know why I need to do it this way or if it will even work. I'm not sure what security feature this is and I don't know how the link on the shop page is supposed to work. Even when I'm ON that exact page if I inspect the link and directly click the link I get the error.
I assume that when I inspect the HTML of the page and manually click on the link, I might be bypassing certain checks or conditions that the website has put in place.
Can someone help me solve this issue or have any insights on how to get around this error?
(30 mintues later)
I noticed that if I print tempAnchor element I get this
<a href="buy_item.phtml?lower=0&owner=unwaanted&obj_info_id =77146&g=1&xhs=65rso632&old_price=2&feat=77146,2,1 &_ref_ck=681aab1d676214dcbb6b240bbd52786c" onclick="if ( !confirm ('Are you sure you wish to buy Checkered Faerie Blumaroo Plushie at 2 NP?') ) { return false; }"><img src="[Only registered and activated users can see links]" width="80" height="80" title="This delightfully soft Checkered Faerie Blumaroo Plushie is a pleasure to cuddle with." border="1"></a>
Notice the confirmation event handler! That seems interesting...
So I tried this
// Step 1: Programmatically click the anchor element within the fetched document's context
firstAnchor.click();
// Step 2: Monitor for the confirmation dialog and programmatically confirm it within the fetched document's context
firstAnchor.ownerDocument.defaultView.addEventList ener('beforeunload', function(e) {
// Check if the event is triggered by the confirmation dialog
if (e.target.activeElement.tagName === 'BODY') {
// Programmatically confirm the dialog
return true;
}
});
An it gives the error "TypeError: Cannot read properties of null (reading 'addEventListener')"