Major ALGs on Skill Page

Displays data from an Excel sheet on a webpage

当前为 2023-07-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         Major ALGs on Skill Page
// @namespace    your-namespace
// @version      1.0
// @description  Displays data from an Excel sheet on a webpage
// @match        https://glb.warriorgeneral.com/game/skill_points.pl?player_id=**
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Define the CSV data
    var csvData = `LEVEL,3 majors,4 majors,5 majors
10,26.17,19.6,15.78
11,25.5,19.1,15.38
12,24.83,18.6,14.98
13,24.16,18.1,14.58
14,23.49,17.6,14.18
15,22.82,17.1,13.78
16,22.15,16.6,13.38
17,21.48,16.1,12.98
18,20.81,15.6,12.58
19,20.14,15.1,12.18
20,19.47,14.6,11.78
21,18.8,14.1,11.38
22,18.3,13.72,11.08
23,17.8,13.34,10.78
24,17.3,12.96,10.48
25,16.8,12.58,10.18
26,16.3,12.2,9.88
27,15.8,11.82,9.58
28,15.3,11.44,9.28
29,14.8,11.06,8.98
30,14.42,10.78,8.75
31,14.04,10.5,8.52
32,13.66,10.22,8.29
33,13.28,9.94,8.06
34,12.9,9.66,7.83
35,12.52,9.38,7.6
36,12.14,9.1,7.37
37,11.76,8.82,7.14
38,11.48,8.61,6.97
39,11.2,8.4,6.8
40,10.92,8.19,6.63
41,10.64,7.98,6.46
42,10.36,7.77,6.29
43,10.08,7.56,6.12
44,9.8,7.35,5.95
45,9.52,7.14,5.78
46,9.24,6.93,5.61
47,8.96,6.72,5.44
48,8.68,6.51,5.27
49,8.4,6.3,5.1
50,8.12,6.09,4.93
51,7.84,5.88,4.76
52,7.56,5.67,4.59
53,7.28,5.46,4.42
54,7,5.25,4.25
55,6.72,5.04,4.08
56,6.44,4.83,3.91
57,6.16,4.62,3.74
58,5.88,4.41,3.57
59,5.6,4.2,3.4
60,5.32,3.99,3.23
61,5.04,3.78,3.06
62,4.76,3.57,2.89
63,4.48,3.36,2.72
64,4.2,3.15,2.55
65,3.92,2.94,2.38
66,3.64,2.73,2.21
67,3.36,2.52,2.04
68,3.08,2.31,1.87
69,2.8,2.1,1.7
70,2.52,1.89,1.53
71,2.24,1.68,1.36
72,1.96,1.47,1.19
73,1.68,1.26,1.02
74,1.4,1.05,0.85
75,1.12,0.84,0.68
76,0.84,0.63,0.51
77,0.56,0.42,0.34
78,0.28,0.21,0.17
79,0,0,0`;

    // Parse the CSV data
    function parseCSV() {
        var rows = csvData.trim().split('\n');
        var headers = rows[0].split(',').map(function (header) {
            return header.trim();
        });

        var data = [];
        for (var i = 1; i < rows.length; i++) {
            var values = rows[i].split(',').map(function (value) {
                return value.trim();
            });

            var entry = {};
            for (var j = 0; j < headers.length; j++) {
                entry[headers[j]] = values[j];
            }

            data.push(entry);
        }

        return data;
    }

    // Create the box container element
    var boxContainer = document.createElement('div');
    boxContainer.classList.add('box');

    // Create the input elements
    var input1 = document.createElement('input');
    input1.type = 'text';
    input1.placeholder = 'Current Level';

    var input2 = document.createElement('input');
    input2.type = 'text';
    input2.placeholder = 'Number of Majors';

    var input3 = document.createElement('input');
    input3.type = 'text';
    input3.placeholder = 'Current Attribute Level';

    // Create the output element
    var output = document.createElement('div');

    // Create the button element
    var button = document.createElement('button');
    button.textContent = 'Calculate';

    // Append the input elements, button, and output element to the box container
    boxContainer.appendChild(input1);
    boxContainer.appendChild(input2);
    boxContainer.appendChild(input3);
    boxContainer.appendChild(button);
    boxContainer.appendChild(output);

    // Find the target element to insert the box (assuming the target element has the id "content")
    var targetElement = document.getElementById('content');
    targetElement.appendChild(boxContainer);

    // Calculate the resulting attribute level
function calculateResult() {
    var currentLevel = parseInt(input1.value);
    var numberOfMajors = parseInt(input2.value);
    var currentAttributeLevel = parseFloat(input3.value);

    var extractedData = parseCSV();

    if (currentLevel < 10 || currentLevel > 79) {
        output.textContent = 'Invalid current level. Please enter a level between 10 and 79.';
        return;
    }

    if (numberOfMajors < 3 || numberOfMajors > 5) {
        output.textContent = 'Invalid number of majors. Please enter a number between 3 and 5.';
        return;
    }

    if (currentAttributeLevel < 0 || currentAttributeLevel > 99.99) {
        output.textContent = 'Invalid current attribute level. Please enter a level between 0 and 99.99.';
        return;
    }

    var dataIndex = currentLevel - 10;
    var targetAttributeLevel = extractedData[dataIndex][numberOfMajors + ' majors'];

    if (targetAttributeLevel === undefined) {
        output.textContent = 'Invalid combination of current level and number of majors.';
        return;
    }

    var requiredAttributePoints = targetAttributeLevel - currentAttributeLevel + currentAttributeLevel;
    var result = currentAttributeLevel + requiredAttributePoints;
    output.textContent = 'Result: ' + result.toFixed(2);
}


    // Add an event listener to the button
    button.addEventListener('click', calculateResult);
})();