GOG Orders history prices summary

Sum paid and original prices on orders history pages and get your total saved money on sales. Add new button (SUM ORDERS on this page) on Orders history page in settings.

目前為 2018-06-16 提交的版本,檢視 最新版本

// ==UserScript==
// @name           GOG Orders history prices summary
// @namespace      XcomeX
// @description    Sum paid and original prices on orders history pages and get your total saved money on sales. Add new button (SUM ORDERS on this page) on Orders history page in settings.
// @version        1.1
// @author         XcomeX
// @include        https://www.gog.com/account/settings/orders
// @grant          GM_addStyle
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
// ==/UserScript==


var targBtnLocation = document.getElementsByClassName("_search orders-header__search")[0].parentNode;

var zNode       = document.createElement ('div');
zNode.innerHTML = '<button id="sumButton" type="button">SUM ORDERS on this page</button>';
zNode.setAttribute ('id', 'sumContainer');
targBtnLocation.appendChild (zNode);

var xNode       = document.createElement ('div');
xNode.setAttribute ('id', 'sumResultsContainer');
targBtnLocation.appendChild (xNode);

var yNode       = document.createElement ('div');
yNode.setAttribute ('id', 'totalSumContainer');
targBtnLocation.appendChild (yNode);


document.getElementById ("sumButton").addEventListener (
    "click", SumButtonClickAction, false
);

$( ".pagin" ).click(function() {
  window.scrollTo(0, 0);
});

GM_addStyle ( "                                    \
    #sumContainer  {                               \
        float:               right;                \
    }                                              \
    .sumRow  {                                     \
        font-weight:         100;                  \
    }                                              \
    .priceSum  {                                   \
        width:               51px;                 \
        display:             inline-block;         \
    }                                              \
    #sumButton {                                   \
        color:               #262626;              \
        font-weight:         600;                  \
        font-size:           14px                  \
        line-height:         1.5;                  \
        position:            relative;             \
        top:                 10px;                 \
        background:          #E0E0E0;              \
        border:              none;                 \
    }                                              \
    .deleteSumRowButton {                          \
        color:               gray;                 \
        font-size:           11px;                 \
        line-height:         1.5;                  \
        background:          none;                 \
        border:              none;                 \
        bottom:              2px;                  \
        position:            relative;             \
    }                                              \
    #sumButton:hover                           {   \
        background:          #EBEBEB;              \
    }                                              \
    .deleteSumRowButton:hover                  {   \
       text-decoration: underline;                 \
    }                                              \
    #sumResultsContainer, #totalSumContainer {     \
        text-align:          right;                \
    }                                              \
" );

function SumButtonClickAction (zEvent) {              
    $("#sumResultsContainer").append(SumRow());       
    
    $(".deleteSumRowButton").each(function( index ) {
        $(this).click(function() {
              $(this).closest('div').remove();
              $("#totalSumContainer").html(TotalSumRow());
            });
       });
    
    $("#totalSumContainer").html(TotalSumRow());
}


// ---------------------------------------------------------------------------------

function SumRow() {
    purchasePrice = SumPurchasePrices().toFixed(2);
    originalPrice = SumOriginalPrices().toFixed(2);
    saved = (originalPrice - purchasePrice).toFixed(2);
    currency = getCurrencySymbol();
    page = getCurrencyPage();
    totalPages = getTotalPages();
    
    sumRow = 
        "<div id='sumRow" + page + "' class='sumRow'>" 
          + "ORDERS HISTORY PAGE " + page + " of " + totalPages + " | "
          + " Paid: " + currency + "<span class='priceSum sumPurchasePrice'>" + purchasePrice + "</span>"
          + " | Original price: " + currency + "<span class='priceSum sumOriginalPrice'>" + originalPrice + "</span>"
          + " | Saved: " + currency + "<span class='priceSum sumSaved'>" + saved + "</span>"
          + '<button class="deleteSumRowButton" type="button">remove</button>' 
        + "</div>"
    return sumRow;
}

function TotalSumRow () {
    var purchasePricesSum = 0.00;   
    $(".sumPurchasePrice").each(function( index ) {
       var price = $(this).text();    
        purchasePricesSum = purchasePricesSum + parseFloat(price || 0.0);
    });    

    var originalPricesSum = 0.00;   
    $(".sumOriginalPrice").each(function( index ) {
       var price = $(this).text();    
        originalPricesSum = originalPricesSum + parseFloat(price || 0.0);
    });    
    
    var savedSum = 0.00;   
    $(".sumSaved").each(function( index ) {
       var price = $(this).text();    
        savedSum = savedSum + parseFloat(price || 0.0);
    });        
    
    currency = getCurrencySymbol();
    totalSumRow = 
        "<div id='totalSumRow'>" 
          + "TOTAL"
          + " | Paid: " + currency + purchasePricesSum.toFixed(2)
          + " | Original price: " + currency + originalPricesSum.toFixed(2)
          + " | Saved: " + currency + savedSum.toFixed(2)
        + "</div>";
    return totalSumRow;
}

function SumPurchasePrices () {
    var sum = 0.00;
    $("[ng-bind='product.price.amount']").each(function( index ) {
       var price = 
          $(this)
           .clone()    //clone the element
           .children() //select all the children
           .remove()   //remove all the children
           .end()  //again go back to selected element
           .text();    
        sum = sum + parseFloat(price || 0.0);
    });    

    return sum;
}

function SumOriginalPrices () {
    var sum = 0.00;   
    $("[ng-bind='product.price.baseAmount']").each(function( index ) {
       var price = $(this).text();    
        sum = sum + parseFloat(price || 0.0);
    });    
    
    return sum;
}

function getCurrencySymbol() {
    var symbol = $(".store-credit-info__total span:first").text();
    return symbol;
}

function getCurrencyPage() {
    var currentPage = $(".pagin__input:first").val();    
    return currentPage;
}

function getTotalPages() {
    var totalPages = $(".pagin__total:first").text();    
    return totalPages;
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址