RuneScape:Drop Log Project

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search

Note that you need RuneMetrics Pro for this script to work.

  1. Go to https://apps.runescape.com/runemetrics/app/my-profile and log in.
  2. Open your browser's developer console and paste the code below, and press enter.
  3. This may take 5-10 minutes to send all the data. If you get an error before it completes, you can just paste the code again - it will skip the ones already sent.

Code

var avatar = $("#a-header-avatar").attr("alt");
// Grab username so we can only re-send new data if the script is re-run
var username = avatar.substr(0, avatar.length - 7);

// Converts the list of RuneMetrics kills to a list of (date, monster pairs)
// that we haven't seen from this user.
function getMissing(data) {
    return fetch('https://chisel.weirdgloop.org/droplogs/get_urls', {
        method: 'POST',
        body: JSON.stringify({"username": username, "data": data.monsterKills})
    }).then(response => response.json())
}

// Just sends the data to the wiki. weirdgloop.org is owned by the wiki.
function sendToWiki(responses, refs, username) {
	var payload = {"responses": responses, "refs": refs, "username": username, "version": 2};
	fetch('https://chisel.weirdgloop.org/droplogs/submit', {
	    method: 'POST',
	    body: JSON.stringify(payload)
	})
}

// Chunk the missing (date, monster) pairs into groups of 20, then
// asynchronously grab the data from RuneMetrics.
async function grab(missing) {
    var BATCH_SIZE = 20;
    for (var i = 0; i < missing.length; i += BATCH_SIZE) {
        var chunk = missing.slice(i, i + BATCH_SIZE);
        var promises = [];
        for (var miss of chunk) {
            promises.push(getContent(miss));
        }
        console.log("Sending monsters " + (i+1) + " to " + (i+chunk.length) + " out of " + missing.length);
        var responses = await Promise.all(promises);
        sendToWiki(responses, chunk, username);
    }
}

// Turn the (date, monster) pair into a url, and then return its JSON content.
function getContent(miss) {
    var unix = Date.parse(miss[1]);
    var url = "https://apps.runescape.com/runemetrics/aggregations/npc/drop-log/range/day?&start=" + unix + "&end=" + (unix + 86400000 - 1) + "&id=" + miss[0]
    return fetch(url)
    .then(response => response.json())
}

// Grab all kill counts over all time.
fetch("https://apps.runescape.com/runemetrics/aggregations/npc/kill/range/day?&start=1328121600000&end=1828726399999")
.then(response => response.json())
.then(getMissing)
.then(grab)
.then(() => console.log("All done!"))