mirror of
https://github.com/Maks1mS/userscripts.git
synced 2024-12-24 00:33:03 +03:00
Compare commits
3 Commits
6e2eb40def
...
5de1a557f1
Author | SHA1 | Date | |
---|---|---|---|
5de1a557f1 | |||
|
db9d93407d | ||
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/*
|
||||||
@ -99,13 +99,11 @@
|
|||||||
updateInfo(element);
|
updateInfo(element);
|
||||||
addObserver(element, () => {
|
addObserver(element, () => {
|
||||||
updateInfo(element);
|
updateInfo(element);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
updateInfoALL();
|
||||||
updateInfoPeriodically(5000);
|
onSelectorAdd(document.body, [
|
||||||
|
'[data-widget="commonAddressBook"]',
|
||||||
function handleNewElement(mutationsList) {
|
], updateInfoALL);
|
||||||
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();
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Steam Price Converter
|
// @name Steam Price Converter
|
||||||
// @namespace https://github.com/Maks1mS/userscripts
|
// @namespace https://github.com/Maks1mS/userscripts
|
||||||
// @version 0.2
|
// @version 0.4
|
||||||
// @description Converts prices to rubles
|
// @description Converts prices to rubles
|
||||||
// @author Maxim Slipenko
|
// @author Maxim Slipenko
|
||||||
// @match https://store.steampowered.com/*
|
// @match https://store.steampowered.com/*
|
||||||
@ -10,7 +10,7 @@
|
|||||||
// @grant GM_registerMenuCommand
|
// @grant GM_registerMenuCommand
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
(function() {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const SYMBOL_TO_CODE_MAPPING = {
|
const SYMBOL_TO_CODE_MAPPING = {
|
||||||
@ -23,12 +23,15 @@
|
|||||||
source_symbol: undefined
|
source_symbol: undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const delay = (ms) =>
|
||||||
|
new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
async function getRates() {
|
async function getRates() {
|
||||||
const arr = await new Promise((resolve, reject) => {
|
const arr = await new Promise((resolve, reject) => {
|
||||||
GM_xmlhttpRequest({
|
GM_xmlhttpRequest({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: 'https://www.cbr-xml-daily.ru/daily_utf8.xml',
|
url: 'https://www.cbr-xml-daily.ru/daily_utf8.xml',
|
||||||
onload: function(res) {
|
onload: function (res) {
|
||||||
const valutes = res.responseXML.getElementsByTagName('Valute');
|
const valutes = res.responseXML.getElementsByTagName('Valute');
|
||||||
resolve([...valutes].map((valute) => {
|
resolve([...valutes].map((valute) => {
|
||||||
const charCode = valute.getElementsByTagName('CharCode')[0].textContent;
|
const charCode = valute.getElementsByTagName('CharCode')[0].textContent;
|
||||||
@ -62,19 +65,22 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await delay(75);
|
||||||
|
|
||||||
const convert = (n) => +(n * rates[source_valute].value).toFixed(2);
|
const convert = (n) => +(n * rates[source_valute].value).toFixed(2);
|
||||||
replace(convert);
|
replace(convert);
|
||||||
|
|
||||||
GM_registerMenuCommand("update", () => replace(convert), "u");
|
// GM_registerMenuCommand("update", () => replace(convert), "u");
|
||||||
}
|
}
|
||||||
|
|
||||||
function replace(convert) {
|
function replace(convert) {
|
||||||
let r = document.evaluate(`//text()[contains(., \"${state.source_symbol}\")]`,document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
let r = document.evaluate(`//text()[contains(., \"${state.source_symbol}\")]`, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||||
|
|
||||||
for (let i = 0; i < r.snapshotLength; i++) {
|
for (let i = 0; i < r.snapshotLength; i++) {
|
||||||
let n = r.snapshotItem(i);
|
let n = r.snapshotItem(i);
|
||||||
const value = parseFloat(n.textContent.replace(" ", "").replace(',', '.'))
|
const value = parseFloat(n.textContent.replace(" ", "").replace(',', '.'))
|
||||||
n.replaceWith(`${convert(value)} ₽`);
|
|
||||||
|
n.replaceWith(`${convert(value)} ₽ / ${value} ${state.source_symbol}`);
|
||||||
console.log(n)
|
console.log(n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user