TornAPI Quick Fill

Prefill API key and check 'pretty' radio buttons. Makes available fields clickable and fires try it button when clicked.

目前為 2016-11-21 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         TornAPI Quick Fill
// @namespace    TornTos
// @version      1.0
// @description  Prefill API key and check 'pretty' radio buttons.  Makes available fields clickable and fires try it button when clicked.
// @author       tos
// @match        *.api.torn.com/*
// @grant        none
// ==/UserScript==

APIkey = 'APIkey'; //API KEY HERE (leave quotes it's a string)

apiQuickFill();

function apiQuickFill() {
    const observer = new MutationObserver((mutations) => {
        for (const mutation of mutations) {
            for (const node of mutation.addedNodes) {
                if(node.tagName === 'SMALL'){
                    var fieldsNode = node.parentNode;
                    fieldsNode.append($('<strong>', {text: 'Available Fields: '})[0]);
                    var selectionList = node.innerText.split(': ')[1].split(', ');
                    for(i=0; i < selectionList.length - 1; i++){
                        var newLink = $('<span>', {style:"cursor: pointer;", text: selectionList[i]})[0];
                        fieldsNode.append(newLink);
                        newLink.addEventListener('click', apiLinkClicked);
                        fieldsNode.append($('<span>', {text: ', '})[0]);
                    }
                    var lastLink = $('<span>', {style:"cursor: pointer;", text: selectionList[i]})[0];
                    fieldsNode.append(lastLink);
                    lastLink.addEventListener('click', apiLinkClicked);
                    node.remove();
                }
            }
        }
    });
    const wrapper = document.querySelector('#demo');
    observer.observe(wrapper, { subtree: true, childList: true });

    $('.demoLink').click();
    $('#api_key').val(APIkey).focusout();
    $("input:radio[value='pretty']").attr('checked', true);
    $.ajax({
        type: "GET",
        url: 'https://api.torn.com/user/?selections=&key='+APIkey,
        success: function (response) {
            if(response.property_id){$('#p_id').val(response.property_id);}
            if(response.faction){$('#f_id').val(response.faction.faction_id);}
            if(response.job){$('#c_id').val(response.job.company_id);}
        }
    });
}
function apiLinkClicked(){
    $('#'+ this.parentNode.className.charAt(0) +'_selections')[0].value = this.innerHTML;
    $('#'+ this.parentNode.className.charAt(0) +'_').click();
}