Simplify process for getting tab URL
This commit is contained in:
parent
135697a544
commit
7f7a0d4b68
|
@ -16,7 +16,8 @@ function init() {
|
||||||
function loadDomain() {
|
function loadDomain() {
|
||||||
let tabs = browser.tabs.query({ active: true, currentWindow: true });
|
let tabs = browser.tabs.query({ active: true, currentWindow: true });
|
||||||
tabs.then((tabs) => {
|
tabs.then((tabs) => {
|
||||||
const url = new URL(tabs[0].url);
|
const tab = tabs[0];
|
||||||
|
const url = new URL(tab.url);
|
||||||
const isAllowedProtocol = url.protocol == "https:" || url.protocol == "http:";
|
const isAllowedProtocol = url.protocol == "https:" || url.protocol == "http:";
|
||||||
|
|
||||||
if (!isAllowedProtocol) {
|
if (!isAllowedProtocol) {
|
||||||
|
@ -24,10 +25,10 @@ function loadDomain() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelector("#domain").textContent = url.hostname;
|
document.querySelector("#domain").textContent = url.host;
|
||||||
let storage = browser.storage.local.get("domains");
|
let storage = browser.storage.local.get("domains");
|
||||||
storage.then((storage) => {
|
storage.then((storage) => {
|
||||||
const hostname = document.querySelector("#domain").innerHTML;
|
const hostname = url.host;
|
||||||
const domains = storage.domains;
|
const domains = storage.domains;
|
||||||
if (domains === undefined) {
|
if (domains === undefined) {
|
||||||
browser.storage.local.set({"domains": []});
|
browser.storage.local.set({"domains": []});
|
||||||
|
|
Loading…
Reference in New Issue