AWS Hourly to Monthly price converter

github link to come

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AWS Hourly to Monthly price converter
// @namespace    http://github.com/
// @version      0.1
// @description  github link to come
// @author       Scellow
// @match        http://aws.amazon.com/ec2/pricing/
// @grant        none
// ==/UserScript==

DEBUG = false;

HOURS_IN_ONE_MONTH = 720;
DECIMAL_TO_DISPLAY = 2;

PRICE_NON_AVAILABLE = "N/A*";
CURRENCY = "$";
PRODUCTS = ["linux","rhel","sles","mswin","mswinSQL","mswinSQLWeb","mswinSQLEnterprise"];


window.onload = function ()
{
    debugLog("INFO: Document loaded!");

    var rates = [];

    //get rates
    for(var i = 0; i < PRODUCTS.length; i++)
    {
        var product = PRODUCTS[i];
        var rate = document.getElementsByClassName(product);
        debugLog("INFO: "+product+" has "+ rate.length + " elements");
        for(var j = 0; j < rate.length; j++)
        {
            var element = rate[j];
            rates.push(element);
        }
    }

    debugLog('INFO: Found:'+ rates.length + ' price');

    for(var i = 0; i < rates.length; i++)
    {
        var element = rates[i];
        var content = rates[i].innerHTML;
        if(content != PRICE_NON_AVAILABLE)
        {
            var pph = content;
            pph = pph.replace(CURRENCY, "");
            pph = pph.replace(" per Hour", "");

            var ppm = (pph * HOURS_IN_ONE_MONTH).toFixed(DECIMAL_TO_DISPLAY);

            rates[i].innerHTML = content + '</br>$' + ppm + ' per Month';
        }
    }
}

$(document).ready(function() {
    debugLog("INFO: Debug mode enabled!");
    debugLog("INFO: Document Ready!");
});

function debugLog(message)
{
    if(!DEBUG) return;

    console.log(message);
}