Implemented changeInstance shortcut in a different way #112
This commit is contained in:
parent
3950812dd9
commit
5582bde76b
@ -45,5 +45,13 @@
|
||||
"encoding": "UTF-8",
|
||||
"is_default": false
|
||||
}
|
||||
},
|
||||
"commands": {
|
||||
"changeInstance": {
|
||||
"suggested_key": {
|
||||
"default": "Alt+Shift+L"
|
||||
},
|
||||
"description": "Change Instance"
|
||||
}
|
||||
}
|
||||
}
|
@ -167,14 +167,6 @@ browser.tabs.onUpdated.addListener(
|
||||
if (instagramHelper.isBibliogram(url)) instagramHelper.initBibliogramCookies(url);
|
||||
// if (changeInfo.url && youtubeHelper.isPipedorInvidious(url, 'main_frame', 'pipedMaterial')) youtubeHelper.initPipedMaterialLocalStorage(tabId);
|
||||
|
||||
if (changeWholeInstance(url))
|
||||
browser.tabs.executeScript(
|
||||
tabId,
|
||||
{
|
||||
file: "/pages/background/shortcuts.js",
|
||||
runAt: "document_start"
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
function changeWholeInstance(url) {
|
||||
@ -203,12 +195,18 @@ function changeWholeInstance(url) {
|
||||
return newUrl;
|
||||
}
|
||||
|
||||
browser.runtime.onMessage.addListener(
|
||||
message => {
|
||||
if (message.function === 'changeInstance') {
|
||||
const url = new URL(message.url);
|
||||
let newUrl = changeWholeInstance(url);
|
||||
if (newUrl) browser.tabs.update({ url: newUrl });
|
||||
}
|
||||
browser.commands.onCommand.addListener(
|
||||
command => {
|
||||
if (command === 'changeInstance')
|
||||
chrome.tabs.query(
|
||||
{ active: true, currentWindow: true },
|
||||
tabs => {
|
||||
let url;
|
||||
try { url = new URL(tabs[0].url); }
|
||||
catch (_) { return }
|
||||
let newUrl = changeWholeInstance(url);
|
||||
if (newUrl) browser.tabs.update({ url: newUrl });
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
@ -1,13 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
window.browser = window.browser || window.chrome;
|
||||
|
||||
document.addEventListener('keydown',
|
||||
e => {
|
||||
if (e.code === 'KeyL' && e.shiftKey && e.altKey)
|
||||
browser.runtime.sendMessage({
|
||||
function: "changeInstance",
|
||||
url: window.location.href,
|
||||
});
|
||||
}
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user