Skip to content

Commit

Permalink
✨ Added uninstall URL
Browse files Browse the repository at this point in the history
  • Loading branch information
prateek3255 committed May 10, 2020
1 parent 8aae7b8 commit 0338569
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import {
executeSaveScroll,
executeGetScroll,
executeDeleteScroll
executeDeleteScroll,
} from "./helpers.js";

function getUrlWithoutHash(url) {
return url.split("?")[0];
}

chrome.runtime.onInstalled.addListener(details => {
chrome.runtime.setUninstallURL(
"https://prateeksurana3255.typeform.com/to/VMfEV6"
);

chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === "install") {
chrome.storage.local.set({ "scroll-mark": {} });
}
});

const updateIcon = () => {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const url = getUrlWithoutHash(tabs[0].url);

chrome.storage.local.get("scroll-mark", data => {
chrome.storage.local.get("scroll-mark", (data) => {
const scrollMarkData = data["scroll-mark"];
if (!scrollMarkData.hasOwnProperty(url)) {
setInactiveIcon();
Expand All @@ -30,10 +34,10 @@ const updateIcon = () => {
};

chrome.tabs.onActivated.addListener(() => {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const url = getUrlWithoutHash(tabs[0].url);

chrome.storage.local.get("scroll-mark", data => {
chrome.storage.local.get("scroll-mark", (data) => {
const scrollMarkData = data["scroll-mark"];
if (!scrollMarkData.hasOwnProperty(url)) {
setInactiveIcon();
Expand All @@ -45,11 +49,11 @@ chrome.tabs.onActivated.addListener(() => {
});

chrome.tabs.onUpdated.addListener((tabId, updateObj) => {
chrome.tabs.get(tabId, tab => {
chrome.tabs.get(tabId, (tab) => {
const url = getUrlWithoutHash(tab.url);

if (url) {
chrome.storage.local.get("scroll-mark", data => {
chrome.storage.local.get("scroll-mark", (data) => {
const scrollMarkData = data["scroll-mark"];
if (!scrollMarkData.hasOwnProperty(url)) {
setInactiveIcon();
Expand All @@ -70,8 +74,8 @@ chrome.runtime.onMessage.addListener((request, sender) => {
}
});

chrome.commands.onCommand.addListener(function(command) {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
chrome.commands.onCommand.addListener(function (command) {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const currentTabId = tabs[0].id;
if (command === "save-or-update-scroll") {
executeSaveScroll(currentTabId);
Expand All @@ -90,8 +94,8 @@ const setActiveIcon = () => {
"32": "images/icon-32.png",
"48": "images/icon-48.png",
"128": "images/icon-128.png",
"256": "images/icon-256.png"
}
"256": "images/icon-256.png",
},
});
};

Expand All @@ -102,7 +106,7 @@ const setInactiveIcon = () => {
"32": "images/icon-32-inactive.png",
"48": "images/icon-48-inactive.png",
"128": "images/icon-128-inactive.png",
"256": "images/icon-256-inactive.png"
}
"256": "images/icon-256-inactive.png",
},
});
};

0 comments on commit 0338569

Please sign in to comment.