|
// ==UserScript== |
|
// @name Snappfood manipulator |
|
// @namespace http://tampermonkey.net/ |
|
// @version 0.1 |
|
// @description try to take over the world! |
|
// @author Ali Torki |
|
// @match https://snappfood.ir/landing/followorder/*?mode=view |
|
// @grant none |
|
// @require https://unpkg.com/[email protected]/persian |
|
// ==/UserScript== |
|
|
|
(function() { |
|
'use strict'; |
|
|
|
// Create and append our wrapper to the body includes price, provider inputs. |
|
const wrapper = id => $("<div class='modifier' id='modifier_price_"+ id +"' style='margin-top: 15px;user-select: none;'><div class='plus' style='font-size:25px;color: #75ae31;with: 20px;height: 20px;display: inline;cursor: pointer;'>+</div><div class='minus' style='font-size:25px;color: #EB5E4D;with: 20px;height: 20px;display: inline;cursor: pointer;margin-right: 15px'>-</div>"); |
|
|
|
const getTotalPrice = action => { |
|
const totalRow = $(".food_row_out").first().find("td").last(); |
|
const totalPriceValue = strToNumber(totalRow.text()) |
|
///// Total price with tax |
|
const total = $(".idn-final-payment").find("td").last().find("span"); |
|
const totalNumber = strToNumber(total.text()); |
|
|
|
|
|
switch(action) { |
|
case "plus": |
|
$(totalRow).html(toEnglishNumber(totalPriceValue + 1000)); |
|
$(total).html(toEnglishNumber(totalNumber + 1000)); |
|
break; |
|
case "minus": |
|
$(totalRow).html(toEnglishNumber(totalPriceValue - 1000)); |
|
$(total).html(toEnglishNumber(totalNumber - 1000)); |
|
break; |
|
default: |
|
console.log("Called action is unknown"); |
|
} |
|
} |
|
const strToNumber = num => { |
|
const value = num.replace(/[،,]/g, ""); |
|
const normalizedNumber = parseInt(persianJs(value).persianNumber().toString(), 10); |
|
|
|
return normalizedNumber; |
|
} |
|
const toEnglishNumber = num => persianJs(num).englishNumber().toString().replace(/([\d۰۱۲۳۴۵۶۷۸۹])(?=([\d۰۱۲۳۴۵۶۷۸۹]{3})+(?![\d۰۱۲۳۴۵۶۷۸۹]))/g, "$1,") |
|
|
|
// update prices |
|
const showUpdatePrice = () => { |
|
const foodRows = $(".food-row"); |
|
const foodRowsSize = $(foodRows).size(); |
|
new Array(foodRowsSize).fill(foodRowsSize).forEach((_, index) => { |
|
const row = $(foodRows).get(index); |
|
const td = $(row).children("td").last() |
|
const currentNumber = $("<span>"+ $(td).text() +"</span>"); |
|
|
|
$(td).html(currentNumber).append(wrapper(index)); |
|
|
|
const changeValue = (elem, num) => { |
|
const span = $(elem).parent().parent().children("span"); |
|
const spanValue = $(span).text().replace(/[،,]/g, ""); |
|
const normilizedNumber = parseInt(persianJs(spanValue).persianNumber().toString(), 10) + num; |
|
|
|
$(span).html(toEnglishNumber(normilizedNumber)) |
|
} |
|
|
|
$(document.body).on('click', "#modifier_price_" + index + " > .plus", function(e) { |
|
changeValue($(this), 1000); |
|
|
|
getTotalPrice("plus"); |
|
}); |
|
|
|
$(document.body).on('click', "#modifier_price_" + index + " > .minus", function(e) { |
|
changeValue($(this), -1000); |
|
|
|
getTotalPrice("minus"); |
|
}); |
|
}); |
|
} |
|
////////// Company name //////////////// |
|
const addCompanyName = name => { |
|
$(".panel-body").children("div.row").first().clone().prependTo($(".panel.body")); |
|
|
|
$(".panel-body").children("div.row").first().find(".idn-right span").html("گیرنده"); |
|
$(".panel-body").children("div.row").first().find(".idn-left span").html(name); |
|
} |
|
|
|
const updateDate = date => { |
|
$(".panel-body").children("div.row:nth-child(2)").find(".idn-left span").html(date); |
|
} |
|
|
|
const removeAll = () => { |
|
$(".modifier").remove(); |
|
} |
|
|
|
addCompanyName("نام شرکت"); |
|
|
|
window.deactive = removeAll; |
|
window.updateDate = updateDate; |
|
window.active = showUpdatePrice; |
|
window.updateCompanyName = addCompanyName; |
|
})(); |