· 6 years ago · Apr 27, 2020, 05:14 PM
1// Note Note in the line
2// request.open('GET',
3// 'https://api.torn.com/torn/?selections=stocks&key=YOURAPIHERE',
4// true);
5// request.onload = function() {
6// var data = JSON.parse(this.response);
7// Object.keys(data.stocks).forEach(stockId => doSomething(
8// stockId, data.stocks[stockId], outArray));
9// if(outArray.length >= 1) {
10// window.alert(outArray.join("\n"));
11// }
12// };
13// request.send();
14// you need to add your api key manulally to install it
15// ==UserScript==
16// @name New Userscript
17// @namespace http://tampermonkey.net/
18// @version 0.1
19// @description try to takeover the world!!!
20// @author Joann_Pierce
21// @match https://www.torn.com/index.php
22// @match https://www.torn.com/stockexchange.php
23// @grant none
24// ==/UserScript==
25
26
27function doSomething(stockId, stock, outArray) {
28 console.log(stockId + ": " + stock.acronym);
29 console.log(" total_shares: " + stock.total_shares);
30 console.log(" available_shares: " + stock.available_shares);
31 var pct = 100 * stock.available_shares / stock.total_shares ;
32 if( pct >= 5 && (stock.forecast == "High" || stock.forecast == "Average") ) {
33 outArray.push(pct + "% of " + stock.acronym + " is available.\n The demand is " + stock.demand + " and the forecast is " + stock.forecast +
34 ".\n The price for a benefit block is currently " + (stock.benefit.requirement * stock.current_price).toLocaleString() + ". \n ");
35 }
36}
37
38function runChecks() {
39 var outArray = [];
40 var request = new XMLHttpRequest();
41
42 request.open('GET', 'https://api.torn.com/torn/?selections=stocks&key=YOURAPIHERE', true);
43 request.onload = function() {
44 var data = JSON.parse(this.response);
45 Object.keys(data.stocks).forEach(stockId => doSomething(
46 stockId, data.stocks[stockId], outArray));
47 if(outArray.length >= 1) {
48 window.alert(outArray.join("\n"));
49 }
50 };
51 request.send();
52}
53
54(function() {
55 'use strict';
56 runChecks();
57 setInterval(runChecks, 5 * 60 * 1000);
58})();