Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
fixes
added sidebar send current link
  • Loading branch information
ueen authored Jul 9, 2022
1 parent 0b91d17 commit a7f962f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
45 changes: 40 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,39 @@ const popupModes = {
let popupMode;

browser.storage.sync.get({SdAmode:"", Backg:false, Servr:"https://snapdrop.net"}).then(function (result) {
sdURL = result.Servr;

popupMode = result.SdAmode;
switch (result.SdAmode) {
case popupModes.Sidebar:
popupListener();
sidebarInit();
case popupModes.Winpop:
case popupModes.Tab:
browser.browserAction.onClicked.addListener(browserActionClick);
break;
default: //classic popup
browser.browserAction.setPopup({popup: 'popup/popup.html'});
popupListener();
break;
}

sdURL = result.Servr;

if (result.Backg) {
snapdrop = new Snapdrop(sdURL.split("//")[1]);
browser.tabs.onUpdated.addListener(handleUpdated);
browser.tabs.onRemoved.addListener(handleRemoved);
}
});

browser.browserAction.onClicked.addListener(browserActionClick);
browser.runtime.onMessage.addListener(_ => {
browser.runtime.reload();
browser.runtime.onMessage.addListener(action => {
switch (action) {
case "reload":
browser.runtime.reload();
break;
case "sidebarClick":
sidebarListener();
break;
}
});

function popupListener() {
Expand All @@ -45,6 +55,31 @@ function popupListener() {
});
}

function sidebarListener() {
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message === "sidebarClick") {
browser.tabs.query({active: true}).then(tabs => {
sendResponse(tabs[0].url);
});
}
return true;
});
}

function sidebarInit() {
try {
browser.contentScripts.register({
matches: [sdURL+'/*'],
js: [{file: "browser-polyfill.js"}, {file: "popup/sidebar.js"}],
allFrames : true,
runAt: "document_idle"
});
} catch (error) {
console.log(error);
}
}


function browserActionClick() { //only if not 'classic' Popup Mode
if (popupMode == popupModes.Sidebar) {
browser.sidebarAction.open(); //requieres direct user input handle
Expand Down
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"homepage_url": "https://github.com/ueen/SnapdropFirefoxAddon",
"manifest_version": 2,
"name": "Snapdrop Browser Extension",
"version": "1.9.5",
"version": "1.9.6",
"options_ui": {
"page": "options/options.html"
},
Expand All @@ -21,7 +21,8 @@
"clipboardWrite",
"downloads",
"storage",
"tabs"
"tabs",
"<all_urls>"

This comment has been minimized.

Copy link
@mkbosmans

mkbosmans Aug 6, 2022

This is not a permission that I would expect an extension like snapdrop to need.
Could this perhaps be made optional?

This comment has been minimized.

Copy link
@ueen

ueen Aug 7, 2022

Author Owner

It is necessary, because it needs to check whether snapdrop is already opened in another tab so not to open it twice. Also it needs to open and interact with iframes of whatever snapdrop provider/url is entered in the settings.
These are sensible features and as it's open source you can exactly see what it's doing, hope this helps :)

],
"browser_specific_settings": {
"gecko": {
Expand Down
2 changes: 1 addition & 1 deletion options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function saveOptions() {
document.querySelector("#saveStateOut").textContent = "saved";
document.querySelector("#saveStateOut").style.opacity = 0;
document.querySelector("#saveStateOut").addEventListener('transitionend', () => {
browser.runtime.sendMessage({action: "reload"});
browser.runtime.sendMessage("reload");
//for chromes floating options
if (window.chrome) {
window.close();
Expand Down
2 changes: 1 addition & 1 deletion popup/popup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
browser.storage.sync.get({Servr:"snapdrop.net"}).then(function (result) {
browser.storage.sync.get({Servr:"https://snapdrop.net"}).then(function (result) {
browser.tabs.query({}).then( tabs => {
let sdTabs = tabs.filter(tab => tab.url.includes(result.Servr.split("//")[1]));
if (sdTabs.length <= 0) {
Expand Down
8 changes: 8 additions & 0 deletions popup/sidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//get active tab url for sending via textInput
document.addEventListener("contextmenu", (ev) => {
browser.runtime.sendMessage("sidebarClick").then(response => {
if (response != undefined) {
document.getElementById("textInput").innerHTML = response;
}
});
});

1 comment on commit a7f962f

@fm-sys
Copy link

@fm-sys fm-sys commented on a7f962f Jul 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool feature, thanks for it!

Please sign in to comment.