Last active
September 4, 2022 14:33
-
-
Save rigwild/0d2c2813bde211c8895a38f9aa270771 to your computer and use it in GitHub Desktop.
Userscript to improve the wegobuy.com agent website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Photo fixed + EUR price + Keyboard arrows | |
// @namespace Violentmonkey Scripts | |
// @match https://www.wegobuy.com/en/page/buy | |
// @grant none | |
// @version 1.0 | |
// @author - | |
// @description 8/28/2022, 1:40:18 AM | |
// ==/UserScript== | |
;(async () => { | |
// Keyboard arrows shortcuts | |
document.onkeydown = e => { | |
if (e.keyCode === 37 || e.keyCode === 39) { | |
const options = [...document.querySelectorAll('.goods-options-tags li')] | |
const currentIndex = options.findIndex(x => x.classList.contains('active')) | |
let nextEle; | |
if (e.keyCode === 37 && currentIndex > 0) { | |
// Left arrow | |
nextEle = options[currentIndex - 1] | |
} | |
else if (e.keyCode === 39 && currentIndex < options.length - 1) { | |
// Right arrow | |
nextEle = options[currentIndex + 1] | |
} | |
nextEle.click() | |
// Scroll to the new selection | |
// Find <dl> scrollable parent element | |
let scrollableParent = nextEle | |
while (!!scrollableParent && scrollableParent.tagName !== 'DL') | |
scrollableParent = scrollableParent.parentElement | |
if (!scrollableParent) return // The website is not the same, should have found a <dl> element! | |
scrollableParent.scrollTop = nextEle.offsetTop - 200 | |
} | |
} | |
let itemsListScrollSet = false | |
setInterval(() => { | |
// document.querySelector('.preview-window').style.position = 'fixed' | |
// Click accept on load alert popup (e.g. counterfeit alert) | |
document.querySelector('.dialogRisk-wrap footer a')?.click() | |
// Show EUR price conversion | |
const priceYuan = document.querySelector('.goods-price-tool .goods-txt')?.innerText | |
if (priceYuan) { | |
const priceEuroStr = (priceYuan * 0.1460).toFixed(2) | |
let priceEuroEle = document.querySelector('#price-euro-conversion') | |
if (!priceEuroEle) { | |
priceEuroEle = document.createElement('strong') | |
priceEuroEle.innerText = `- ${priceEuroStr} €` | |
priceEuroEle.classList.add('goods-txt') | |
priceEuroEle.style.marginLeft = '8px' | |
priceEuroEle.id = 'price-euro-conversion' | |
document.querySelector('.goods-price-tool').append(priceEuroEle) | |
} | |
else { | |
priceEuroEle.innerText = `- ${priceEuroStr} €` | |
} | |
} | |
// Make the options list scrollable | |
if (!itemsListScrollSet) { | |
const itemsList = document.querySelector('.goods-sizes .goods-options-row') | |
if (itemsList) { | |
itemsList.style.overflow = 'scroll' | |
itemsList.style.height = '500px' | |
itemsListScrollSet = true | |
} | |
} | |
}, 500) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment