-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholx_auto_click_grid_icon.js
44 lines (38 loc) · 1.43 KB
/
olx_auto_click_grid_icon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// ==UserScript==
// @name OLX Auto Click Grid Icon
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Clicks grid icon on OLX if it's inactive
// @author puksh
// @match https://www.olx.pl/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const targetColor = 'rgb(127, 151, 153)'; // #7F9799 in rgb format
const targetColorDarkReader = 'rgb(159, 151, 139)';
function simulateClick(element) {
const event = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
element.dispatchEvent(event);
console.log("Simulated click dispatched.");
}
function checkAndClick() {
const gridIconParent = document.querySelector('[data-testid="grid-icon"]');
if (gridIconParent) {
const style = window.getComputedStyle(gridIconParent);
if (style.color === targetColor || style.color === targetColorDarkReader) {
console.log("Grid icon found with matching color. Clicking...");
simulateClick(gridIconParent);
}
}
}
// Observe DOM changes for dynamically loaded elements
const observer = new MutationObserver(() => checkAndClick());
observer.observe(document.body, { childList: true, subtree: true });
// Initial check in case the element is already present
checkAndClick();
})();