-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
150 lines (131 loc) · 4.19 KB
/
preload.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const { contextBridge, ipcRenderer } = require('electron');
// Create the UI bar element
function createUIBar() {
const bar = document.createElement('div');
bar.id = 'homebox-ui-bar';
bar.style.cssText = `
position: fixed;
top: 0;
left: 0;
right: 0;
height: 30px;
background: #f5f5f5;
border-bottom: 1px solid #ddd;
display: flex;
align-items: center;
padding: 0 10px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
font-size: 12px;
z-index: 999999;
`;
const urlDisplay = document.createElement('div');
urlDisplay.id = 'url-display';
urlDisplay.style.cssText = `
flex: 1;
overflow-x: auto;
margin-right: 10px;
`;
const copyButton = document.createElement('button');
copyButton.innerHTML = '📋';
copyButton.style.cssText = `
background: none;
border: none;
cursor: pointer;
padding: 5px;
margin-right: 10px;
font-size: 14px;
`;
copyButton.title = 'Copy URL';
const assetIdDisplay = document.createElement('div');
assetIdDisplay.id = 'asset-id-display';
assetIdDisplay.style.cssText = `
margin-left: 10px;
padding: 2px 6px;
background: #e9ecef;
border-radius: 3px;
`;
// Add search input
const searchContainer = document.createElement('div');
searchContainer.style.cssText = `
display: flex;
align-items: center;
margin-right: 10px;
`;
const searchInput = document.createElement('input');
searchInput.type = 'text';
searchInput.placeholder = 'Search by Asset ID...';
searchInput.style.cssText = `
padding: 2px 6px;
border: 1px solid #ddd;
border-radius: 3px;
font-size: 12px;
width: 150px;
`;
bar.appendChild(urlDisplay);
bar.appendChild(copyButton);
searchContainer.appendChild(searchInput);
bar.appendChild(searchContainer);
bar.appendChild(assetIdDisplay);
setupSearchFunctionality(searchInput);
// Add 30px padding to body to account for the bar
document.body.style.paddingTop = '30px';
// Update URL display
urlDisplay.textContent = window.location.href;
// Copy URL functionality
copyButton.addEventListener('click', () => {
navigator.clipboard.writeText(window.location.href);
copyButton.innerHTML = '✓';
setTimeout(() => {
copyButton.innerHTML = '📋';
}, 1000);
});
return bar;
}
// Setup search functionality
function setupSearchFunctionality(searchInput) {
searchInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
const searchValue = searchInput.value.trim();
if (searchValue) {
// Remove any existing # symbol
const cleanId = searchValue.replace('#', '');
// Construct search URL
const searchUrl = `https://homebox.residencejlm.com/items?q=%23${cleanId}&page=1`;
window.location.href = searchUrl;
}
}
});
}
// Detect asset ID from the page
function detectAssetId() {
// Look for asset ID in table cells
const cells = document.querySelectorAll('td');
let assetIdMatch = null;
for (const cell of cells) {
const match = cell.textContent.match(/^(\d{3}-\d{3}|\d{2}-\d{3}|\d{3}-\d{2}|\d{2}-\d{2})$/);
if (match) {
assetIdMatch = match;
break;
}
}
if (assetIdMatch) {
const assetIdDisplay = document.getElementById('asset-id-display');
if (assetIdDisplay) {
assetIdDisplay.textContent = `Asset ID: ${assetIdMatch[1]}`;
}
}
}
// Initialize UI when the page loads
window.addEventListener('DOMContentLoaded', () => {
const bar = createUIBar();
document.body.prepend(bar);
detectAssetId();
});
// Update UI on navigation
window.addEventListener('popstate', () => {
const urlDisplay = document.getElementById('url-display');
if (urlDisplay) {
urlDisplay.textContent = window.location.href;
}
detectAssetId();
});