Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
flosommerfeld committed Oct 6, 2018
2 parents 098fe3c + 4e455e3 commit 51e5105
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 364 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Favourites [![Mozilla Add-on](https://img.shields.io/badge/Version-1.2.1-green.svg)](https://github.com/flosommerfeld/Favourites/releases/tag/v1.2.1)
# Favourites [![Mozilla Add-on](https://img.shields.io/badge/Version-1.2.2-green.svg)](https://github.com/flosommerfeld/Favourites/releases/tag/v1.2.2)

Favourites is a Mozilla Firefox WebExtension which can be used as an alternative to the common Firefox bookmarks. Favourites adds an icon to your browsers toolbar from which you can access all of your saved pages. The user can manage his favourite pages inside the WebExtensions settings page.

Expand All @@ -9,6 +9,7 @@ Favourites is a Mozilla Firefox WebExtension which can be used as an alternative
<details>
<summary>Click here to view more demo screenshots</summary>
<br>

#### Settings page

![picture alt](https://i.imgur.com/fIgy4mk.png "Settings page")
Expand Down
87 changes: 48 additions & 39 deletions background-script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/********************* Global constants *********************/
const DEFAULT_IMAGE = "img/noImage.png";
/*************************************************************/



/*
* Name of the function:
* onError
Expand All @@ -6,8 +12,8 @@
* Promise - Logs errors in case something goes wrong
*
*/
function onError(error) { //log errors
console.log("Error: ${error}");
function onError(error) {
console.log("Error: ${error}");
}


Expand All @@ -20,60 +26,63 @@ function onError(error) { //log errors
* I'll just log success/failure here.
*/
function onCreated() {
if (browser.runtime.lastError) {
console.log("Error: ${browser.runtime.lastError}");
} else {
console.log("Item created successfully");
}
if (browser.runtime.lastError) {
console.log("Error: ${browser.runtime.lastError}");
} else {
console.log("Item created successfully");
}
}







/* Create 'contextMenu' item/button */
browser.contextMenus.create({
id: "add-to-favourites",
title: "Add website to favourites",
contexts: ["all"]
id: "add-to-favourites",
title: "Add website to favourites",
contexts: ["all"]
}, onCreated);//promise


/* Eventhandler for item/button from the 'contextMenu' */
browser.contextMenus.onClicked.addListener(function(info, tab) {
switch (info.menuItemId) {
case "add-to-favourites":

/* Thanks to the 'activeTab' permission i can get more information about 'tab' (see parameter) */
switch (info.menuItemId) {
case "add-to-favourites":

/* Load the JSON object array in which all the favourites are saved */
let tabs = browser.storage.local.get("tabs");
tabs.then(function(item) {
/* Give the new favourite the data of this active tab */
let image = tab.favIconUrl;
let url = tab.url
let title = tab.title;
/* Thanks to the 'activeTab' permission i can get more information about 'tab' (see parameter) */

/* Load the JSON object array in which all the favourites are saved */
let tabs = browser.storage.local.get("tabs");
tabs.then(function(item) {
/* Give the new favourite the data of this active tab */
let image = tab.favIconUrl;
let url = tab.url;
let title = tab.title;

//TODO General function for adding new favourites which checks everything

/* If the website/active tab doesn't have a favicon then set the default image */
if (image == null) {
image = "img/noImage.png";
}
/* If the website/active tab doesn't have a favicon then set the default image */
if (image == null) {
image = DEFAULT_IMAGE;
}

/* Add the website of the active tab to the JSON object array */
item.tabs.push({
"image": image,
"url": url,
"title": title
});
/* Add the website of the active tab to the JSON object array */
item.tabs.push({
"image": image,
"url": url,
"title": title
});

/* Save alls changes that were made to the JSON object array */
browser.storage.local.set({
tabs: item.tabs
});
/* Save alls changes that were made to the JSON object array */
browser.storage.local.set({
tabs: item.tabs
});

}, onError);//promise
}, onError);//promise

break;
break;

}
}
})
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

"manifest_version": 2,
"name": "Favourites",
"version": "1.2.1",
"permissions": ["storage", "contextMenus", "activeTab"],
"version": "1.2.2",
"permissions": ["storage", "unlimitedStorage", "contextMenus", "activeTab"],

"description": "Simple alternative to Firefox's bookmarks.",
"homepage_url": "https://flosommerfeld.github.io",
Expand Down
84 changes: 44 additions & 40 deletions ui/js/functions/popup-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/
function onError(error) {
console.log("Error: ${error}");
console.log("Error: ${error}");
}


Expand All @@ -24,58 +24,62 @@ function onError(error) {
*
*/
function visualizeFavourites(item) {
var tabs = item.tabs;//JSON object array where all the favourites are saved
var tabContainer = document.getElementById("tab-container");
var tabs = item.tabs;//JSON object array where all the favourites are saved
var tabContainer = document.getElementById("tab-container");

tabContainer.innerHTML = "";
tabContainer.innerHTML = "";

console.log(tabs);

/* Check if the JSON object array was initialized */
if (tabs == undefined || tabs == null || tabs.length == 0) {
browser.storage.local.set({ //Initialize if it is currently uninitialized
tabs: []
});
/* Check if the JSON object array was initialized */
if (tabs == undefined || tabs == null || tabs.length == 0) {
browser.storage.local.set({ //Initialize if it is currently uninitialized
tabs: []
});

/* Show message: Add favourites via settings page... */
document.getElementById("no-favourites-message").style.display = "flex"; /* change from block to flex */
}
/* Show message: Add favourites via settings page... */
document.getElementById("no-favourites-message").style.display = "flex"; /* change from display none to flex */
}


/* Go through each favourite and add it to the DOM */
for (i in tabs) {
/* Go through each favourite and add it to the DOM */
for (i in tabs) {

/* Assure that the url is really a url and that the image is really an image */
if (tabs[i].url.startsWith("http") && (tabs[i].image.startsWith("data:image/jpeg;base64,") || tabs[i].image.startsWith("data:image/png;base64,") || tabs[i].image.startsWith("http") || tabs[i].image == "img/noImage.png")) {
/* Assure that the url is really a url and that the image is really an image */
if (tabs[i].url.startsWith("http") && (tabs[i].image.startsWith("data:image/jpeg;base64,")
|| tabs[i].image.startsWith("data:image/png;base64,") || tabs[i].image.startsWith("http")
|| tabs[i].image == "img/noImage.png")) {

/* Example strucure of a favourite/tab in HTML:
*
* <a href="https://www.firefox.com/" target="_blank">
* <img src="img/firefox.png">
* <div class="text">Firefox</div>
* </a>
*
*/
/*
* Example strucure of a favourite/tab in HTML:
*
* <a href="https://www.firefox.com/" target="_blank">
* <img src="img/firefox.png">
* <div class="text">Firefox</div>
* </a>
*
*/

/* Create <a> element and set the url */
let a = document.createElement("a");
a.href = tabs[i].url;
/* Create <a> element and set the url */
let a = document.createElement("a");
a.href = tabs[i].url;

/* Create <img> element and set the image */
let img = document.createElement("img");
img.src = tabs[i].image;
/* Create <img> element and set the image */
let img = document.createElement("img");
img.src = tabs[i].image;

/* Create <div> element and set the classes&innerHTML */
let div = document.createElement("div");
div.className = "text";
div.innerHTML = tabs[i].title;
/* Create <div> element and set the classes&innerHTML */
let div = document.createElement("div");
div.className = "text";
div.innerHTML = tabs[i].title;


/* Append the <img> and <div> element to the <a> element */
a.appendChild(img);
a.appendChild(div);
/* Append the <img> and <div> element to the <a> element */
a.appendChild(img);
a.appendChild(div);

/* Append the favourite/tab/<a> element to the tabContainer */
tabContainer.appendChild(a);
/* Append the favourite/tab/<a> element to the tabContainer */
tabContainer.appendChild(a);
}
}
}
}
37 changes: 19 additions & 18 deletions ui/js/functions/redirect-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,50 @@
*
*/
function onError(error) {
console.log("Error: ${error}");
console.log("Error: ${error}");
}



/*
* Name of the function:
* onOpened
* onClosed
*
* Description:
* Promise - Logs that the options page was opened
* Promise - Logs that the tab was closed
*
*/
function onOpened() {
console.log("Options page opened");
function onClosed() {
console.log("Tab successfully closed");
}



/*
* Name of the function:
* onGotTab
* onOpened
*
* Description:
* Promise - Gets the current tab ID and closes it
* Promise - Logs that the options page was opened
*
*/
function onGotTab(tabInfo) {
console.log(tabInfo);

/* Close the tab */
var removing = browser.tabs.remove(tabInfo.id);
removing.then(onClosed, onError);

function onOpened() {
console.log("Options page opened");
}


/*
* Name of the function:
* onClosed
* onGotTab
*
* Description:
* Promise - Logs that the tab was closed
* Promise - Gets the current tab ID and closes it
*
*/
function onClosed() {
console.log("Tab successfully closed");
function onGotTab(tabInfo) {
console.log(tabInfo);

/* Close the tab */
let removing = browser.tabs.remove(tabInfo.id);
removing.then(onClosed, onError);
}
Loading

0 comments on commit 51e5105

Please sign in to comment.