mirror of
https://github.com/Maks1mS/userscripts.git
synced 2024-12-24 00:33:03 +03:00
[FreeOzonDPR] update to 0.2
This commit is contained in:
parent
6e2eb40def
commit
32a4239fe4
@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name БЕСПЛАТНЫЕ ПВЗ ОЗОН
|
// @name БЕСПЛАТНЫЕ ПВЗ ОЗОН
|
||||||
// @namespace https://github.com/Maks1mS/userscripts
|
// @namespace https://github.com/Maks1mS/userscripts
|
||||||
// @version 0.1
|
// @version 0.2
|
||||||
// @description Заменяет партнерские ПВЗ на понятные адреса
|
// @description Заменяет партнерские ПВЗ на понятные адреса
|
||||||
// @author Maxim Slipenko
|
// @author Maxim Slipenko
|
||||||
// @match https://www.ozon.ru/*
|
// @match https://www.ozon.ru/*
|
||||||
@ -104,8 +104,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateInfoALL() {
|
function updateInfoALL() {
|
||||||
console.log('updateall!');
|
|
||||||
|
|
||||||
const headerAddress = qs('[data-widget="addressBookBarWeb"] .tsBody400Small');
|
const headerAddress = qs('[data-widget="addressBookBarWeb"] .tsBody400Small');
|
||||||
const commonAddressBook = qsa('[data-widget="commonAddressBook"] .tsBody500Medium');
|
const commonAddressBook = qsa('[data-widget="commonAddressBook"] .tsBody500Medium');
|
||||||
const delivery = qsa('[data-widget="orderDeliveryDetails"] .tsBody500Medium');
|
const delivery = qsa('[data-widget="orderDeliveryDetails"] .tsBody500Medium');
|
||||||
@ -120,41 +118,52 @@
|
|||||||
updateInfoALL();
|
updateInfoALL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function onSelectorAdd(targetNode, selector, callback) {
|
||||||
|
function check(s) {
|
||||||
|
const r = qs(s);
|
||||||
|
if (r) {
|
||||||
|
callback(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkSelector() {
|
||||||
|
if (Array.isArray(selector)) {
|
||||||
|
selector.forEach(check);
|
||||||
|
}
|
||||||
|
check(selector);
|
||||||
|
}
|
||||||
|
checkSelector();
|
||||||
|
function handle(mutationsList) {
|
||||||
|
for (let mutation of mutationsList) {
|
||||||
|
if (mutation.type === 'childList') {
|
||||||
|
checkSelector();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addObserver(targetNode, handle, { childList: true, subtree: true });
|
||||||
|
}
|
||||||
|
|
||||||
let called = false;
|
let called = false;
|
||||||
|
|
||||||
function fullExecute() {
|
function fullExecute() {
|
||||||
if (called) return;
|
if (called) return;
|
||||||
|
|
||||||
called = true;
|
called = true;
|
||||||
|
|
||||||
updateInfoPeriodically(5000);
|
|
||||||
|
|
||||||
function handleNewElement(mutationsList) {
|
|
||||||
for (let mutation of mutationsList) {
|
|
||||||
if (mutation.type === 'childList') {
|
|
||||||
mutation.addedNodes.forEach(node => {
|
|
||||||
if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains('vue-portal-target')) {
|
|
||||||
setTimeout(() => {
|
|
||||||
updateInfoALL();
|
updateInfoALL();
|
||||||
}, 1000);
|
onSelectorAdd(document.body, [
|
||||||
}
|
'[data-widget="commonAddressBook"]',
|
||||||
});
|
], updateInfoALL);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const observer = new MutationObserver(handleNewElement);
|
|
||||||
|
|
||||||
const targetNode = document.body;
|
|
||||||
const config = { childList: true, subtree: true };
|
|
||||||
|
|
||||||
observer.observe(targetNode, config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('popstate', fullExecute);
|
window.addEventListener('popstate', fullExecute);
|
||||||
window.addEventListener('load', fullExecute);
|
window.addEventListener('load', fullExecute);
|
||||||
document.addEventListener('DOMContentLoaded', fullExecute);
|
document.addEventListener('DOMContentLoaded', fullExecute);
|
||||||
setTimeout(fullExecute, 2500);
|
|
||||||
|
if (document.readyState == "complete" ||
|
||||||
|
document.readyState == "loaded" ||
|
||||||
|
document.readyState == "interactive"
|
||||||
|
) {
|
||||||
|
fullExecute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
Loading…
Reference in New Issue
Block a user