|
| 1 | +// ==UserScript== |
| 2 | +// @name GeoMap Auto-Agree & Defaults |
| 3 | +// @namespace https://github.com/softwareengineerprogrammer |
| 4 | +// @version 1.7 |
| 5 | +// @description Make GeoMap more usable |
| 6 | +// @author softwareengineerprogrammer |
| 7 | +// @match https://geomap.projectinnerspace.org/test* |
| 8 | +// @match https://geomap.projectinnerspace.org/geomap/* |
| 9 | +// @grant none |
| 10 | +// ==/UserScript== |
| 11 | + |
| 12 | +(function () { |
| 13 | + 'use strict'; |
| 14 | + |
| 15 | + // --- UTILITIES --- |
| 16 | + |
| 17 | + function highlightElement(element, color = 'red') { |
| 18 | + if (!element) return; |
| 19 | + const originalOutline = element.style.outline; |
| 20 | + element.style.outline = `3px solid ${color}`; |
| 21 | + element.style.boxShadow = `0 0 10px ${color}`; |
| 22 | + setTimeout(() => { |
| 23 | + element.style.outline = originalOutline; |
| 24 | + element.style.boxShadow = ''; |
| 25 | + }, 1000); |
| 26 | + } |
| 27 | + |
| 28 | + function simulateClick(element) { |
| 29 | + if (!element) return; |
| 30 | + |
| 31 | + console.log('[Userscript] ⚡ CLICKING BUTTON:', element); |
| 32 | + highlightElement(element, 'red'); // Visual confirmation for you |
| 33 | + |
| 34 | + // 1. Try Native Form Submit first (Cleanest way to trigger "onSubmit") |
| 35 | + const parentForm = element.closest('form'); |
| 36 | + if (parentForm) { |
| 37 | + try { |
| 38 | + parentForm.requestSubmit(element); |
| 39 | + console.log('[Userscript] Triggered via form.requestSubmit()'); |
| 40 | + return; |
| 41 | + } catch (e) { |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + // 2. Mouse Event Chain (Standard React requirement) |
| 46 | + const eventOptions = {bubbles: true, cancelable: true, view: window, buttons: 1}; |
| 47 | + element.dispatchEvent(new MouseEvent('mousedown', eventOptions)); |
| 48 | + element.dispatchEvent(new MouseEvent('mouseup', eventOptions)); |
| 49 | + element.dispatchEvent(new MouseEvent('click', eventOptions)); |
| 50 | + |
| 51 | + // 3. React Internal Prop Access (Fallback "God Mode") |
| 52 | + const reactKey = Object.keys(element).find(key => key.startsWith('__reactProps')); |
| 53 | + if (reactKey && element[reactKey].onClick) { |
| 54 | + console.log('[Userscript] Invoking React onClick prop directly'); |
| 55 | + try { |
| 56 | + element[reactKey].onClick({ |
| 57 | + preventDefault: () => { |
| 58 | + }, |
| 59 | + stopPropagation: () => { |
| 60 | + }, |
| 61 | + nativeEvent: new MouseEvent('click', eventOptions), |
| 62 | + target: element, |
| 63 | + currentTarget: element |
| 64 | + }); |
| 65 | + } catch (e) { |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + function setReactValue(element, value) { |
| 71 | + const lastValue = element.value; |
| 72 | + element.focus(); |
| 73 | + element.value = value; |
| 74 | + // The React 16+ Hack: Overwrite the internal value tracker |
| 75 | + const tracker = element._valueTracker; |
| 76 | + if (tracker) tracker.setValue(lastValue); |
| 77 | + element.dispatchEvent(new Event('input', {bubbles: true})); |
| 78 | + element.dispatchEvent(new Event('change', {bubbles: true})); |
| 79 | + element.dispatchEvent(new Event('blur', {bubbles: true})); |
| 80 | + } |
| 81 | + |
| 82 | + // --- MAIN LOGIC --- |
| 83 | + |
| 84 | + function setLatLong(lat, lng) { |
| 85 | + const labels = Array.from(document.querySelectorAll('label')); |
| 86 | + |
| 87 | + // Retry if DOM isn't ready |
| 88 | + if (labels.length === 0) { |
| 89 | + setTimeout(() => setLatLong(lat, lng), 500); |
| 90 | + return; |
| 91 | + } |
| 92 | + |
| 93 | + labels.forEach(label => { |
| 94 | + const text = label.textContent.trim().toLowerCase(); |
| 95 | + const container = label.parentElement; |
| 96 | + if (!container || container.offsetParent === null) return; // Skip invisible elements |
| 97 | + |
| 98 | + const input = container.querySelector('input'); |
| 99 | + if (!input) return; |
| 100 | + |
| 101 | + if (text.startsWith('latitude')) { |
| 102 | + setReactValue(input, lat); |
| 103 | + highlightElement(input, '#00ff00'); // Highlight Green |
| 104 | + } else if (text.startsWith('longitude')) { |
| 105 | + setReactValue(input, lng); |
| 106 | + highlightElement(input, '#00ff00'); // Highlight Green |
| 107 | + } |
| 108 | + }); |
| 109 | + } |
| 110 | + |
| 111 | + const setCapeStationLatLong = function () { |
| 112 | + const targetLat = 38.498766977413105; |
| 113 | + const targetLng = -112.91634316299478; |
| 114 | + |
| 115 | + try { |
| 116 | + console.log('--- Setting Cape Station Lat/Long ---'); |
| 117 | + setLatLong(targetLat, targetLng); |
| 118 | + |
| 119 | + setTimeout(function () { |
| 120 | + // Find all buttons on the page |
| 121 | + const allButtons = Array.from(document.querySelectorAll('button')); |
| 122 | + |
| 123 | + // Filter specifically for the one that says "UPDATE" |
| 124 | + const updateBtn = allButtons.find(btn => |
| 125 | + btn.innerText.trim().toUpperCase() === 'UPDATE' |
| 126 | + ); |
| 127 | + |
| 128 | + if (updateBtn) { |
| 129 | + console.log('[Userscript] Found "UPDATE" button.'); |
| 130 | + simulateClick(updateBtn); |
| 131 | + } else { |
| 132 | + console.error('[Userscript] ❌ Could not find a button with text "UPDATE".'); |
| 133 | + // Log available buttons to help debug if it fails again |
| 134 | + console.log('Available buttons:', allButtons.map(b => b.innerText.trim())); |
| 135 | + } |
| 136 | + }, 1000); |
| 137 | + } catch (e) { |
| 138 | + console.error('Error in sequence:', e); |
| 139 | + } |
| 140 | + }; |
| 141 | + |
| 142 | + let clickAgree = function () { |
| 143 | + let btn = document.querySelector('.test_starting_popup-module--acknowledgeButton--4b14d') || |
| 144 | + document.querySelector('.library_starting_popup-module--acknowledgeButton--50da6'); |
| 145 | + |
| 146 | + if (btn) { |
| 147 | + btn.click(); |
| 148 | + return; |
| 149 | + } |
| 150 | + setTimeout(clickAgree, 100); |
| 151 | + }; |
| 152 | + |
| 153 | + clickAgree(); |
| 154 | + setTimeout(setCapeStationLatLong, 3000); |
| 155 | +})(); |
0 commit comments