|
|
|
@ -1,13 +1,13 @@
|
|
|
|
|
var sbId, sbPrevUrl;
|
|
|
|
|
// Create the window and save the tab id
|
|
|
|
|
browser.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
|
|
|
|
if (request.type === "share-backid") {
|
|
|
|
|
if (request.type === 'share-backid') {
|
|
|
|
|
browser.windows.create(request.data).then(function (tab) {
|
|
|
|
|
sbId = tab.id;
|
|
|
|
|
sbPrevUrl = request.data.url;
|
|
|
|
|
return tab.id;
|
|
|
|
|
});
|
|
|
|
|
} else if (request.type === "share-backid-container") {
|
|
|
|
|
} else if (request.type === 'share-backid-container') {
|
|
|
|
|
browser.tabs.create(request.data).then(function (tab) {
|
|
|
|
|
sbId = tab.id;
|
|
|
|
|
sbPrevUrl = request.data.url;
|
|
|
|
@ -20,9 +20,9 @@ browser.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
|
|
|
|
browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|
|
|
|
if (sbId === tab.windowId) {
|
|
|
|
|
const cssInjectionsFor = [
|
|
|
|
|
"https://www.linkedin.com/shareArticle",
|
|
|
|
|
"https://www.reddit.com/",
|
|
|
|
|
"shaarli",
|
|
|
|
|
'https://www.linkedin.com/shareArticle',
|
|
|
|
|
'https://www.reddit.com/',
|
|
|
|
|
'shaarli',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (sbPrevUrl !== undefined) {
|
|
|
|
@ -33,7 +33,7 @@ browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|
|
|
|
|
|
|
|
|
if (shallInjectCss) {
|
|
|
|
|
browser.tabs.insertCSS(tabId, {
|
|
|
|
|
code: "body { overflow: auto !important; }",
|
|
|
|
|
code: 'body { overflow: auto !important; }',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -43,17 +43,17 @@ browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function urlChangeStrategy(tabId, sbPrevUrl) {
|
|
|
|
|
const closeWhen = ["dialog/close_window", "latest_status_id="];
|
|
|
|
|
const closeWhen = ['dialog/close_window', 'latest_status_id='];
|
|
|
|
|
|
|
|
|
|
const closeCarefullyWhen = [
|
|
|
|
|
"reddit.com/user/.+/comments/.+/",
|
|
|
|
|
"reddit.com/r/.+/comments/.+/",
|
|
|
|
|
'reddit.com/user/.+/comments/.+/',
|
|
|
|
|
'reddit.com/r/.+/comments/.+/',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
browser.tabs.get(tabId, function (tabinfo) {
|
|
|
|
|
const modalUrl = tabinfo.url;
|
|
|
|
|
|
|
|
|
|
if (sbPrevUrl !== modalUrl && modalUrl !== "about:blank") {
|
|
|
|
|
if (sbPrevUrl !== modalUrl && modalUrl !== 'about:blank') {
|
|
|
|
|
// True if any of above parts are part of the modal URL
|
|
|
|
|
var shallClose = closeWhen.some(function (urlPart) {
|
|
|
|
|
return modalUrl.includes(urlPart);
|
|
|
|
@ -76,42 +76,42 @@ setPageActionIcon();
|
|
|
|
|
|
|
|
|
|
async function setPageActionIcon() {
|
|
|
|
|
var themeInfo = await browser.theme.getCurrent();
|
|
|
|
|
let color = "light";
|
|
|
|
|
var rgb_list = ["rgb(71, 71, 73)", "rgb(50, 50, 52)"]; // list of RGB where icon_theme should be light
|
|
|
|
|
let color = 'light';
|
|
|
|
|
var rgb_list = ['rgb(71, 71, 73)', 'rgb(50, 50, 52)']; // list of RGB where icon_theme should be light
|
|
|
|
|
if (themeInfo.colors && themeInfo.colors.toolbar_field) {
|
|
|
|
|
if (!rgb_list.includes(themeInfo.colors.toolbar_field.toString())) {
|
|
|
|
|
color = "dark";
|
|
|
|
|
color = 'dark';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setPageAction(color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setPageAction(color) {
|
|
|
|
|
var ext_icon = "icon-" + color + ".svg";
|
|
|
|
|
var ext_icon = 'icon-' + color + '.svg';
|
|
|
|
|
browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|
|
|
|
var getting = browser.storage.local.get("pageaction");
|
|
|
|
|
var getting = browser.storage.local.get('pageaction');
|
|
|
|
|
getting.then(
|
|
|
|
|
function (result) {
|
|
|
|
|
var pageaction = result.pageaction;
|
|
|
|
|
if (!pageaction) {
|
|
|
|
|
if (
|
|
|
|
|
tab.url.indexOf("about:") !== 0 &&
|
|
|
|
|
tab.url.indexOf("moz-extension:") !== 0
|
|
|
|
|
tab.url.indexOf('about:') !== 0 &&
|
|
|
|
|
tab.url.indexOf('moz-extension:') !== 0
|
|
|
|
|
) {
|
|
|
|
|
browser.pageAction.setIcon({
|
|
|
|
|
tabId: tab.id,
|
|
|
|
|
path: ext_icon,
|
|
|
|
|
path: ext_icon
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
browser.pageAction.setTitle({
|
|
|
|
|
tabId: tab.id,
|
|
|
|
|
title: "Share",
|
|
|
|
|
title: 'Share'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
browser.pageAction.show(tab.id);
|
|
|
|
|
browser.pageAction.setPopup({
|
|
|
|
|
tabId,
|
|
|
|
|
popup: "/modal/modal.html",
|
|
|
|
|
popup: '/modal/modal.html'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|