Created
July 15, 2022 20:51
-
-
Save gioragutt/9ac5ced7d7a65319bd367122ff235222 to your computer and use it in GitHub Desktop.
yad2 tampermonkey userscript
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 Yad2 Fixes | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://www.yad2.co.il/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=co.il | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
document.addEventListener('keydown', event => { | |
if (event.code === 'ArrowLeft') { | |
document.querySelector('.swiper-button-prev')?.click(); | |
} else if (event.code === 'ArrowRight') { | |
document.querySelector('.swiper-button-next')?.click(); | |
} | |
}) | |
document.querySelector('.lightbox_contact_seller_button')?.addEventListener('click', async () => { | |
while (document.querySelectorAll('[id^="lightbox_phone_number"]').length === 0) { | |
await new Promise(res => setTimeout(res, 300)); | |
} | |
const url = new URL(document.querySelector('a[title="טאב חדש"]')?.href); | |
url.search = ''; | |
const ownerName = document.querySelector('.seller .name')?.textContent; | |
const address = document.querySelector('.main_title')?.textContent; | |
const neighbourhoodAndCity = [...document.querySelector('.description')?.querySelectorAll('span')].map(x => x.textContent).join(' ') | |
const fullAddress = `${address}, ${neighbourhoodAndCity}`; | |
const hour = new Date().getHours(); | |
let greeting; | |
if (hour > 17) greeting = 'ערב טוב'; | |
else if (hour < 12) greeting = 'בוקר טוב'; | |
else greeting = 'צהוריים טובים'; | |
const message = `היי ${ownerName}, ${greeting}, פונה בקשר לדירה ב-${address} שפירסמת ביד2 (${url.href}), האם עדיין רלוונטי?`; | |
for (const phoneNumberElement of document.querySelectorAll('[id^="lightbox_phone_number"]')) { | |
const phoneNumber = `972${phoneNumberElement.textContent.trim().substring(1)}`.replace('-', ''); | |
const link = `https://api.whatsapp.com/send?phone=${phoneNumber}&text=${encodeURI(message)}`; | |
const tickTickUrl = new URL( | |
`ticktick://x-callback-url/v1/add_task`, | |
); | |
tickTickUrl.searchParams.append('title', fullAddress); | |
tickTickUrl.searchParams.append('list', encodeURI('Yad2 TODOs')); | |
tickTickUrl.searchParams.append('content', url.href); | |
const tickTickTaskAnchor = document.createElement('a'); | |
tickTickTaskAnchor.href = tickTickUrl.toString(); | |
tickTickTaskAnchor.target = '_blank'; | |
tickTickTaskAnchor.innerHTML = `<b>TT</b>`; | |
phoneNumberElement.appendChild(tickTickTaskAnchor); | |
const phoneLinkElement = phoneNumberElement.querySelector('a'); | |
phoneLinkElement.href = link; | |
phoneLinkElement.style.pointerEvents = 'unset'; | |
phoneLinkElement.target = '_blank'; | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment