Cetak Sekaligus Kertas A6

Untuk mencetak sekaligus buat kertas ukuran A6 untuk Tokopedia, Bukalapak, Shopee, dan Akulaku

Versão de: 22/01/2019. Veja: a última versão.

// ==UserScript==
// @name         Cetak Sekaligus Kertas A6
// @author       Celleven Store
// @namespace    https://www.tokopedia.com/celleven
// @version      0.0.7
// @description  Untuk mencetak sekaligus buat kertas ukuran A6 untuk Tokopedia, Bukalapak, Shopee, dan Akulaku
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @match        https://www.tokopedia.com/logistic/print-address*
// @match        https://www.tokopedia.com/print-address.pl*
// @match        https://seller.shopee.co.id/api/v2/orders/waybill*
// @run-at       document-idle
// ==/UserScript==

(function() {
  'use strict';

  var backgroundImage = '';
  var logo = '';

  if (window.location.href.indexOf("tokopedia") > -1)
  {
    cetakTokopedia();
  }
  else if (window.location.href.indexOf("shopee") > -1)
  {
    cetakShopee();
  }
  else if (window.location.href.indexOf("bukalapak") > -1)
  {
    cetakBukalapak();
  }
  else if (window.location.href.indexOf("akulaku") > -1)
  {
    cetakAkulaku();
  }

})();

function cetakTokopedia()
{
  var styleCSS = `<style>
  @page
  {
    size: 105mm 148mm portrait;
    margin: 3mm 2mm 2mm 3mm;
  }
  @media print
  {
    div.address_contaier_left, div.address_contaier_right, div.address
    {
      float: none !important;
      padding-left: 0px;
    }
    div.address
    {
      page-break-after: always;
    }
    body
    {
      zoom: 117%;
    }
    h5
    {
      display: none;
    }
  }
  </style>`;

  $('body').append(styleCSS);
  $('div.address > table > tbody > tr > td').each(function(x, r)
  {
    $(r).find('table:contains("Kepada") > tbody > tr > td > div').css('font-size', '15px');
  });

  $("table div:contains('bayar asuransi')").remove();
  $("div.page-break").remove();
  $("td div:contains('Asuransi')").next().html('+ Rp 0').css('text-decoration', 'none');
  $("td div:contains('Ongkir')").next().css('text-decoration', 'none');
  $("div.address_contaier_right").each(function()
  {
    if ($(this).children().length == 0)
    {
      $(this).remove();
    }
  });
  $("div.address").filter(function()
  {
    return $(this).text().trim() == "";
  }).remove();
  $("div.address_contaier_right").filter(function()
  {
    return $(this).text().trim() == "";
  }).remove();
}

function cetakShopee()
{
  var styleCSS = `<style>
  @page
  {
    margin: 4mm 1mm 2mm 4mm;
  }
  @media print
  {
    .page
    {
      float: none !important;
      page-break-after: always;
      border-right: none !important;
      width: 48%;
    }
    .left
    {
      margin-left: -1px;
    }
    .page.left
    {
      padding: 0 0.55in 0 0;
      border-right: none;
    }
    .page.right
    {
      padding: 0 0.55in 0 0;
      border-left: none;
    }
  }
  </style>`;

  $('style:last').html($('style:last').html().replace('A4 landscape', 'auto'));
  $('style:first').html($('style:first').html().replace('A4 landscape', 'auto'));
  $('head').append(styleCSS);
  $('div.page-breaker').remove();
  $('div:last').remove();
  $('img.scissors-vertical').remove();
  $(".page.right").each(function()
  {
    if ($("div.job-shipping-label", this).length > 0)
    {
      $("style:last").html($('style:last').html().replace(/(padding: 0 0.55in 0 0;)/g, ""));
    }
  });
}

function cetakBukalapak()
{
}

function cetakAkulaku()
{
}