Skip to content

Commit

Permalink
0.0.21
Browse files Browse the repository at this point in the history
- ensure that popup window centered based on current screen when 'Close popup when origin window is focused' is uncheck.(try to make it work with zoom level change)
- ensure "send page back" response when idle.
- added Wikipedia in search providers.
- keep options page following system's light/dark mode.
  • Loading branch information
u-Sir authored Jul 15, 2024
1 parent 2bf8301 commit d9d5ed6
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 110 deletions.
10 changes: 5 additions & 5 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
"message": "Set blur effect on Original Window when popup"
},
"enableContainerIdentify": {
"message": "keep open in the same container as original page"
"message": "Keep open in the same container as original page"
},
"blurPx": {
"message": "blur effect strengh: "
"message": "Blur effect strengh: "
},
"blurTime": {
"message": "blur in specific seconds (s): "
"message": "Blur in specific seconds (s): "
},
"keySelection": {
"message": "Response when selected key is pressing (Please test to ensure it meets expectations.)"
Expand All @@ -48,10 +48,10 @@
"message": "Search provider"
},
"custom": {
"message": "custom search url (use %s as selected text)"
"message": "Custom (use %s as selected text)"
},
"searchDisable": {
"message": "Disable search in popup window"
"message": "Disable"
},
"noneKey": {
"message": "None"
Expand Down
6 changes: 3 additions & 3 deletions _locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
"message": "Aplicar efecto de desenfoque en la ventana original al abrir el popup"
},
"enableContainerIdentify": {
"message": "mantener abierto en el mismo contenedor que la página original"
"message": "Mantener abierto en el mismo contenedor que la página original"
},
"blurPx": {
"message": "intensidad del efecto de desenfoque: "
"message": "Intensidad del efecto de desenfoque: "
},
"blurTime": {
"message": "desenfoque en segundos específicos (s): "
"message": "Desenfoque en segundos específicos (s): "
},
"keySelection": {
"message": "Respuesta cuando se presiona la tecla seleccionada (Por favor, prueba para asegurarte de que cumple con las expectativas.)"
Expand Down
2 changes: 1 addition & 1 deletion _locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"message": "搜索引擎"
},
"custom": {
"message": "自定义"
"message": "自定义(选中文本:%s)"
},
"searchDisable": {
"message": "禁用"
Expand Down
36 changes: 28 additions & 8 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
});
console.log('Current window:', currentWindow);


const userConfigs = await loadUserConfigs();
let { originWindowId } = userConfigs;

Expand Down Expand Up @@ -135,15 +136,25 @@ chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
sendResponse({ status: 'window focus handled' });
}

const zoomFactor = await new Promise((resolve, reject) => {
chrome.tabs.getZoom(sender.tab.id, (zoom) => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve(zoom);
}
});
});

await Promise.all([
saveConfig('lastClientX', request.lastClientX),
saveConfig('lastClientY', request.lastClientY),
saveConfig('lastScreenTop', request.top),
saveConfig('lastScreenLeft', request.left),
saveConfig('lastScreenWidth', request.width),
saveConfig('lastScreenHeight', request.height)
saveConfig('lastClientX', request.lastClientX * zoomFactor),
saveConfig('lastClientY', request.lastClientY * zoomFactor),
saveConfig('lastScreenTop', request.top * zoomFactor),
saveConfig('lastScreenLeft', request.left * zoomFactor),
saveConfig('lastScreenWidth', request.width * zoomFactor),
saveConfig('lastScreenHeight', request.height * zoomFactor)
]);

const { disabledUrls } = userConfigs;
if (isUrlDisabled(sender.tab.url, disabledUrls)) {
sendResponse({ status: 'url disabled' });
Expand Down Expand Up @@ -174,7 +185,7 @@ async function handleLinkInPopup(linkUrl, tab, currentWindow) {
const {
lastClientX, lastClientY, enableContainerIdentify,
popupHeight, popupWidth, tryOpenAtMousePosition,
lastScreenTop, lastScreenLeft, lastScreenWidth, lastScreenHeight
lastScreenTop, lastScreenLeft, lastScreenWidth, lastScreenHeight, devicePixelRatio
} = userConfigs;

const height = parseInt(popupHeight, 10) || 800;
Expand All @@ -185,6 +196,15 @@ async function handleLinkInPopup(linkUrl, tab, currentWindow) {
dx = Math.max(lastScreenLeft, Math.min(dx, lastScreenLeft + lastScreenWidth - width));
dy = Math.max(lastScreenTop, Math.min(dy, lastScreenTop + lastScreenHeight - height));

console.log("tryOpenAtMousePosition: " + tryOpenAtMousePosition )
console.log("lastScreenLeft: " + lastScreenLeft )
console.log("lastScreenTop: " + lastScreenTop )
console.log("lastScreenWidth: " + lastScreenWidth)
console.log("lastScreenHeight: " + lastScreenHeight)
console.log("dx - dy : " + dx + "-" + dy)
console.log("devicePixelRatio: " + devicePixelRatio)


const createData = {
url: linkUrl,
type: 'popup',
Expand Down
26 changes: 13 additions & 13 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@ const configs = {
async function loadUserConfigs() {
return new Promise(resolve => {
chrome.storage.local.get(Object.keys(configs), storedConfigs => {
// Merge stored configurations with default configs, setting defaults for undefined keys
const mergedConfigs = { ...configs, ...storedConfigs };

// Update the main configs object with merged configurations
Object.assign(configs, mergedConfigs);

// Log the merged configurations (optional)
// console.log('Loaded and merged user configurations:', configs);

// Resolve with the merged configurations
resolve(mergedConfigs);
});
});
Expand Down Expand Up @@ -54,10 +46,16 @@ function removeListeners() {
function handleEvent(e) {
if (e.type === 'dragstart') {
handleDragStart(e);
} else if (['dragover', 'drop', 'dragend', 'mouseup'].includes(e.type)) {

} else if (['dragover', 'drop', 'dragend'].includes(e.type)) {
preventEvent(e);
} else if (e.type === 'click') {
handleClick(e);
} else if (e.type === 'mouseup') {
if (e.target.tagName === 'A' && e.target.href) {
e.preventDefault();
e.stopImmediatePropagation();
}
}
}

Expand All @@ -84,7 +82,8 @@ async function handleDragStart(e) {
}

if (e.target.tagName === 'A' || (selectionText && searchEngine !== 'None')) {
preventEvent(e);
e.preventDefault();
e.stopImmediatePropagation();

if (blurEnabled) {
document.body.style.filter = `blur(${blurPx}px)`;
Expand All @@ -108,8 +107,9 @@ function handleClick(e) {
preventEvent(e);
isDragging = false;
}

}

function isUrlDisabled(url, disabledUrls) {
return disabledUrls.some(disabledUrl => {
if (disabledUrl.includes('*')) {
Expand Down Expand Up @@ -182,10 +182,10 @@ window.addEventListener('focus', async () => {
try {
document.body.style.filter = '';
const data = await loadUserConfigs(['closeWhenFocusedInitialWindow']);
const message = data.closeWhenFocusedInitialWindow
const message = data.closeWhenFocusedInitialWindow
? { action: 'windowRegainedFocus', checkContextMenuItem: true }
: { checkContextMenuItem: true };

const response = await sendMessageToBackground(message);
console.log("Background script responded:", response);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "0.0.20",
"version": "0.0.21",
"default_locale": "en",
"icons": {
"48": "icon.svg",
Expand Down
27 changes: 18 additions & 9 deletions options/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,32 @@
border-radius: 4px;
}

input[type="text"], input[type="number"], textarea {
input[type="text"],
input[type="number"],
textarea {
min-width: 40%;
margin-right: 4px;
}

textarea {
width: 100%;
box-sizing: border-box; /* Ensure the textarea takes the full width */
box-sizing: border-box;
/* Ensure the textarea takes the full width */
margin-top: 5px;
padding: 5px;
font-size: 14px;
resize: vertical; /* Allow vertical resize */
resize: vertical;
/* Allow vertical resize */
}

legend {
background-color: #0000007d;
color: #fff;
padding: 3px 6px;
}
}


/* Dark Mode */
/* Dark Mode */
@media (prefers-color-scheme: dark) {
body {
background-color: #121212;
Expand All @@ -49,7 +54,9 @@ legend {
border-radius: 4px;
}

input[type="text"], input[type="number"], textarea {
input[type="text"],
input[type="number"],
textarea {
min-width: 40%;
margin-right: 4px;
background-color: #1e1e1e;
Expand All @@ -59,11 +66,13 @@ legend {

textarea {
width: 100%;
box-sizing: border-box; /* Ensure the textarea takes the full width */
box-sizing: border-box;
/* Ensure the textarea takes the full width */
margin-top: 5px;
padding: 5px;
font-size: 14px;
resize: vertical; /* Allow vertical resize */
resize: vertical;
/* Allow vertical resize */
background-color: #1e1e1e;
color: #e0e0e0;
border: 1px solid #333;
Expand All @@ -74,4 +83,4 @@ legend {
color: #e0e0e0;
padding: 3px 6px;
}
}
}
15 changes: 12 additions & 3 deletions options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

<input type="radio" id="noneKey" name="modifiedKey" value="None" />
<label for="noneKey">None</label>
<br >
</fieldset>
</p>

Expand All @@ -33,23 +34,31 @@
<p>
<fieldset>
<legend id="searchEngineSelection">Select Search Engine</legend>
<input type="radio" id="custom" name="searchEngine" value="custom" />
<label for="custom">Custom</label>
<input type="radio" id="google" name="searchEngine" value="https://www.google.com/search?q=%s" />
<label for="google">Google</label>

<input type="radio" id="bing" name="searchEngine" value="https://www.bing.com/search?q=%s" />
<label for="bing">Bing</label>

<input type="radio" id="baidu" name="searchEngine" value="https://www.baidu.com/s?wd=%s" />
<label for="baidu">Baidu</label>

<input type="radio" id="yandex" name="searchEngine" value="https://yandex.com/search/?text=%s" />
<label for="yandex">Yandex</label>

<input type="radio" id="duckduckgo" name="searchEngine" value="https://duckduckgo.com/?q=%s" />
<label for="duckduckgo">DuckDuckGo</label>

<input type="radio" id="wiki" name="searchEngine" value="https://wikipedia.org/w/index.php?title=Special:Search&search=%s" />
<label for="wiki">Wikipedia</label>

<input type="radio" id="searchDisable" name="searchEngine" value="None" />
<label for="searchDisable">None</label>
<input type="text" id="customSearchEngine" style="display:none;" placeholder="URL" />
<br>
<input type="radio" id="custom" name="searchEngine" value="custom" />
<label for="custom">Custom</label>
<input type="text" id="customSearchEngine" style="display:none;" placeholder="https://example.com/%s" />

</fieldset>
</p>

Expand Down
Loading

0 comments on commit d9d5ed6

Please sign in to comment.