86-reorder-modal
Daniele Scasciafratte 6 years ago
parent 284d35be18
commit 675ec5de1b

@ -1,49 +1,49 @@
/* global browser */
var sbId, sbPrevUrl
var sbId, sbPrevUrl;
// Create the window and save the tab id
browser.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.type === 'share-backid') {
browser.windows.create(request.data).then(function (tab) {
sbId = tab.id
sbPrevUrl = request.data.url
return tab.id
})
sbId = tab.id;
sbPrevUrl = request.data.url;
return tab.id;
});
}
})
});
// Autoclose the iwndow when the url change
browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (sbId === tab.windowId) {
if (sbPrevUrl.indexOf('https://www.linkedin.com/shareArticle') >= 0 || sbPrevUrl.indexOf('https://plus.google.com/share') >= 0 || sbPrevUrl.indexOf('https://reddit.com/') >= 0) {
browser.tabs.insertCSS(tabId, {code: 'body { overflow: auto !important; }'})
browser.tabs.insertCSS(tabId, {code: 'body { overflow: auto !important; }'});
}
browser.tabs.get(tabId, function (tabinfo) {
if (sbPrevUrl !== tabinfo.url) {
var close = false
var close = false;
if (tabinfo.url.indexOf('dialog/return/close#_=_') > 0 || tabinfo.url.indexOf('latest_status_id=') > 0 || tabinfo.url === 'https://plus.google.com/') {
close = true
close = true;
}
if (close === true) {
browser.tabs.remove(tabId)
browser.tabs.remove(tabId);
}
}
})
});
}
})
});
// Add pageaction
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) {
if (typeof result.pagection === 'undefined') {
if (tab.url.indexOf('about:') !== 0 && tab.url.indexOf('moz-extension:') !== 0) {
browser.pageAction.setIcon({tabId: tab.id, path: 'icon.svg'})
browser.pageAction.setTitle({tabId: tab.id, title: 'Share'})
browser.pageAction.show(tab.id)
browser.pageAction.setIcon({tabId: tab.id, path: 'icon.svg'});
browser.pageAction.setTitle({tabId: tab.id, title: 'Share'});
browser.pageAction.show(tab.id);
browser.pageAction.setPopup({
tabId,
popup: '/modal/modal.html'
})
});
}
}
})
})
});
});

Before

Width:  |  Height:  |  Size: 379 B

After

Width:  |  Height:  |  Size: 379 B

Before

Width:  |  Height:  |  Size: 384 B

After

Width:  |  Height:  |  Size: 384 B

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before

Width:  |  Height:  |  Size: 541 B

After

Width:  |  Height:  |  Size: 541 B

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Before

Width:  |  Height:  |  Size: 656 B

After

Width:  |  Height:  |  Size: 656 B

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before

Width:  |  Height:  |  Size: 999 B

After

Width:  |  Height:  |  Size: 999 B

Before

Width:  |  Height:  |  Size: 637 B

After

Width:  |  Height:  |  Size: 637 B

Before

Width:  |  Height:  |  Size: 854 B

After

Width:  |  Height:  |  Size: 854 B

@ -1,45 +1,45 @@
/* global browser, URL */
document.addEventListener('DOMContentLoaded', () => {
const width = 700
const height = 340
const buttons = document.querySelectorAll('.share')
const width = 700;
const height = 340;
const buttons = document.querySelectorAll('.share');
var shares = 0
var shares = 0;
Array.from(buttons).forEach(function (button, index) {
// Hide the share
var item = button.getAttribute('id')
var getting = browser.storage.local.get(item)
var item = button.getAttribute('id');
var getting = browser.storage.local.get(item);
getting.then(function (result) {
if (result[Object.keys(result)[0]]) {
document.querySelector('#' + item).remove()
document.querySelector('#' + item).remove();
} else {
shares++
shares++;
// Add click event
button.addEventListener('click', function (event) {
event.preventDefault()
const url = new URL(this.dataset.share)
event.preventDefault();
const url = new URL(this.dataset.share);
browser.tabs.query({
active: true,
windowId: browser.windows.WINDOW_ID_CURRENT
},
tabs => {
if (url.searchParams.has('u')) {
url.searchParams.set('u', tabs[0].url)
url.searchParams.set('u', tabs[0].url);
} else if (url.searchParams.has('url')) {
url.searchParams.set('url', tabs[0].url)
url.searchParams.set('url', tabs[0].url);
} else if (url.searchParams.has('canonicalUrl')) {
url.searchParams.set('canonicalUrl', tabs[0].url)
url.searchParams.set('canonicalUrl', tabs[0].url);
} else if (url.searchParams.has('body')) {
url.searchParams.set('body', tabs[0].url)
url.searchParams.set('body', tabs[0].url);
}
if (url.searchParams.has('text')) {
url.searchParams.set('text', tabs[0].title)
url.searchParams.set('text', tabs[0].title);
} else if (url.searchParams.has('title')) {
url.searchParams.set('title', tabs[0].title)
url.searchParams.set('title', tabs[0].title);
} else if (url.searchParams.has('su')) {
url.searchParams.set('su', tabs[0].title)
url.searchParams.set('su', tabs[0].title);
}
browser.runtime.sendMessage({
@ -50,24 +50,24 @@ document.addEventListener('DOMContentLoaded', () => {
height,
type: 'popup'
}
})
});
}
)
}, false)
);
}, false);
}
if (index === (buttons.length - 1)) {
// Set the height of the modal
if (shares <= 4) {
document.querySelector('html').classList.add('lines-1')
document.querySelector('body').classList.add('lines-1')
document.querySelector('html').classList.add('lines-1');
document.querySelector('body').classList.add('lines-1');
} else if (shares <= 8) {
document.querySelector('html').classList.add('lines-2')
document.querySelector('body').classList.add('lines-2')
document.querySelector('html').classList.add('lines-2');
document.querySelector('body').classList.add('lines-2');
}
}
}, function (error) {
console.log(`Error: ${error}`)
})
})
})
console.log(`Error: ${error}`);
});
});
});

@ -1,7 +1,7 @@
/* global browser */
function saveOptions (e) {
e.preventDefault()
e.preventDefault();
browser.storage.local.set({
facebook: document.querySelector('#facebook').checked,
twitter: document.querySelector('#twitter').checked,
@ -13,20 +13,20 @@ function saveOptions (e) {
gmail: document.querySelector('#gmail').checked,
diaspora: document.querySelector('#diaspora').checked,
pageaction: document.querySelector('#pageaction').checked
})
});
}
function restoreOptions () {
var shares = ['facebook', 'twitter', 'google', 'linkedin', 'tumblr', 'reddit', 'telegram', 'gmail', 'diaspora', 'pageaction']
var shares = ['facebook', 'twitter', 'google', 'linkedin', 'tumblr', 'reddit', 'telegram', 'gmail', 'diaspora', 'pageaction'];
shares.forEach(function (item) {
var getting = browser.storage.local.get(item)
var getting = browser.storage.local.get(item);
getting.then(function (result) {
document.querySelector('#' + item).checked = result[Object.keys(result)[0]]
document.querySelector('#' + item).checked = result[Object.keys(result)[0]];
}, function (error) {
console.log(`Error: ${error}`)
})
})
console.log(`Error: ${error}`);
});
});
}
document.addEventListener('DOMContentLoaded', restoreOptions)
document.querySelector('form').addEventListener('submit', saveOptions)
document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelector('form').addEventListener('submit', saveOptions);

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Loading…
Cancel
Save