-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🚚 Move files to separate folders * 🔧 Added rollup setup config * ✨ Setup rollup for popup * ♻️ Migrated existing popup functionality to svelte * ⬆️ Upgrade to v3 manifest and update according to the new APIs * ✨ Udpated the CRUD methods * ♻️ Moved content scripts to separte file * ✨ Fix background script * ♻️ Simplify get scroll logic * ♻️ Updated options file for new changes * 📝 Updated readme
- Loading branch information
1 parent
a8b345c
commit 8cd9b9e
Showing
35 changed files
with
3,135 additions
and
5,760 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
webextensions: true, | ||
}, | ||
extends: ['airbnb-base', 'eslint:recommended', 'prettier'], | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
sourceType: 'module', | ||
}, | ||
rules: { | ||
'prettier/prettier': [ | ||
'error', | ||
{ | ||
arrowParens: 'avoid', | ||
printWidth: 120, | ||
singleQuote: true, | ||
tabWidth: 2, | ||
trailingComma: 'es5', | ||
endOfLine: 'auto', | ||
}, | ||
], | ||
'no-prototype-builtins': 0, | ||
}, | ||
plugins: ['prettier'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"eslint.autoFixOnSave": true, | ||
"editor.formatOnSave": true | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,112 @@ | ||
import { | ||
executeSaveScroll, | ||
executeGetScroll, | ||
executeDeleteScroll, | ||
} from "./helpers.js"; | ||
import { executeSaveScroll, executeGetScroll } from './contentScripts'; | ||
|
||
function getUrlWithoutHash(url) { | ||
return url.split("?")[0]; | ||
return url.split('?')[0]; | ||
} | ||
|
||
chrome.runtime.setUninstallURL( | ||
"https://prateeksurana3255.typeform.com/to/VMfEV6" | ||
); | ||
const setActiveIcon = () => { | ||
chrome.action.setIcon({ | ||
path: { | ||
16: '../images/icon-16.png', | ||
32: '../images/icon-32.png', | ||
48: '../images/icon-48.png', | ||
128: '../images/icon-128.png', | ||
256: '../images/icon-256.png', | ||
}, | ||
}); | ||
}; | ||
|
||
const setInactiveIcon = () => { | ||
chrome.action.setIcon({ | ||
path: { | ||
16: '../images/icon-16-inactive.png', | ||
32: '../images/icon-32-inactive.png', | ||
48: '../images/icon-48-inactive.png', | ||
128: '../images/icon-128-inactive.png', | ||
256: '../images/icon-256-inactive.png', | ||
}, | ||
}); | ||
}; | ||
|
||
chrome.runtime.onInstalled.addListener((details) => { | ||
if (details.reason === "install") { | ||
chrome.storage.local.set({ "scroll-mark": {} }); | ||
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) => { | ||
const url = getUrlWithoutHash(tabs[0].url); | ||
// const updateIcon = () => { | ||
// chrome.tabs.query({ active: true, currentWindow: true }, tabs => { | ||
// const url = getUrlWithoutHash(tabs[0].url); | ||
|
||
chrome.storage.local.get("scroll-mark", (data) => { | ||
const scrollMarkData = data["scroll-mark"]; | ||
if (!scrollMarkData.hasOwnProperty(url)) { | ||
setInactiveIcon(); | ||
} else { | ||
setActiveIcon(); | ||
} | ||
}); | ||
}); | ||
}; | ||
// chrome.storage.local.get('scroll-mark', data => { | ||
// const scrollMarkData = data['scroll-mark']; | ||
// if (!scrollMarkData.hasOwnProperty(url)) { | ||
// setInactiveIcon(); | ||
// } else { | ||
// setActiveIcon(); | ||
// } | ||
// }); | ||
// }); | ||
// }; | ||
|
||
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) => { | ||
const scrollMarkData = data["scroll-mark"]; | ||
if (!scrollMarkData.hasOwnProperty(url)) { | ||
setInactiveIcon(); | ||
} else { | ||
chrome.storage.local.get('scroll-mark', data => { | ||
const scrollMarkData = data['scroll-mark']; | ||
if (scrollMarkData && scrollMarkData[url] !== undefined) { | ||
setActiveIcon(); | ||
} else { | ||
setInactiveIcon(); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
chrome.tabs.onUpdated.addListener((tabId, updateObj) => { | ||
chrome.tabs.get(tabId, (tab) => { | ||
chrome.tabs.onUpdated.addListener(tabId => { | ||
chrome.tabs.get(tabId, tab => { | ||
const url = getUrlWithoutHash(tab.url); | ||
|
||
if (url) { | ||
chrome.storage.local.get("scroll-mark", (data) => { | ||
const scrollMarkData = data["scroll-mark"]; | ||
if (!scrollMarkData.hasOwnProperty(url)) { | ||
setInactiveIcon(); | ||
} else { | ||
executeGetScroll(tabId); | ||
chrome.storage.local.get('scroll-mark', data => { | ||
const scrollMarkData = data['scroll-mark']; | ||
if (scrollMarkData && scrollMarkData[url] !== undefined) { | ||
executeGetScroll(tabId, null, true); | ||
setActiveIcon(); | ||
} else { | ||
setInactiveIcon(); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
chrome.runtime.onMessage.addListener((request, sender) => { | ||
if (request === "setActive") { | ||
chrome.runtime.onMessage.addListener(request => { | ||
if (request === 'setActive') { | ||
setActiveIcon(); | ||
} else { | ||
setInactiveIcon(); | ||
} | ||
}); | ||
|
||
chrome.commands.onCommand.addListener(function (command) { | ||
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { | ||
chrome.commands.onCommand.addListener(command => { | ||
chrome.tabs.query({ active: true, currentWindow: true }, tabs => { | ||
const currentTabId = tabs[0].id; | ||
if (command === "save-or-update-scroll") { | ||
if (command === 'save-scroll') { | ||
executeSaveScroll(currentTabId); | ||
} else if (command === "delete-scroll") { | ||
executeDeleteScroll(currentTabId); | ||
} else if (command === "fetch-scroll") { | ||
executeGetScroll(currentTabId); | ||
} else if (command === 'fetch-scroll') { | ||
chrome.tabs.get(currentTabId, tab => { | ||
const url = getUrlWithoutHash(tab.url); | ||
chrome.storage.local.get('scroll-mark', data => { | ||
const scrollMarkData = data['scroll-mark']; | ||
if (scrollMarkData && scrollMarkData[url] !== undefined) { | ||
executeGetScroll(currentTabId, null, true); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
const setActiveIcon = () => { | ||
chrome.browserAction.setIcon({ | ||
path: { | ||
"16": "images/icon-16.png", | ||
"32": "images/icon-32.png", | ||
"48": "images/icon-48.png", | ||
"128": "images/icon-128.png", | ||
"256": "images/icon-256.png", | ||
}, | ||
}); | ||
}; | ||
|
||
const setInactiveIcon = () => { | ||
chrome.browserAction.setIcon({ | ||
path: { | ||
"16": "images/icon-16-inactive.png", | ||
"32": "images/icon-32-inactive.png", | ||
"48": "images/icon-48-inactive.png", | ||
"128": "images/icon-128-inactive.png", | ||
"256": "images/icon-256-inactive.png", | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { getURL, getItemFromStorage } from './index'; | ||
|
||
(async function () { | ||
const url = getURL(); | ||
|
||
const data = await getItemFromStorage('scroll-mark'); | ||
const scrollMarkData = data['scroll-mark']; | ||
const urlData = scrollMarkData[url]; | ||
|
||
let updatedURLData; | ||
|
||
const shouldClearAll = (await getItemFromStorage('clear-all'))['clear-all']; | ||
|
||
if (Array.isArray(urlData) && !shouldClearAll) { | ||
const currentScrollData = await getItemFromStorage('current-scroll-id'); | ||
const id = currentScrollData['current-scroll-id']; | ||
|
||
updatedURLData = urlData.filter(item => item.uuid !== id); | ||
|
||
if (updatedURLData.length === 0) { | ||
updatedURLData = undefined; | ||
} | ||
} | ||
|
||
if (scrollMarkData[url]) { | ||
const updatedData = { ...scrollMarkData, [url]: updatedURLData }; | ||
chrome.storage.local.set({ 'scroll-mark': updatedData }, () => { | ||
if (updatedURLData === undefined) { | ||
chrome.runtime.sendMessage('setInactive'); | ||
} | ||
}); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getURL, getItemFromStorage } from './index'; | ||
|
||
(async function () { | ||
const url = getURL(); | ||
const data = await getItemFromStorage('scroll-mark'); | ||
|
||
const scrollMarkData = data['scroll-mark']; | ||
let offset = null; | ||
const urlData = scrollMarkData[url]; | ||
|
||
if (typeof urlData.offset === 'number') { | ||
offset = urlData.offset; | ||
} else if (Array.isArray(urlData)) { | ||
const latestScroll = await getItemFromStorage('fetch-latest-item'); | ||
const shouldFetchLatestItem = latestScroll['fetch-latest-item']; | ||
|
||
let item = null; | ||
|
||
if (shouldFetchLatestItem) { | ||
item = urlData.reduce((prev, current) => (prev.offset > current.offset ? prev : current), { offset: 0 }); | ||
} else { | ||
const currentScrollData = await getItemFromStorage('current-scroll-id'); | ||
const id = currentScrollData['current-scroll-id']; | ||
item = urlData.find(currentItem => currentItem.uuid === id); | ||
} | ||
|
||
if (item) { | ||
offset = item.offset; | ||
} | ||
} | ||
|
||
if (offset) { | ||
window.scrollTo({ left: 0, top: offset, behavior: 'smooth' }); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export const executeScript = (tabId, file) => { | ||
chrome.scripting.executeScript({ | ||
target: { tabId }, | ||
files: [file], | ||
}); | ||
}; | ||
|
||
export const MAX_SCROLLS = 20; | ||
|
||
export const getURL = () => { | ||
const fullUrl = window.location.href; | ||
return fullUrl.split('?')[0]; | ||
}; | ||
|
||
export const getItemFromStorage = name => | ||
new Promise(resolve => { | ||
chrome.storage.local.get(name, data => { | ||
resolve(data); | ||
}); | ||
}); | ||
|
||
export const executeSaveScroll = tabId => { | ||
executeScript(tabId, 'contentScripts/save.js'); | ||
}; | ||
|
||
export const executeDeleteScroll = (tabId, scrollId, clearAll = false) => { | ||
chrome.storage.local.set({ 'current-scroll-id': scrollId, 'clear-all': clearAll }); | ||
executeScript(tabId, 'contentScripts/delete.js'); | ||
}; | ||
|
||
export const executeGetScroll = (tabId, scrollId, fetchLatestItem = false) => { | ||
chrome.storage.local.set({ 'current-scroll-id': scrollId, 'fetch-latest-item': fetchLatestItem }); | ||
executeScript(tabId, 'contentScripts/get.js'); | ||
}; | ||
|
||
export const executeUpdateScroll = (tabId, scrollId) => { | ||
chrome.storage.local.set({ 'current-scroll-id': scrollId }); | ||
executeScript(tabId, 'contentScripts/update.js'); | ||
}; |
Oops, something went wrong.