forked from diceroll123/shapeshiftersolver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserscript.js
More file actions
67 lines (60 loc) · 2.46 KB
/
Copy pathuserscript.js
File metadata and controls
67 lines (60 loc) · 2.46 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
// ==UserScript==
// @name Neopets - Shapeshifter Script Maker
// @match https://www.neopets.com/medieval/shapeshifter.phtml*
// @version 1.1
// @description Script to generate Neopets Shapeshifter scripts
// @namespace https://github.com/DannyPhantom14/shapeshiftersolver2024
// ==/UserScript==
/* globals jQuery, $, waitForKeyElements */
(function() {
function getDeltas() {
var pieces = {};
var items = $("table[border=1][bordercolor='gray']").find("img[name='i_']:not(:last)").get();
items.splice(0, 0, items.pop()); // Move the last item to the front
$(items).each(function(index, element) {
pieces[$(element).attr("src").slice(0, 52)] = index; // Use slice for safety
});
return pieces;
}
var deltas = getDeltas();
function tableScripter(table) {
var lines = [];
table.find("tr").each(function(index, row) {
var line = '';
$(row).find("td").each(function(colIndex, cell) {
line += $(cell).find("img").length;
});
lines.push(line);
});
return "'" + lines.join() + "'";
}
function getShapes() {
var shapes = [];
$($("big")[1]).parent().parent().find("table[cellpadding='0']").each(function(index, shapeTable) {
shapes.push(tableScripter($(shapeTable)));
});
return shapes.length ? "pieces = [" + shapes.join(", ") + "]" : ""; // Handle no shapes
}
function getBoard() {
var lines = [];
$("table[align=center][cellpadding=0][cellspacing=0][border=0]").find("tr").each(function(index, row) {
var line = '';
$(row).find("img").each(function(imgIndex, img) {
line += deltas[$(img).attr("src").slice(0, 52)] || '0'; // Return 0 if delta doesn't exist
});
lines.push(line);
});
return "board = Board('" + lines.join() + "', " + (Object.keys(deltas).length - 1) + ")";
}
// Click event to copy code to clipboard
$(document).on("click", "#copy", function() {
var $temp = $("<textarea>");
$("body").append($temp);
$temp.val(getBoard() + "\n" + getShapes()).select();
document.execCommand("copy");
$temp.remove();
$("#copy").fadeOut();
});
// Add copy button after the target table
$("table[border=1][bordercolor='gray']").after("<p><center><button id='copy'>Copy Board Code</button></center>");
})();