// ==UserScript==
// @name Cetak Sekaligus Kertas A6
// @author Celleven Store
// @namespace https://www.tokopedia.com/celleven
// @version 0.0.12
// @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*
// @match https://www.bukalapak.com/payment/transactions/print_preview*
// @match http://vendor.akulaku.com/*
// @run-at document-idle
// @downloadURL none
// ==/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 = ``;
$('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', '17px');
});
$("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: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, ""));
}
});
$("div.page:has(div.job-shipping-label)").css("width", "550px");
$("div.container:has(div.right) > div.page:has(div.job-shipping-label)").css("width", "530px");
}
function cetakBukalapak()
{
var styleCSS = ``;
$('body').append(styleCSS);
}
let label = `
';
var kanan = false;
var x = 0;
$.each(data.data.list, function(i) {
list = data.data.list[i];
if (x == 0)
{
html += '
';
}
else if (x == 3 && kanan == false)
{
html += '
';
kanan = true;
x = 0;
}
else if (x == 3 && kanan == true)
{
html += '
';
kanan = false;
x = 0;
}
html += cetakAkulaku3(list);
x++;
if (x == 3)
{
html += '
';
}
});
html += '
';
$('button.btn.btn-success.btn-sm').first().after('
');
$('#cetakAkulaku').click(function()
{
var blank = window.open('about:blank#jangan_lupa_traktir', '_blank');
blank.document.write(html);
});
})
.fail(function() {
console.log( "error" );
})
.always(function() {
console.log( "complete" );
});
}
function cetakAkulaku3(list)
{
var text = '';
var logokurir = 'https://ecs7.tokopedia.net/img/kurir/logo_sicepat.png';
var logotoko = 'https://github.com/rendy1287/tokopedia-cetak-sekaligus/raw/master/gambar/logo_akulaku.png';
var nama_toko = list.vendorName;
var nama_penerima = list.customerName;
var alamat_penerima = list.street + ' ' + list.roomNumber + '
' + list.district + ', ' + list.city + ', ' + list.province + ' ' + list.postcode;
var telepon_penerima = list.customerPhone;
var ekspedisi = 'SiCepat REG';
var kode_ekspedisi = 'SiCepat';
ekspedisi = '
' + ekspedisi.substr(0, ekspedisi.indexOf(' ')) + '' + ekspedisi.substr(ekspedisi.indexOf(' ')+1);
ekspedisi = ekspedisi.replace('(', '').replace(')', '');
var ongkir = 'Rp ' + formatMoney(list.subTotal, 0, ',', '.');
var nama_pengirim = list.vendorName;
var telepon_pengirim = list.vPhone;
var alamat_pengirim = list.vDistrict + ', ' + list.vCity;
var invoice = list.invoiceNo;
var administrasi = '+ Rp 0';
var asuransi = '+ Rp 0';
var logo_asuransi = '';
var berat = timeConverter(list.orderTime);
var total_harga = 'Rp ' + list.subTotal;
var insurance_type = '';
var insurance_note = '';
var additional_fee = '';
var kode_booking = '';
if (kode_ekspedisi == 'SiCepat')
{
logokurir = 'https://ecs7.tokopedia.net/img/kurir/logo_sicepat.png';
}
text += label;
text = text.replace('{{logotoko}}', logotoko);
text = text.replace('{{kode_booking}}', kode_booking);
text = text.replace('{{logokurir}}', logokurir);
text = text.replace('{{ekspedisi}}', ekspedisi);
text = text.replace('{{invoice}}', invoice);
text = text.replace('{{administrasi}}', administrasi);
text = text.replace('{{asuransi}}', asuransi);
text = text.replace('{{ongkir}}', ongkir);
text = text.replace('{{berat}}', berat);
text = text.replace('{{nama_penerima}}', nama_penerima);
text = text.replace('{{telepon_penerima}}', telepon_penerima);
text = text.replace('{{alamat_penerima}}', alamat_penerima);
text = text.replace('{{nama_pengirim}}', nama_pengirim);
text = text.replace('{{telepon_pengirim}}', telepon_pengirim);
text = text.replace('{{alamat_pengirim}}', alamat_pengirim);
var print_item = '';
$.each(list.lineItemVOs, function(i)
{
var items = list.lineItemVOs[i];
var label_item = '';
var gambar_produk = items.img;
var nama_produk = items.itemName;
var jumlah_produk = items.qty + ' buah';
var keterangan_produk = items.property;
var total_harga_barang = 'Rp ' + items.price;
label_item = item;
label_item = label_item.replace('{{jumlah_produk}}', jumlah_produk);
label_item = label_item.replace('{{nama_produk}}', nama_produk);
label_item = label_item.replace('{{keterangan_produk}}', keterangan_produk);
print_item += label_item;
});
text = text.replace('{{foreach_item}}', print_item);
return text;
}
function formatMoney(amount, decimalCount = 2, decimal = ".", thousands = ",")
{
try {
decimalCount = Math.abs(decimalCount);
decimalCount = isNaN(decimalCount) ? 2 : decimalCount;
const negativeSign = amount < 0 ? "-" : "";
let i = parseInt(amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)).toString();
let j = (i.length > 3) ? i.length % 3 : 0;
return negativeSign + (j ? i.substr(0, j) + thousands : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands) + (decimalCount ? decimal + Math.abs(amount - i).toFixed(decimalCount).slice(2) : "");
} catch (e) {
console.log(e)
}
};
function timeConverter(UNIX_timestamp){
var a = new Date(UNIX_timestamp);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var year = a.getFullYear();
var month = months[a.getMonth()];
var date = a.getDate();
var hour = a.getHours();
var min = '0' + a.getMinutes();
var sec = '0' + a.getSeconds();
var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min.substr(-2) + ':' + sec.substr(-2) ;
return time;
}