Implemented changeInstance shortcut in a different way #112
This commit is contained in:
parent
3950812dd9
commit
5582bde76b
@ -45,5 +45,13 @@
|
|||||||
"encoding": "UTF-8",
|
"encoding": "UTF-8",
|
||||||
"is_default": false
|
"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 (instagramHelper.isBibliogram(url)) instagramHelper.initBibliogramCookies(url);
|
||||||
// if (changeInfo.url && youtubeHelper.isPipedorInvidious(url, 'main_frame', 'pipedMaterial')) youtubeHelper.initPipedMaterialLocalStorage(tabId);
|
// 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) {
|
function changeWholeInstance(url) {
|
||||||
@ -203,12 +195,18 @@ function changeWholeInstance(url) {
|
|||||||
return newUrl;
|
return newUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener(
|
browser.commands.onCommand.addListener(
|
||||||
message => {
|
command => {
|
||||||
if (message.function === 'changeInstance') {
|
if (command === 'changeInstance')
|
||||||
const url = new URL(message.url);
|
chrome.tabs.query(
|
||||||
let newUrl = changeWholeInstance(url);
|
{ active: true, currentWindow: true },
|
||||||
if (newUrl) browser.tabs.update({ url: newUrl });
|
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