Facebook
From M, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 230
  1. (function (self) {
  2.     'use strict';
  3.  
  4.     self.init = function () {
  5.         self.reset();
  6.         self.checkDifference();
  7.     };
  8.  
  9.     self.reset = function () {
  10.         sQuery('ins-percentage-value-cat-page').remove();
  11.     };
  12.  
  13.     self.checkDifference = function () {
  14.         sQuery('.b-itemList_container').each(function () {
  15.             if (!sQuery('.b-itemList_price.is-old', this).exists()) {
  16.                 return;
  17.             }
  18.             var previousPrice = parseFloat(sQuery('.b-itemList_price.is-old', this).text().replace(',', '.').replace(/[^0-9.]/g, ''));
  19.             var newPrice = parseFloat(sQuery('.b-itemList_prices>p:eq(1)', this).text().replace(',', '.').replace(/[^0-9.]/g, ''));
  20.  
  21.             /*if (previousPrice !== newPrice) {*/
  22.             if (previousPrice != 0) {
  23.                 var percentageDiff = self.calculatePercentage(previousPrice, newPrice);
  24.  
  25.                 sQuery(this).append(
  26.                     '<div class="ins-percentage-value-cat-page" style=" color: #fff; display: block; background-color: #f00d16; position: absolute; top: 12px; right: 4px; margin-left: 0px; height: 16px; width: 60px; font-size: 12px; font-family: Open Sans Condensed; font-weight: bold; float: right;"> -' + Math.floor((100 - percentageDiff).toFixed(2)) + '% <div>'
  27.                 );
  28.             }
  29.         })
  30.     };
  31.  
  32.     self.calculatePercentage = function (previousPrice, newPrice) {
  33.         return (newPrice * 100 / previousPrice).toFixed(2);
  34.     };
  35.  
  36.     self.init();
  37. }({}));

Replies to JS rss

Title Name Language When
Re: JS Bulky Meerkat javascript 4 Years ago.