1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-04-18 08:08:28 +02:00

Fixed options standalone detection.

This commit is contained in:
kkapsner 2018-08-18 22:35:52 +02:00
parent dfc613db04
commit 635912c8b9
2 changed files with 38 additions and 23 deletions

View File

@ -34,30 +34,44 @@
} }
}; };
if (window === window.top){ new Promise(function(resolve){
let head = document.createElement("header"); const port = browser.runtime.connect();
let heading = document.createElement("h1"); port.onMessage.addListener(function(data){
heading.textContent = browser.i18n.getMessage("options"); if (data.hasOwnProperty("tabId")){
head.appendChild(heading); logging.notice("my tab id is", data.tabId);
port.disconnect();
let introduction = document.createElement("div"); resolve(data.tabId);
introduction.textContent = browser.i18n.getMessage("optionsIntroduction");
head.appendChild(introduction);
if (window.location.search){
let noticeName = window.location.search.substr(1).trim() + "Notice";
let notice = browser.i18n.getMessage(noticeName);
if (notice){
let bookmarkingNotice = document.createElement("div");
bookmarkingNotice.className = noticeName + " bookmarkNotice";
bookmarkingNotice.textContent = notice;
head.appendChild(bookmarkingNotice);
} }
} });
}).then(function(tabId){
return browser.tabs.get(tabId);
}).then(function(tab){
let head = document.createElement("header");
document.body.insertBefore(head, document.body.firstChild);
document.body.appendChild(head); if (tab.url === window.location.href){
document.body.classList.add("standalone"); let heading = document.createElement("h1");
} heading.textContent = browser.i18n.getMessage("options");
head.appendChild(heading);
let introduction = document.createElement("div");
introduction.textContent = browser.i18n.getMessage("optionsIntroduction");
head.appendChild(introduction);
if (window.location.search){
let noticeName = window.location.search.substr(1).trim() + "Notice";
let notice = browser.i18n.getMessage(noticeName);
if (notice){
let bookmarkingNotice = document.createElement("div");
bookmarkingNotice.className = noticeName + " bookmarkNotice";
bookmarkingNotice.textContent = notice;
head.appendChild(bookmarkingNotice);
}
}
document.body.classList.add("standalone");
}
});
var table = document.createElement("table"); var table = document.createElement("table");
table.className = "settings " + (settings.displayDescriptions? "display": "hide") + "Descriptions"; table.className = "settings " + (settings.displayDescriptions? "display": "hide") + "Descriptions";

View File

@ -6,7 +6,8 @@ Version 0.5.3:
- display version in options page - display version in options page
fixes: fixes:
- - CSP did not work properly for worker-src
- detection if the options page was displayed in a separate tab did not work reliably
known issues: known issues:
- if a data URL is blocked the page action button does not appear - if a data URL is blocked the page action button does not appear