forked from saahphire/NeopetsUserscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtradingPostButtonsToLinks.js
More file actions
139 lines (132 loc) · 6.4 KB
/
Copy pathtradingPostButtonsToLinks.js
File metadata and controls
139 lines (132 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// ==UserScript==
// @name Neopets: Trading Post Buttons to Links
// @namespace https://github.com/saahphire/NeopetsUserscripts
// @version 1.0.0
// @description Transforms the "Make an Offer" and link copy buttons in the Trading Post into links so you can right-click them
// @author saahphire
// @homepageURL https://github.com/saahphire/NeopetsUserscripts
// @homepage https://github.com/saahphire/NeopetsUserscripts
// @downloadURL https://github.com/saahphire/NeopetsUserscripts/blob/main/tradingPostButtonsToLinks.js
// @updateURL https://github.com/saahphire/NeopetsUserscripts/blob/main/tradingPostButtonsToLinks.js
// @match *://*.neopets.com/island/tradingpost.phtml*
// @icon https://www.google.com/s2/favicons?sz=64&domain=neopets.com
// @license The Unlicense
// ==/UserScript==
/*
•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•:•:•:•:•:•:•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•.•:•:•:•:•:•:•:•:•.•:•:•.•:•.••:•.•:•.••:
........................................................................................................................
☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦
This script does the following:
- Changes the "Clear" button to something less clickable. You can reverse that by setting changeClearButton to false.
- Converts the following buttons into links:
- Copy link to lot
- Make an Offer
- View Offers
- Report
- Your Trades
- Browse Lots
- Offers You Have Made
- The "copy link" button still copies if you click it, instead of navigating to the link. Dragging and right-clicking
work as expected for a link.
- Does NOT convert "Instant Buy" into a link. That's impossible.
- Does NOT convert "Create a New Trade" into a link. Instead, hover over the Inventory buttons to see a new "Create
a New Trade" button that is a link. I'm not going to watch the page forever for changes.
- If you "View Details", the buttons in that pop-up are still buttons. It was extra work that I didn't know if anyone
would even want me to do.
✦ ⌇ saahphire
☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦
........................................................................................................................
•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•:•:•:•:•:•:•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•.•:•:•:•:•:•:•:•:•.•:•:•.•:•.••:•.•:•.••:
*/
const changeClearButton = true;
const links = {
lot: [
{
// Copy link
url: id => `https//www.neopets.com/island/tradingpost.phtml?type=browse&criteria=id&search_string=${id}`,
query: '.mt-auto img'
},
{
// Make an Offer
url: id => `${window.location.href.split('#/')[0]}#/?type=makeoffer&lot_id=${id}`,
query: '.button-classic-primary'
},
{
// Report
url: () => 'https://www.neopets.com/settings/privacy/report/',
query: '.icon-container + .flex + img'
},
{
// View Offers
url: id => `https://www.neopets.com/island/tradingpost.phtml#/?type=offers-lot&lot_id=${id}`,
query: '.flex:not(:has(.button-classic-primary)) .button-classic-default'
}
],
global: [
{
// Your Trades
url: 'https://www.neopets.com/island/tradingpost.phtml#/?type=view',
query: 'button.relative .item-label'
},
{
// Browse Lots (top left)
url: 'https://www.neopets.com/island/tradingpost.phtml#/?type=browse',
query: 'button.relative:nth-of-type(2) .item-label'
},
{
// Browse Lots (empty page)
url: 'https://www.neopets.com/island/tradingpost.phtml#/?type=browse',
query: '.text-museo + .relative .tp-border-frame-btn'
},
{
// Offers You Have Made
url: 'https://www.neopets.com/island/tradingpost.phtml#/?type=offer-made',
query: 'button.relative:last-of-type .item-label'
},
{
// Create a New Trade (top left)
url: 'https://www.neopets.com/island/tradingpost.phtml#/?type=view',
query: '.tp-border-frame-btn'
},
{
// Create a New Trade (empty page)
url: 'https://www.neopets.com/island/tradingpost.phtml#/?type=view',
query: '.text-cafeteria + .relative .tp-border-frame-btn'
}
]
}
const addLink = (url, button) => {
if(!button) return;
const link = document.createElement('a');
link.href = url;
link.onclick = e => e.preventDefault();
link.style.textDecoration = 'none';
button.parentElement.appendChild(link);
link.appendChild(button);
}
const init = observer => {
if(!document.querySelector('.tp-border-frame') && !document.querySelector('.tp-border-frame-btn')) return;
observer.disconnect();
document.querySelectorAll('.tp-border-frame').forEach(lot => {
const id = lot.querySelector('.text-cafeteria').textContent.match(/\d+/)[0];
links.lot.forEach(link => addLink(link.url(id), lot.querySelector(link.query), id));
});
links.global.forEach(link => addLink(link.url, document.querySelector(link.query)));
if(changeClearButton) document.querySelector('.button-classic-cancel').parentElement.insertAdjacentHTML('afterBegin', `<style>
.button-classic-cancel {
background: none;
box-shadow: none;
&::before {
content: '❌';
}
& p {
display: none;
}
}
</style>`);
}
(function() {
'use strict';
const observer = new MutationObserver(() => init(observer));
observer.observe(document.getElementsByClassName('tp-main-content')[0], {childList: true});
})();