Skip to content

Instantly share code, notes, and snippets.

@rigwild
Last active September 4, 2022 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rigwild/0d2c2813bde211c8895a38f9aa270771 to your computer and use it in GitHub Desktop.
Save rigwild/0d2c2813bde211c8895a38f9aa270771 to your computer and use it in GitHub Desktop.
Userscript to improve the wegobuy.com agent website
// ==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