Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated popup.js #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/chrome/popup/popup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/edge/popup/popup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/firefox/popup/popup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/safari/dissenter.safariextension/popup/popup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 31 additions & 13 deletions src/scripts/components/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,26 @@ var Popup = function() {
var activeWindow = safari.application.activeBrowserWindow;
var activeTab = activeWindow.activeTab;

if (!isObject(activeTab)) activeTab = {};

var title = activeTab.title || '';
var url = activeTab.url || '';

//
onPopupOpen(title, url);
var _loadPopup = function(e) {
var title = e.target.title || '';
var url = e.target.url || '';

if (url) {
onPopupOpen(title, url);
}
};

activeWindow.addEventListener('activate', function(e) {
if (e.target.hasOwnProperty('url')) {
_loadPopup(e);

e.target.addEventListener('navigate', function(e) {
if (e.target.hasOwnProperty('url')) {
_loadPopup(e);
}
});
}
}, true);
}
else {
//On popup open, get current tab
Expand All @@ -69,12 +82,17 @@ var Popup = function() {
//Get active tab
var activeTab = tabs[0] || {};

//Get title, url
var title = activeTab.title || '';
var url = activeTab.url || '';

//
onPopupOpen(title, url);
// check if a canonical url is defined before using the tab url
__BROWSER__.tabs.executeScript({
code: "try { document.querySelector('link[rel=\"canonical\"]').href; } catch(e) {}"
}, function(result) {
//Get title, url
var title = activeTab.title || '';
var url = result[0] || activeTab.url || '';

//
onPopupOpen(title, url);
});
});
}
}
Expand Down