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

Syncing across devices with Github Gists #117

Merged
merged 84 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
053b0a5
include gist management
vict0rsch Aug 19, 2022
cbda9d6
PAT input functional
vict0rsch Aug 19, 2022
93861ba
add `sync.js`
vict0rsch Aug 19, 2022
9187249
write papers to gist
vict0rsch Aug 20, 2022
7736d34
working pull from new PM instance
vict0rsch Aug 20, 2022
54252df
typo stop gh sync
vict0rsch Aug 20, 2022
f710b78
functional bidirectional sync
vict0rsch Aug 23, 2022
b143767
update sync help
vict0rsch Aug 23, 2022
3813bdc
add options floating title sidebar
vict0rsch Aug 24, 2022
0403a17
adjust responsiveness
vict0rsch Aug 24, 2022
ec107a0
improve sync title
vict0rsch Aug 24, 2022
8ca91d6
faster paper sorting
vict0rsch Aug 24, 2022
7af2397
add sync loader UIs & fix paper deletion
vict0rsch Aug 24, 2022
7af4db3
missing loader removal
vict0rsch Aug 24, 2022
c10e35e
downgrade to original puppeteer
vict0rsch Aug 25, 2022
02016e3
v0 working testing skeleton
vict0rsch Aug 25, 2022
e10e3a0
towards testing deletions
vict0rsch Aug 26, 2022
897d251
`pullFromRemote` writes to local storage
vict0rsch Aug 29, 2022
bf140a9
improve pull/push logs
vict0rsch Aug 29, 2022
66f8229
`?noRefresh=true` for full memory page
vict0rsch Aug 29, 2022
9e7f9cb
refactor to `initGist` & `restartGist`
vict0rsch Aug 30, 2022
2b6e841
`String.fromCodePoint` for emoji
vict0rsch Aug 30, 2022
200adfa
check for `Boolean(papers)` not just `type === undefined`
vict0rsch Aug 30, 2022
74a12f4
time pull from remote
vict0rsch Aug 30, 2022
64aafab
handle test data file
vict0rsch Aug 30, 2022
7719c12
`initSyncAndState` handles promises and uses default params destructu…
vict0rsch Aug 30, 2022
53198d7
return result from `pushToRemote`
vict0rsch Aug 30, 2022
8033399
`contentScriptMain` and `addOrUpdatePaper` refactoreed to default par…
vict0rsch Aug 30, 2022
839d1cb
`getDataFile` is async
vict0rsch Aug 30, 2022
86453b3
push to remote after paper imports
vict0rsch Aug 30, 2022
5f5a588
group `pushToRemote` console logs
vict0rsch Aug 30, 2022
8713fe0
add sync feedbacks
vict0rsch Aug 30, 2022
2e6d8de
fix `deletePaperInStorage` that would not wait
vict0rsch Aug 30, 2022
49f3a50
`getMemoryState` -> `getPaperMemoryState`
vict0rsch Aug 30, 2022
e7c05b8
no auto refresh if GET parameter `?noRefresh=true`
vict0rsch Aug 30, 2022
b97ffc7
`syncOnBlur`
vict0rsch Aug 30, 2022
43431e2
`delay` as `function` not `()=>{}`
vict0rsch Aug 30, 2022
6b7b53b
add urls
vict0rsch Aug 30, 2022
d0de047
Initial mini memory
vict0rsch Aug 30, 2022
e43aad8
passing tests for additions and deletions
vict0rsch Aug 30, 2022
e53933a
build
vict0rsch Aug 30, 2022
4f16179
update test scripts
vict0rsch Aug 30, 2022
4030266
smaller console group titles
vict0rsch Aug 30, 2022
70a070c
typo passing `contentScriptCallbacks` arg
vict0rsch Aug 30, 2022
469f910
switch download button / text order
vict0rsch Aug 30, 2022
fd80ca8
add margin-top to button
vict0rsch Aug 30, 2022
4528397
faster time-to-display on Arxiv
vict0rsch Aug 30, 2022
fe79e0a
build
vict0rsch Aug 30, 2022
bcf1b68
no arxiv display on pdfs
vict0rsch Aug 30, 2022
b497478
update console header style
vict0rsch Aug 30, 2022
4257823
reorder preprint matchings
vict0rsch Aug 30, 2022
c7050c4
build
vict0rsch Aug 30, 2022
69819f0
fix: missing `remoteIsReady()` call if not `shouldSync`
vict0rsch Aug 30, 2022
38e0075
v0 add `Inspire HEP` paper source
vict0rsch Aug 30, 2022
237ea78
fix: missing `remoteIsReady()` call if not `shouldSync`
vict0rsch Aug 30, 2022
0efe787
build
vict0rsch Aug 30, 2022
2bc178d
remove Puppeteer style adjustment
vict0rsch Aug 30, 2022
870ab46
typo in `ihep`'s `parseIdFromUrl`
vict0rsch Aug 30, 2022
676c64d
adjust titles surrounded by `{}`
vict0rsch Aug 30, 2022
edbed4f
add tests
vict0rsch Aug 30, 2022
d54704b
build
vict0rsch Aug 30, 2022
b0aa91f
Merge branch 'gist-storage' into inspire-hep
vict0rsch Aug 30, 2022
dd9fff5
Merge pull request #120 from vict0rsch/inspire-hep
vict0rsch Aug 30, 2022
3b37559
post-merge build
vict0rsch Aug 30, 2022
534d3d7
typo in `paperToAbs`
vict0rsch Aug 30, 2022
4651359
parse IHEP from pdfs
vict0rsch Aug 31, 2022
497a539
shorten sync time & improve background logs
vict0rsch Aug 31, 2022
45d19bb
replace most `Array.from(x)` by `[...x]`
vict0rsch Aug 31, 2022
df4328c
`1000` to `1e3`
vict0rsch Aug 31, 2022
80f9cec
implement merge and improve sync UI (modals)
vict0rsch Aug 31, 2022
6028fc5
allow PAT deletion and fix loaders
vict0rsch Aug 31, 2022
7c5016c
add message about remote paper deletion in "no paper" possibilities
vict0rsch Aug 31, 2022
059e6f1
update popup UI if paper gets deleted after Pull
vict0rsch Aug 31, 2022
ec01943
`initState` uses default params destructuring
vict0rsch Aug 31, 2022
b4fca30
add 5-10 seconds guideline
vict0rsch Aug 31, 2022
f075fe0
disable body scrolling on modal open
vict0rsch Aug 31, 2022
f1e5f30
add badge text for sync state
vict0rsch Aug 31, 2022
d933fb3
build
vict0rsch Aug 31, 2022
a389783
no `makeMemoryHTML` on options page
vict0rsch Aug 31, 2022
ac4c84d
add online sync
vict0rsch Aug 31, 2022
b8cbe34
build
vict0rsch Aug 31, 2022
7d456fb
use `<summary>` to display a list of all tags if searc query starts w…
vict0rsch Sep 1, 2022
2f554b5
Merge pull request #121 from vict0rsch/tags-list
vict0rsch Sep 27, 2022
1d3314f
Merge branch 'master' into gist-storage
vict0rsch Sep 27, 2022
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
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ In the extension's `options` (right click on the icon or in the popup's menu) yo
* **Source filtering**: filter out some paper sources you don't want to record papers from
* **Custom title function**: provide Javascript code to generate your own web page titles and pdf filenames based on a paper's attributes
* **Data management**: export/load your memory data and export the bibliography as a `.bib` file
* **Online Synchronization**: use Github Gists to sync your papers across devices

<p align="center">
<img src="https://raw.github.com/vict0rsch/PaperMemory/master/extra/imgs/opt_concat.png?raw=true">
Expand Down
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function utilsJS() {
"src/shared/js/utils/levenshtein.js",
"src/shared/js/utils/bibtexParser.js",
"src/shared/js/utils/functions.js",
"src/shared/js/utils/gist.js",
"src/shared/js/utils/sync.js",
"src/shared/js/utils/data.js",
"src/shared/js/utils/paper.js",
"src/shared/js/utils/state.js",
Expand Down
2 changes: 2 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
"src/shared/js/utils/miniquery.js",
"src/shared/js/utils/config.js",
"src/shared/js/utils/functions.js",
"src/shared/js/utils/gist.js",
"src/shared/js/utils/sync.js",
"src/shared/js/utils/data.js",
"src/shared/js/utils/paper.js",
"src/shared/js/utils/state.js",
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"test-cov": "gulp build && cd test/ && ../node_modules/.bin/nyc --reporter=text ../node_modules/.bin/mocha test-*.js",
"test-storage": "gulp build && cd test/ && ../node_modules/.bin/mocha test-storage.js",
"test-duplicates": "gulp build && cd test/ && ../node_modules/.bin/mocha test-duplicates.js",
"test-no-browser": "gulp build && cd test/ && ../node_modules/.bin/mocha 'test-!(storage|duplicates)*.js'",
"test-no-browser-no-build": "cd test/ && ../node_modules/.bin/mocha 'test-!(storage)*.js'",
"test-no-browser-no-build-cov": "cd test/ && ../node_modules/.bin/nyc --reporter=text ../node_modules/.bin/mocha 'test-!(storage)*.js'",
"test-sync": "gulp build && cd test/ && ../node_modules/.bin/mocha test-sync.js",
"test-no-browser": "gulp build && cd test/ && ../node_modules/.bin/mocha 'test-!(storage|duplicates|sync)*.js'",
"test-no-browser-no-build": "cd test/ && ../node_modules/.bin/mocha 'test-!(storage|duplicates|sync)*.js'",
"test-no-browser-no-build-cov": "cd test/ && ../node_modules/.bin/nyc --reporter=text ../node_modules/.bin/mocha 'test-!(storage|duplicates|sync)*.js'",
"screenshots": "node_modules/.bin/mocha test/screenshots.js"
},
"repository": {
Expand Down Expand Up @@ -41,11 +42,12 @@
"jsdom": "^20.0.0",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"puppeteer": "^13.5.2",
"puppeteer-to-istanbul": "^1.4.0",
"readline-sync": "^1.4.10",
"uuid": "^9.0.0"
},
"dependencies": {
"puppeteer": "^18.0.2"
"ora": "5.4.1"
}
}
}
113 changes: 113 additions & 0 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,56 @@ var paperTitles = {};
var MAX_TITLE_UPDATES = 100;
var tabStatuses = {};

const badgeOk = () => {
chrome.browserAction.setBadgeText({ text: "OK!" });
chrome.browserAction.setBadgeBackgroundColor({ color: "rgb(68, 164, 68)" });
};

const badgeWait = (text) => {
chrome.browserAction.setBadgeText({ text });
chrome.browserAction.setBadgeBackgroundColor({ color: "rgb(189, 127, 10)" });
};

const badgeError = () => {
chrome.browserAction.setBadgeText({ text: "Error" });
chrome.browserAction.setBadgeBackgroundColor({ color: "rgb(195, 40, 56)" });
};

const badgeClear = (preventTimeout = false) => {
if (preventTimeout) {
chrome.browserAction.setBadgeText({ text: "" });
} else {
setTimeout(() => {
chrome.browserAction.setBadgeText({ text: "" });
}, 2000);
}
};

const initGist = async () => {
if (!(await shouldSync())) {
warn("Sync disabled.");
return;
}
const start = Date.now();
log("Initializing Sync...");
badgeWait("Init...");
const { ok, error, payload } = await getGist();
if (ok) {
global.state.gist = payload.gist;
global.state.gistDataFile = await getDataFile(global.state.gist);
await global.state.gistDataFile.fetchLatest();
const duration = (Date.now() - start) / 1e3;
logOk(`Sync successfully enabled (${duration}s).`);
badgeOk();
} else {
logError("[initGist]", error);
badgeError();
}
badgeClear();
};

initGist();

const setFaviconCode = `
var link;
if (window.location.href.startsWith("file://")){
Expand Down Expand Up @@ -163,6 +213,53 @@ const findCodesForPaper = async (request) => {
return { ...codes[0], ...code };
};

const pullSyncPapers = async () => {
if (!(await shouldSync())) return;
try {
badgeWait("Pull...");
const start = Date.now();
consoleHeader(`Pulling ${String.fromCodePoint("0x23EC")}`);
log("Pulling from Github...");
await global.state.gistDataFile.fetchLatest();
const remotePapers = global.state.gistDataFile.content;
log("Pulled papers:", remotePapers);
const duration = (Date.now() - start) / 1e3;
info(`Pulling from Github... Done (${duration}s)!`);
console.groupEnd();
badgeOk();
badgeClear();
return remotePapers;
} catch (e) {
logError("[pullSyncPapers]", e);
badgeError();
}
badgeClear();
console.groupEnd();
};

const pushSyncPapers = async () => {
if (!(await shouldSync())) return;
try {
const start = Date.now();
consoleHeader(`Pushing ${String.fromCodePoint("0x23EB")}`);
log("Writing to Github...");
badgeWait("Push...");
chrome.browserAction.setBadgeBackgroundColor({ color: "rgb(189, 127, 10)" });
const papers = (await getStorage("papers")) ?? {};
log("Papers to write: ", papers);
await global.state.gistDataFile.overwrite(JSON.stringify(papers, null, ""));
await global.state.gistDataFile.save();
const duration = (Date.now() - start) / 1e3;
log(`Writing to Github... Done (${duration}s)!`);
badgeOk();
} catch (e) {
logError("[pushSyncPapers]", e);
badgeError();
}
badgeClear();
console.groupEnd();
};

chrome.runtime.onMessage.addListener((payload, sender, sendResponse) => {
if (payload.type === "update-title") {
const { title, url } = payload.options;
Expand Down Expand Up @@ -190,6 +287,12 @@ chrome.runtime.onMessage.addListener((payload, sender, sendResponse) => {
});
} else if (payload.type === "hello") {
sendResponse("Connection to background script established.");
} else if (payload.type === "writeSync") {
pushSyncPapers().then(sendResponse);
} else if (payload.type === "pullSync") {
pullSyncPapers(payload.gist).then(sendResponse);
} else if (payload.type === "restartGist") {
initGist().then(sendResponse);
}
return true;
});
Expand Down Expand Up @@ -260,3 +363,13 @@ chrome.commands.onCommand.addListener((command) => {
});
}
});

chrome.runtime.onConnect.addListener(function (port) {
if (port.name === "PaperMemoryPopupSync") {
log("[chrome.runtime.onConnect] Popup connected.");
port.onDisconnect.addListener(async function () {
log("[chrome.runtime.onConnect] Popup disconnected.");
await pushSyncPapers();
});
}
});
1 change: 1 addition & 0 deletions src/content_scripts/content_script.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
justify-content: center;
align-items: center;
justify-content: space-between;
margin-top: 24px;
}

.pm-sub-header {
Expand Down
Loading