Skip to content

Commit

Permalink
feat: initial poc roundtrip from web extension
Browse files Browse the repository at this point in the history
to cloud function
  • Loading branch information
Andreas Sahle committed Jul 31, 2019
1 parent 7b9b3b4 commit bd3127c
Show file tree
Hide file tree
Showing 31 changed files with 8,749 additions and 250 deletions.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "poolbase-123"
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@ typings/

# DynamoDB Local files
.dynamodb/

.firebase/
20 changes: 20 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"source": "packages/functions",
"predeploy": ["npx lerna --scope functions run build"]
},
"hosting": {
"public": "packages/app/public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
13 changes: 13 additions & 0 deletions firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"indexes": [
{
"collectionGroup": "pages",
"queryScope": "COLLECTION",
"fields": [
{ "fieldPath": "url", "arrayConfig": "CONTAINS" },
{ "fieldPath": "title", "mode": "DESCENDING" }
]
}
],
"fieldOverrides": []
}
7 changes: 7 additions & 0 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
6 changes: 6 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"lerna": "3.15.0",
"packages": ["./packages/*"],
"version": "0.1.0",
"npmClient": "yarn"
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"keywords": [],
"author": "Andreas Sahle <andreas.sahle@gmail.com> (https://pixelmord.de/)",
"license": "MIT",
"dependencies": {
"devDependencies": {
"docsify": "^4.9.4",
"docsify-cli": "^4.3.0"
"docsify-cli": "^4.3.0",
"lerna": "^3.16.4"
}
}
65 changes: 65 additions & 0 deletions packages/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
12 changes: 12 additions & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "poolbase-app",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Andreas Sahle <andreas.sahle@gmail.com> (https://pixelmord.de/)",
"license": "MIT"
}
33 changes: 33 additions & 0 deletions packages/app/public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page Not Found</title>

<style media="screen">
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px 16px; border-radius: 3px; }
#message h3 { color: #888; font-weight: normal; font-size: 16px; margin: 16px 0 12px; }
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
@media (max-width: 600px) {
body, #message { margin-top: 0; background: white; box-shadow: none; }
body { border-top: 16px solid #ffa100; }
}
</style>
</head>
<body>
<div id="message">
<h2>404</h2>
<h1>Page Not Found</h1>
<p>The specified file was not found on this website. Please check the URL for mistakes and try again.</p>
<h3>Why am I seeing this?</h3>
<p>This page was generated by the Firebase Command-Line Interface. To modify it, edit the <code>404.html</code> file in your project's configured <code>public</code> directory.</p>
</div>
</body>
</html>
65 changes: 65 additions & 0 deletions packages/app/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome to Firebase Hosting</title>

<!-- update the version number as needed -->
<script defer src="/__/firebase/6.3.1/firebase-app.js"></script>
<!-- include only the Firebase features as you need -->
<script defer src="/__/firebase/6.3.1/firebase-auth.js"></script>
<script defer src="/__/firebase/6.3.1/firebase-database.js"></script>
<script defer src="/__/firebase/6.3.1/firebase-messaging.js"></script>
<script defer src="/__/firebase/6.3.1/firebase-storage.js"></script>
<!-- initialize the SDK after all desired features are loaded -->
<script defer src="/__/firebase/init.js"></script>

<style media="screen">
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px; border-radius: 3px; }
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
@media (max-width: 600px) {
body, #message { margin-top: 0; background: white; box-shadow: none; }
body { border-top: 16px solid #ffa100; }
}
</style>
</head>
<body>
<div id="message">
<h2>Welcome</h2>
<h1>Firebase Hosting Setup Complete</h1>
<p>You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary!</p>
<a target="_blank" href="https://firebase.google.com/docs/hosting/">Open Hosting Documentation</a>
</div>
<p id="load">Firebase SDK Loading&hellip;</p>

<script>
document.addEventListener('DOMContentLoaded', function() {
// // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
// // The Firebase SDK is initialized and available here!
//
// firebase.auth().onAuthStateChanged(user => { });
// firebase.database().ref('/path/to/ref').on('value', snapshot => { });
// firebase.messaging().requestPermission().then(() => { });
// firebase.storage().ref('/path/to/ref').getDownloadURL().then(() => { });
//
// // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥

try {
let app = firebase.app();
let features = ['auth', 'database', 'messaging', 'storage'].filter(feature => typeof app[feature] === 'function');
document.getElementById('load').innerHTML = `Firebase SDK loaded with ${features.join(', ')}`;
} catch (e) {
console.error(e);
document.getElementById('load').innerHTML = 'Error loading the Firebase SDK, check the console.';
}
});
</script>
</body>
</html>
4 changes: 4 additions & 0 deletions packages/browser-extension/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
yarn-debug.log
node_modules/
dist/
tmp/
3 changes: 3 additions & 0 deletions packages/browser-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Poolbase browser extension

To quickly add an url to poolbase.
Binary file added packages/browser-extension/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions packages/browser-extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"manifest_version": 2,
"name": "Save to Poolbase",
"version": "0.1.0",
"browser_action": {
"default_icon": "icon.png"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["dist/content.js"]
}
],
"background": {
"scripts": ["dist/background.js"]
},
"permissions": ["tabs"],
"homepage_url": "https://poolbase.fyi"
}
24 changes: 24 additions & 0 deletions packages/browser-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "browser-extension",
"version": "0.1.0",
"description": "Save to Poolbase browser extension",
"main": "index.js",
"scripts": {
"watch": "webpack --config webpack/webpack.dev.js --watch",
"build": "webpack --config webpack/webpack.prod.js",
"clean": "rimraf dist"
},
"keywords": [],
"author": "Andreas Sahle <andreas.sahle@gmail.com> (https://pixelmord.de/)",
"license": "MIT",
"devDependencies": {
"@types/chrome": "0.0.86",
"copy-webpack-plugin": "^5.0.4",
"rimraf": "^2.6.3",
"ts-loader": "^6.0.4",
"typescript": "~3.5.3",
"webpack": "~4.38.0",
"webpack-cli": "~3.3.6",
"webpack-merge": "~4.2.1"
}
}
6 changes: 6 additions & 0 deletions packages/browser-extension/prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
trailingComma: "es5",
tabWidth: 2,
semi: true,
singleQuote: true
};
34 changes: 34 additions & 0 deletions packages/browser-extension/src/background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
chrome.browserAction.onClicked.addListener(function(tab) {
// Send a message to the active tab
chrome.tabs.query({ active: true, currentWindow: true }, async function(
tabs
) {
const activeTab = tabs[0];
const response = await savePage(activeTab.url, activeTab.title);
console.log(response);
chrome.tabs.sendMessage(activeTab.id, {
message: 'clicked_browser_action',
});
});
});

async function savePage<T>(url: string, title: string): Promise<T> {
return fetch('https://us-central1-poolbase-123.cloudfunctions.net/savePage', {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
url,
title,
}),
}).then(response => {
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json() as Promise<T>;
});
}
5 changes: 5 additions & 0 deletions packages/browser-extension/src/content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.message === 'clicked_browser_action') {
console.log(window.location);
}
});
11 changes: 11 additions & 0 deletions packages/browser-extension/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": false,
"rootDir": "src",
"outDir": "dist/js",
"noEmitOnError": true
}
}
Loading

0 comments on commit bd3127c

Please sign in to comment.