RuneScape talk:Drop Log Project

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to: navigation, search
This talk page is for discussing the RuneScape:Drop Log Project page.

I was bored and made browser extension using this code and added UI I will leave code hare if you want to upload to browser stores
Not going to upload my self because I am not going to update if needed if you have question's DM me Icemourne#8622
Its ready to use as it is and can be installed manually by extracting zip contents going to extensions setting in browser selecting developer mode > load unpacked select folder with extracted files for Chrome / Chromium browsers or manifest file for FireFox
Zip file can also be uploaded to any browser store to make installation for users simple
Link to download extension https://ufile.io/nq3h86us
78.60.241.69 17:41, 18 August 2021 (UTC) Icemourne

Code[edit source]

If you don't understand what this code dose just ignore it[edit source]

File name has to be "stuff.js" can be changed in manifest.json

// Extra stuff
(() => { // looking for avatar and running code then its loaded
    let observer = new MutationObserver((zzz, quit) => {
        let avatar = document.querySelector("#a-header-avatar")
        if (avatar){
            setTimeout(() => newCode(), 200)
            quit.disconnect()
        }
    })
    observer.observe(document, {
        childList: true,
        subtree: true
    })
}) ()

function newCode() {
    let textPlace
    if (localStorage.getItem('wiki_setting') != 'disable') {
        let mainPage = document.querySelector('body') // place we going to put our container
        let container = document.createElement('div') // create container
        textPlace = document.createElement('div')
        let setting = document.createElement('div')

        container.className = 'main-container'
        textPlace.className = 'progress-text'
        setting.className = 'setting-thing'

        textPlace.textContent = 'Loading...'

        textPlace.addEventListener('click', e => {
            if (e.currentTarget.textContent == 'All done!\nClick me to close') {
                e.currentTarget.parentNode.remove()
            } // then its done clicking on it will remove it
        })

        setting.textContent = `Click hare if you don't want to see this window anymore\nThis will disable message window but script still run in background`
        setting.addEventListener('click', e => {
            let target = e.currentTarget
            let text = `Click me if you really want to disable to re-enable you will have to clear browser cache`
            let text2 = 'This menu now disabled and will no longer appear'
            if(target.textContent == text2) return
            if (target.textContent == text) {
                localStorage.setItem('wiki_setting', 'disable')
                target.textContent = text2
            } else {
                target.textContent = text
            }
        })
        container.append(textPlace, setting)
        mainPage.append(container)
    }
    originalCode(textPlace) // run old code
}

// changes bellow replaced console log with element.textContent = stuff what was originally logged
// changed var avatar = $("#a-header-avatar").attr("alt");
// to var avatar = document.querySelector("#a-header-avatar").getAttribute('alt');

function originalCode(textPlace) {
    var avatar = document.querySelector("#a-header-avatar").getAttribute('alt'); // small changes no jQuery allowed hare
    // 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 40, then
    // asynchronously grab the data from RuneMetrics.
    async function grab(missing) {
        var BATCH_SIZE = 40;
        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));
            }
            element.textContent = "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(() => {
        if(textPlace) textPlace.textContent = "All done!\nClick me to close"
        console.log('All done!')
    })
}

File name has to be "styling.css" can be changed in manifest.json

.main-container{
    position: absolute;
    left: 50%;
    top: 20%;
    transform: translate(-50%, -50%);
    width: 400px;
    background: #071f2a;
    border: 3px solid #e1bb34;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
.progress-text{
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 10px;
    padding-bottom: 10px;
}
.setting-thing{
    padding: 10px;
    border-top: 3px solid #e1bb34;
    white-space: break-spaces;
    text-align: center;
}

File name has to be "manifest.json" can't be changed

{
    "manifest_version": 2,
    "name": "RS_Wiki_uploader",
    "version": "1.0.0",
    "author": "Icemourne",
    "description": "Simple extension making uploading data to wiki easer",
    "homepage_url": "https://runescape.wiki/",
    "icons": { "128": "Wiki.png" },
    "content_scripts": [
        {
            "matches": ["https://apps.runescape.com/runemetrics/app/*"],
            "js": [
                "stuff.js"
            ],
            "css": [
                "styling.css"
            ]
        }
    ],
    "permissions": [
        "https://chisel.weirdgloop.org/*",
        "https://apps.runescape.com/*",
        "webRequest"
    ]
}

Place everything in one folder and also add this image https://runescape.wiki/images/b/bc/Wiki.png?e374a has to be named "Wiki.png" can be changed in "manifest.json"