Skip to content

Instantly share code, notes, and snippets.

@ali-master
Last active November 20, 2021 13:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ali-master/1a1d987aee9d8f02ba8698c72c443724 to your computer and use it in GitHub Desktop.
Save ali-master/1a1d987aee9d8f02ba8698c72c443724 to your computer and use it in GitHub Desktop.
Update Snappfood order page

Install

  1. Install the tampermonkey extension.
  2. Add this hack into your scripts
  3. Go to snappfood.com and then click on an order in orders page.
  4. Open the browser console
  5. Call one of these functions in console

Change date

updateDate("۱۳۹۸/۰۱/۱۲");

Change company name

updateCompanyName("تست");

Show price updater

active();

Hide price updater

deactive();

Star me if you liked it. Thank you.

// ==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/persianjs@0.4.0/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;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment