This repository has been archived by the owner on May 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyprice-links.user.js
117 lines (103 loc) · 4.49 KB
/
keyprice-links.user.js
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
// ==UserScript==
// @name keyprice links
// @namespace http://manic.tf
// @version 4.0
// @description add http://manic.tf/keyprice links to marketplace.tf/mannco.store item pages
// @author manic
// @grant none
// @license MIT
// @homepageURL https://github.com/mninc/keyprice-links
// @supportURL https://github.com/mninc/keyprice-links/issues
// @downloadURL https://github.com/mninc/keyprice-links/raw/master/keyprice-links.user.js
// @run-at document-end
// @match https://marketplace.tf/items/*
// @match https://mannco.store/item/*
// ==/UserScript==
(function() {
'use strict';
if (window.location.hostname.includes("marketplace.tf")) {
let elements = document.getElementsByClassName('panel-body');
let panel;
for (let i = 0; i < elements.length; i++) {
let elem = elements[i];
let scriptFound = elem.getElementsByTagName("script").length;
let canvasFound = elem.getElementsByTagName("canvas").length;
if (canvasFound && scriptFound) {
panel = elem;
break;
}
}
if (!panel) return;
let script = panel.getElementsByTagName("script")[0];
let canvas = panel.getElementsByTagName('canvas')[0];
let canvasID = canvas.id;
let newCanvasID = canvasID + "-manic";
let canvasSku = canvas.dataset.sku;
let iframe = panel.getElementsByTagName("iframe")[0];
let scriptText = script.innerText;
scriptText = scriptText.substring(0, scriptText.indexOf('});'));
scriptText = scriptText.replace(new RegExp(canvasID, "g"), newCanvasID);
scriptText += `
let time, price;
myLineChart.options.tooltips.custom = function(tooltip){
if (!tooltip.title) return;
let date = tooltip.title[0];
time = new Date(date);
let year = time.getFullYear().toString();
let month = time.getMonth() + 1;
month = (month>9 ? '' : '0') + month;
month = month.toString();
let day = time.getDate();
day = (day>9 ? '' : '0') + day;
day = day.toString();
time = year + "-" + month + "-" + day;
price = tooltip.body[0].lines[0].substring(14);
};
let old_function = myLineChart.options.onClick;
myLineChart.options.onClick = function(data, elements) {
old_function(data, elements);
if (document.getElementById("keyprice-link")) {
document.getElementById("keyprice-link").href = "http://manic.tf/keyprice?site=marketplace.tf&at=" + time + "&price=" + price;
} else {
let a = document.createElement("a");
a.href = "http://manic.tf/keyprice?at=" + time + "&price=" + price;
a.innerText = "Convert to keys";
a.id = "keyprice-link";
a.target = "_blank";
let titles = document.getElementsByClassName("modal-title");
for (let i = 0; i < titles.length; i++) {
let title = titles[i];
if (title.innerText === "Detailed Stats") {
title.innerText += " - ";
title.appendChild(a);
}
}
}
};
myLineChart.update();`;
scriptText += '});';
let newCanvas = document.createElement('canvas');
newCanvas.id = newCanvasID;
newCanvas.dataset.sku = canvasSku;
newCanvas.width = canvas.width;
newCanvas.height = canvas.height;
let newScript = document.createElement("script");
newScript.innerHTML = scriptText;
canvas.remove();
iframe.remove();
script.remove();
panel.appendChild(newCanvas);
panel.appendChild(newScript);
} else {
let time, price;
window.myLine.options.tooltips.custom = function(tooltip) {
if (!tooltip.title) return;
time = tooltip.title[0];
price = tooltip.body[0].lines[0].substring(14);
}
window.myLine.options.onClick = function() {
console.log(time, price);
window.open(`https://manic.tf/keyprice?site=mannco.store&at=${time}&price=${price}`)
}
}
})();