Compare commits
7 Commits
0.0.2.2
...
feature/ex
Author | SHA1 | Date | |
---|---|---|---|
fad8af07a7 | |||
b571af29c5 | |||
c5cadb1557 | |||
45cf59be52 | |||
19aa864579 | |||
8723154371 | |||
25fe0c5849 |
121
README.md
121
README.md
@@ -1,28 +1,61 @@
|
||||
<div align="center">
|
||||
<h1>
|
||||
Extension Boilerplate
|
||||
</h1>
|
||||
# ReadLater WebExtension 
|
||||
|
||||
<p>
|
||||
<strong>A foundation for creating browser extensions for Chrome, Opera & Firefox.</strong>
|
||||
</p>
|
||||
</div>
|
||||
> ReadLaterByEmail webextension generator
|
||||
|
||||
Now that Firefox supports WebExtensions, it has become a lot easier to build browser extensions/addons for multiple browsers without duplicating the codebase. This project serves as a sensible starting point to help you get started.
|
||||
## :books: Table of Contents
|
||||
|
||||
<div align="center">
|
||||
<a href="https://www.emailthis.me/open-source/extension-boilerplate">
|
||||
<img src="./resources/chrome-promo/large.png" alt="Extension Boilerplate">
|
||||
</a>
|
||||
</div>
|
||||
- [Installation](#package-installation)
|
||||
- [Usage](#rocket-usage)
|
||||
- [Features](#sparkles-features)
|
||||
- [Support](#hammer_and_wrench-support)
|
||||
- [Contributing](#memo-contributing)
|
||||
- [License](#scroll-license)
|
||||
|
||||
I have extracted this from the browser extensions that I built for my side-project, [Email This](https://www.emailthis.me).
|
||||
## :package: Installation
|
||||
|
||||
> Side note: Do check out [**Email This**](https://www.emailthis.me). It is a simpler alternative to bookmarking tools like Pocket, Readability & Instapaper. Email This will remove ads & distractions from an article and send you a nice email with just the text/images. No need to install any additional applications or login to another app just to access your bookmarks.
|
||||
The Chrome Extensions is available [on the Chrome Web Store](https://chrome.google.com/webstore/detail/email-this/lgblkllcjgihfnlefhnnpppndbbjallh).
|
||||
### First check if you have composer installed
|
||||
|
||||
Before installing this, you need to check if you have `NPM` installed on your computer.
|
||||
|
||||
## Features
|
||||
### Then install this script
|
||||
|
||||
```sh
|
||||
git clone ssh://gogs@git.shikiryu.com:2200/ReadLaterByEmail/webextensions.git
|
||||
cd webextensions
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
## :rocket: Usage
|
||||
|
||||
### Load the extension in Chrome & Opera
|
||||
|
||||
1. Open Chrome/Opera browser and navigate to chrome://extensions
|
||||
2. Select "Developer Mode" and then click "Load unpacked extension..."
|
||||
3. From the file browser, choose to `extension-boilerplate/build/chrome` or (`extension-boilerplate/build/opera`)
|
||||
|
||||
### Load the extension in Firefox
|
||||
|
||||
1. Open Firefox browser and navigate to about:debugging
|
||||
2. Click "Load Temporary Add-on" and from the file browser, choose `extension-boilerplate/build/firefox`
|
||||
|
||||
### Developing
|
||||
|
||||
The following tasks can be used when you want to start developing the extension and want to enable live reload -
|
||||
|
||||
- `npm run chrome-watch`
|
||||
- `npm run opera-watch`
|
||||
- `npm run firefox-watch`
|
||||
|
||||
### Packaging
|
||||
|
||||
Run `npm run dist` to create a zipped, production-ready extension for each browser. You can then upload that to the appstore.
|
||||
|
||||
Run `npm run sourcezip` for firefox submission
|
||||
|
||||
Update <https://addons.mozilla.org/fr/developers/addon/shikiryu-readlater/versions/submit/>
|
||||
|
||||
## :sparkles: Features
|
||||
|
||||
<dl>
|
||||
<dt>Write once and deploy to Chrome, Opera & Firefox</dt>
|
||||
@@ -67,56 +100,20 @@ The Chrome Extensions is available [on the Chrome Web Store](https://chrome.goog
|
||||
You might need to specify different data variables based on your environment. For example, you might want to use a localhost API endpoint during development and a production API endpoint once the extension is submitted to the appstore. You can specify such data in the json files inside `config` directory.
|
||||
|
||||
You can also set custom data variables based on the platform (different variable for Chrome, FF, Opera).
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
## :hammer_and_wrench: Support
|
||||
|
||||
Please [open an issue](https://git.shikiryu.com/ReadLaterByEmail/webextensions/issues/new) for support.
|
||||
|
||||
## Installation
|
||||
1. Clone the repository `git clone https://github.com/EmailThis/extension-boilerplate.git`
|
||||
2. Run `npm install`
|
||||
3. Run `npm run build`
|
||||
## :memo: Contributing
|
||||
|
||||
Alternately, if you want to try out the sample extension, here are the download links. After you download it, unzip the file and load it in your browser using the steps mentioned below.
|
||||
- [**Download Chrome Extension**](https://github.com/EmailThis/extension-boilerplate/releases/download/v1.0/chrome.zip)
|
||||
- [**Download Opera Extension**](https://github.com/EmailThis/extension-boilerplate/releases/download/v1.0/opera.zip)
|
||||
- [**Download Firefox Extension**](https://github.com/EmailThis/extension-boilerplate/releases/download/v1.0/firefox.zip)
|
||||
Please contribute using [Github Flow](https://guides.github.com/introduction/flow/). Create a branch, add commits, and [open a pull request](https://git.shikiryu.com/ReadLaterByEmail/webextensions/compare/master...master).
|
||||
|
||||
## :scroll: License
|
||||
|
||||
##### Load the extension in Chrome & Opera
|
||||
1. Open Chrome/Opera browser and navigate to chrome://extensions
|
||||
2. Select "Developer Mode" and then click "Load unpacked extension..."
|
||||
3. From the file browser, choose to `extension-boilerplate/build/chrome` or (`extension-boilerplate/build/opera`)
|
||||
[Creative Commons Attribution NonCommercial (CC-BY-NC)](<https://tldrlegal.com/license/creative-commons-attribution-noncommercial-(cc-nc)>) © [Chouchen](https://github.com/Chouchen/)
|
||||
|
||||
|
||||
##### Load the extension in Firefox
|
||||
1. Open Firefox browser and navigate to about:debugging
|
||||
2. Click "Load Temporary Add-on" and from the file browser, choose `extension-boilerplate/build/firefox`
|
||||
|
||||
|
||||
## Developing
|
||||
The following tasks can be used when you want to start developing the extension and want to enable live reload -
|
||||
|
||||
- `npm run chrome-watch`
|
||||
- `npm run opera-watch`
|
||||
- `npm run firefox-watch`
|
||||
|
||||
|
||||
## Packaging
|
||||
Run `npm run dist` to create a zipped, production-ready extension for each browser. You can then upload that to the appstore.
|
||||
|
||||
|
||||
## TODO
|
||||
- [ ] Add support for Safari
|
||||
- [x] Add Firefox & Opera Promo images
|
||||
- [x] Add sample screenshot templates
|
||||
- [ ] Write a guide for using config variables & JS preprocessor
|
||||
|
||||
|
||||
-----------
|
||||
This project is licensed under the MIT license.
|
||||
|
||||
If you have any questions or comments, please create a new issue. I'd be happy to hear your thoughts.
|
||||
|
||||
|
||||
Bharani, [Email This](https://www.emailthis.me)
|
||||
Based on [Email This](https://www.emailthis.me) which is licensed under the MIT license.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Shikiryu Read Later",
|
||||
"version": "0.0.2.1",
|
||||
"version": "0.0.3",
|
||||
"manifest_version": 2,
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"icons": {
|
||||
@@ -9,28 +9,18 @@
|
||||
},
|
||||
"default_locale": "en",
|
||||
"background": {
|
||||
"scripts": [
|
||||
"scripts/background.js"
|
||||
]
|
||||
"scripts": ["scripts/background.js"]
|
||||
},
|
||||
"permissions": [
|
||||
"activeTab",
|
||||
"storage"
|
||||
],
|
||||
"permissions": ["activeTab", "storage", "contextMenus"],
|
||||
"options_ui": {
|
||||
"page": "options.html"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": [
|
||||
"http://*/*",
|
||||
"https://*/*"
|
||||
],
|
||||
"js": [
|
||||
"scripts/contentscript.js"
|
||||
],
|
||||
"matches": ["http://*/*", "https://*/*"],
|
||||
"js": ["scripts/contentscript.js"],
|
||||
"run_at": "document_end",
|
||||
"all_frames": false
|
||||
"all_frames": true
|
||||
}
|
||||
],
|
||||
"browser_action": {
|
||||
@@ -44,7 +34,7 @@
|
||||
},
|
||||
"applications": {
|
||||
"gecko": {
|
||||
"id": "bookmarklet@shikiryu.com"
|
||||
"id": "bookmarklet@shikiryu.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -47,8 +47,16 @@
|
||||
"gulp-sourcemaps": "^1.6.0",
|
||||
"gulp-uglify": "^1.5.4",
|
||||
"gulp-zip": "^2.0.3",
|
||||
"husky": "^2.2.0",
|
||||
"preprocessify": "^1.0.1",
|
||||
"prettier": "^1.17.0",
|
||||
"pretty-quick": "^1.10.0",
|
||||
"vinyl-buffer": "^1.0.0",
|
||||
"vinyl-source-stream": "^1.1.0"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "pretty-quick --staged"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -23,6 +23,10 @@
|
||||
"message": "Token:",
|
||||
"description": "Token label"
|
||||
},
|
||||
"optionsExtract": {
|
||||
"message": "Send page content into the email:",
|
||||
"description": "Extract label"
|
||||
},
|
||||
"URLChanged": {
|
||||
"message": "URL changed!",
|
||||
"description": "Message when URL is changed."
|
||||
@@ -31,6 +35,10 @@
|
||||
"message": "Token saved!",
|
||||
"description": "Message when token is changed."
|
||||
},
|
||||
"optionSaved": {
|
||||
"message": "Option saved!",
|
||||
"description": "Message when option is changed."
|
||||
},
|
||||
"cantExtractTitle": {
|
||||
"message": "Sorry, could not extract this page's title and URL",
|
||||
"description": "Message when we could not extract the page's title and URL"
|
||||
@@ -46,5 +54,13 @@
|
||||
"defaultURL": {
|
||||
"message": "https://app.readlater.shikiryu.com",
|
||||
"description": "Default URL"
|
||||
},
|
||||
"excerpt": {
|
||||
"message": "Add content",
|
||||
"description": "Option to add the webpage content into the email"
|
||||
},
|
||||
"selectDomToSend": {
|
||||
"message": "Select DOM To Send",
|
||||
"description": "Select DOM To Send"
|
||||
}
|
||||
}
|
||||
|
@@ -23,14 +23,22 @@
|
||||
"message": "Jeton :",
|
||||
"description": "Token label"
|
||||
},
|
||||
"optionsExtract": {
|
||||
"message": "Envoyer le contenu de la page dans le mail:",
|
||||
"description": "Extract label"
|
||||
},
|
||||
"URLChanged": {
|
||||
"message": "URL changed!",
|
||||
"message": "URL enregistrée !",
|
||||
"description": "Message when URL is changed."
|
||||
},
|
||||
"tokenSaved": {
|
||||
"message": "Token saved!",
|
||||
"message": "Jeton enregistré !",
|
||||
"description": "Message when token is changed."
|
||||
},
|
||||
"optionSaved": {
|
||||
"message": "Option enregistrée !",
|
||||
"description": "Message when option is changed."
|
||||
},
|
||||
"cantExtractTitle": {
|
||||
"message": "Sorry, could not extract this page's title and URL",
|
||||
"description": "Message when we could not extract the page's title and URL"
|
||||
@@ -46,5 +54,13 @@
|
||||
"defaultURL": {
|
||||
"message": "https://app.readlater.shikiryu.com",
|
||||
"description": "Default URL"
|
||||
},
|
||||
"excerpt": {
|
||||
"message": "Ajouter le contenu",
|
||||
"description": "Option to add the webpage content into the email"
|
||||
},
|
||||
"selectDomToSend": {
|
||||
"message": "Partie à envoyer par email",
|
||||
"description": "Select DOM To Send"
|
||||
}
|
||||
}
|
||||
|
@@ -1,57 +1,63 @@
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link href="styles/options.css" rel="stylesheet">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title data-message="optionsAndSettings"></title>
|
||||
</head>
|
||||
<body class="wrap">
|
||||
<div class="grid">
|
||||
<div class="unit whole center-on-mobiles">
|
||||
<div class="heading">
|
||||
<h1 data-message="extensionName"></h1>
|
||||
<p class="lead" data-message="optionsPageSubtitle"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section>
|
||||
<div class="grid">
|
||||
<div class="unit whole center-on-mobiles">
|
||||
<div id="msg"></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="content">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link href="styles/options.css" rel="stylesheet" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title data-message="optionsAndSettings"></title>
|
||||
</head>
|
||||
<body class="wrap">
|
||||
<div class="grid">
|
||||
<div class="unit whole center-on-mobiles">
|
||||
<div class="option">
|
||||
<h5 data-message="optionsURL"></h5>
|
||||
<input type="text" name="url" value="https://app.readlater.shikiryu.com" />
|
||||
<div class="heading">
|
||||
<h1 data-message="extensionName"></h1>
|
||||
<p class="lead" data-message="optionsPageSubtitle"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="option">
|
||||
<section>
|
||||
<div class="grid">
|
||||
<div class="unit whole center-on-mobiles">
|
||||
<div id="msg"></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="content">
|
||||
<div class="grid">
|
||||
<div class="unit whole center-on-mobiles">
|
||||
<div class="option">
|
||||
<h5 data-message="optionsURL"></h5>
|
||||
<input
|
||||
type="text"
|
||||
name="url"
|
||||
value="https://app.readlater.shikiryu.com"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="option">
|
||||
<h5 data-message="optionsToken"></h5>
|
||||
<input type="text" name="token" value="" />
|
||||
</div>
|
||||
|
||||
<div class="option">
|
||||
<h5 data-message="optionsExtract"></h5>
|
||||
<input type="checkbox" name="extract" value="1" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
|
||||
<footer class="main-footer">
|
||||
<div class="grid">
|
||||
<div class="unit whole center-on-mobiles">
|
||||
<p class="text-center text-muted">
|
||||
© <a href="https://readlater.shikiryu.com">Shikiryu</a>
|
||||
</p>
|
||||
<footer class="main-footer">
|
||||
<div class="grid">
|
||||
<div class="unit whole center-on-mobiles">
|
||||
<p class="text-center text-muted">
|
||||
© <a href="https://readlater.shikiryu.com">Shikiryu</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
<script src="scripts/options.js"></script>
|
||||
</body>
|
||||
</footer>
|
||||
<script src="scripts/options.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -1,14 +1,30 @@
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link href="styles/popup.css" rel="stylesheet">
|
||||
<meta charset="utf-8" />
|
||||
<link href="styles/popup.css" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" class="popup-content">
|
||||
<h1 data-message="extensionName"></h1>
|
||||
|
||||
<div id="display-container"></div>
|
||||
<div id="display-container">
|
||||
<div class="site-description">
|
||||
<h3 class="title" data-template="title"></h3>
|
||||
<p class="description" data-template="description"></p>
|
||||
<p class="image" data-template="image"></p>
|
||||
<div>
|
||||
<label for="comment">Comment:</label>
|
||||
<textarea id="comment" name="comment"></textarea>
|
||||
</div>
|
||||
<a href="" target="_blank" class="url" data-template="url"></a>
|
||||
</div>
|
||||
<div class="action-container">
|
||||
<label for="save-content" data-message="excerpt"></label>
|
||||
<input type="checkbox" id="save-content" name="save-content" />
|
||||
<button id="save-btn" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="main-footer">
|
||||
<div class="grid">
|
||||
@@ -21,7 +37,7 @@
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="scripts/popup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -1,44 +1,90 @@
|
||||
import ext from "./utils/ext";
|
||||
import storage from "./utils/storage";
|
||||
|
||||
ext.runtime.onMessage.addListener(
|
||||
function(request, sender, sendResponse) {
|
||||
if(request.action === "perform-save") {
|
||||
var data = request.data;
|
||||
var url;
|
||||
var token;
|
||||
storage.get(['url', 'token'], function(resp) {
|
||||
url = resp.url;
|
||||
token = resp.token;
|
||||
var params = {
|
||||
v: 1,
|
||||
u: encodeURIComponent(data.url),
|
||||
t: encodeURIComponent(data.title),
|
||||
d: encodeURIComponent(data.description),
|
||||
api_token: encodeURIComponent(token),
|
||||
i: encodeURIComponent(data.image),
|
||||
c: encodeURIComponent(data.comment),
|
||||
};
|
||||
var queryString = Object.keys(params).map((key) => {
|
||||
return key + '=' + params[key];
|
||||
}).join('&');
|
||||
fetch(url + "/api/links", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
body: new URLSearchParams(queryString)
|
||||
})
|
||||
.then(function(response) {
|
||||
if (200 === response.status) {
|
||||
sendResponse({action: "saved"});
|
||||
} else {
|
||||
sendResponse({action: "error", status: response.status, error: response.statusText});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return true; // https://stackoverflow.com/a/20077854
|
||||
}
|
||||
let onMenuAdded = function() {
|
||||
if (ext.browser.runtime.lastError) {
|
||||
console.log(`Error: ${ext.browser.runtime.lastError}`);
|
||||
} else {
|
||||
console.log("Readlater menu created successfully");
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
ext.contextMenus.create(
|
||||
{
|
||||
id: "dom-selection",
|
||||
title: ext.i18n.getMessage("selectDomToSend"),
|
||||
contexts: ["all"]
|
||||
},
|
||||
onMenuAdded
|
||||
);
|
||||
|
||||
ext.contextMenus.onClicked.addListener(function(info, tab) {
|
||||
if ("dom-selection" === info.menuItemId) {
|
||||
var page_data = {
|
||||
title: "",
|
||||
description: "",
|
||||
image: "",
|
||||
comment: "",
|
||||
url: document.location.href
|
||||
};
|
||||
ext.tabs.sendMessage(tab.id, { action: "process-page" }, function(data) {
|
||||
ext.tabs.sendMessage(tab.id, { action: "DOM", data: data }, function(
|
||||
response
|
||||
) {
|
||||
if (response && response.action === "saved") {
|
||||
console.log(ext.i18n.getMessage("savedSuccessfully"));
|
||||
} else {
|
||||
console.log(response.error + " (" + response.status + ")");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ext.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||
if (request.action === "perform-save") {
|
||||
var data = request.data;
|
||||
var url;
|
||||
var token;
|
||||
storage.get(["url", "token"], function(resp) {
|
||||
url = resp.url;
|
||||
token = resp.token;
|
||||
var params = {
|
||||
v: 1,
|
||||
u: encodeURIComponent(data.url),
|
||||
t: encodeURIComponent(data.title),
|
||||
d: encodeURIComponent(data.description),
|
||||
api_token: encodeURIComponent(token),
|
||||
i: encodeURIComponent(data.image),
|
||||
c: encodeURIComponent(data.comment)
|
||||
};
|
||||
if (data.extract) {
|
||||
params["e"] = true;
|
||||
}
|
||||
var queryString = Object.keys(params)
|
||||
.map(key => {
|
||||
return key + "=" + params[key];
|
||||
})
|
||||
.join("&");
|
||||
fetch(url + "/api/links", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: "application/json"
|
||||
},
|
||||
body: new URLSearchParams(queryString)
|
||||
}).then(function(response) {
|
||||
if (200 === response.status) {
|
||||
sendResponse({ action: "saved" });
|
||||
} else {
|
||||
sendResponse({
|
||||
action: "error",
|
||||
status: response.status,
|
||||
error: response.statusText
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return true; // https://stackoverflow.com/a/20077854
|
||||
}
|
||||
});
|
||||
|
@@ -1,49 +1,91 @@
|
||||
import ext from "./utils/ext";
|
||||
import storage from "./utils/storage";
|
||||
|
||||
var extractTags = () => {
|
||||
var url = document.location.href;
|
||||
let extractDOM = () => {
|
||||
let indexInParent = node => {
|
||||
let children = node.parentNode.childNodes;
|
||||
let num = 0;
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
if (children[i] === node) return num;
|
||||
if (children[i].nodeType === 1) num++;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
let gx = el => {
|
||||
let xp = "";
|
||||
for (; el && el.nodeType === 1; el = el.parentNode) {
|
||||
let id = indexInParent(el) + 1; // jQuery(el.parentNode).children(el.tagName).index(el)+1;
|
||||
id = id > 1 ? "[" + id + "]" : "";
|
||||
xp = "/" + el.tagName.toLowerCase() + id + xp;
|
||||
}
|
||||
|
||||
return xp;
|
||||
};
|
||||
|
||||
document.addEventListener("click", function(evt) {
|
||||
let tar = evt.target;
|
||||
while (tar && tar !== this) {
|
||||
if (tar.matches(".shikihover")) {
|
||||
let data = extractTags();
|
||||
data.xpath = gx(tar);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let extractTags = () => {
|
||||
let url = document.location.href;
|
||||
if (!url || !url.match(/^http/)) {
|
||||
console.error("Invalid URL : " + url);
|
||||
return;
|
||||
}
|
||||
|
||||
var data = {
|
||||
let data = {
|
||||
title: "",
|
||||
description: "",
|
||||
image: "",
|
||||
url: url
|
||||
};
|
||||
|
||||
var ogTitle = document.querySelector("meta[property='og:title']");
|
||||
if(ogTitle) {
|
||||
let ogTitle = document.querySelector("meta[property='og:title']");
|
||||
if (ogTitle) {
|
||||
data.title = ogTitle.getAttribute("content");
|
||||
} else {
|
||||
data.title = document.title;
|
||||
}
|
||||
|
||||
var descriptionTag = document.querySelector("meta[property='og:description']") || document.querySelector("meta[name='description']");
|
||||
if(descriptionTag) {
|
||||
data.description = descriptionTag.getAttribute("content")
|
||||
let descriptionTag =
|
||||
document.querySelector("meta[property='og:description']") ||
|
||||
document.querySelector("meta[name='description']");
|
||||
if (descriptionTag) {
|
||||
data.description = descriptionTag.getAttribute("content");
|
||||
}
|
||||
|
||||
var imgTag = document.querySelector("meta[property='og:image']") || document.querySelector("meta[property='twitter-image']");
|
||||
if(imgTag) {
|
||||
data.image = imgTag.getAttribute("content")
|
||||
} else {
|
||||
imgTag = document.querySelector("link[rel=icon]") || document.querySelector("link[rel=apple-touch-icon]");
|
||||
if (imgTag) {
|
||||
data.image = imgTag.getAttribute("href");
|
||||
}
|
||||
let imgTag =
|
||||
document.querySelector("meta[property='og:image']") ||
|
||||
document.querySelector("meta[property='twitter-image']");
|
||||
if (imgTag) {
|
||||
data.image = imgTag.getAttribute("content");
|
||||
} else {
|
||||
imgTag =
|
||||
document.querySelector("link[rel=icon]") ||
|
||||
document.querySelector("link[rel=apple-touch-icon]");
|
||||
if (imgTag) {
|
||||
data.image = imgTag.getAttribute("href");
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
function onRequest(request, sender, sendResponse) {
|
||||
if (request.action === 'process-page') {
|
||||
sendResponse(extractTags())
|
||||
if (request.action === "process-page") {
|
||||
sendResponse(extractTags());
|
||||
}
|
||||
if (request.action === "DOM") {
|
||||
console.log("DOM");
|
||||
sendResponse(extractDOM());
|
||||
}
|
||||
}
|
||||
|
||||
ext.runtime.onMessage.addListener(onRequest);
|
||||
ext.runtime.onMessage.addListener(onRequest);
|
||||
|
@@ -1,20 +1,22 @@
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
import ext from "./utils/ext";
|
||||
|
||||
var LIVERELOAD_HOST = 'localhost:';
|
||||
var LIVERELOAD_HOST = "localhost:";
|
||||
var LIVERELOAD_PORT = 35729;
|
||||
var connection = new WebSocket('ws://' + LIVERELOAD_HOST + LIVERELOAD_PORT + '/livereload');
|
||||
var connection = new WebSocket(
|
||||
"ws://" + LIVERELOAD_HOST + LIVERELOAD_PORT + "/livereload"
|
||||
);
|
||||
|
||||
connection.onerror = function (error) {
|
||||
console.log('reload connection got error:', error);
|
||||
connection.onerror = function(error) {
|
||||
console.log("reload connection got error:", error);
|
||||
};
|
||||
|
||||
connection.onmessage = function (e) {
|
||||
connection.onmessage = function(e) {
|
||||
if (e.data) {
|
||||
var data = JSON.parse(e.data);
|
||||
if (data && data.command === 'reload') {
|
||||
if (data && data.command === "reload") {
|
||||
ext.runtime.reload();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@@ -3,30 +3,42 @@ import storage from "./utils/storage";
|
||||
|
||||
var urlInput = document.querySelector("[name=url]");
|
||||
var tokenInput = document.querySelector("[name=token]");
|
||||
var extractInput = document.querySelector("[name=extract]");
|
||||
var message = document.getElementById("msg");
|
||||
|
||||
storage.get('url', function(resp) {
|
||||
urlInput.value = resp.url || "https://app.readlater.shikiryu.com";
|
||||
storage.get("url", function(resp) {
|
||||
urlInput.value = resp.url || "https://app.readlater.shikiryu.com";
|
||||
});
|
||||
|
||||
storage.get('token', function(resp) {
|
||||
tokenInput.value = resp.token;
|
||||
storage.get("token", function(resp) {
|
||||
tokenInput.value = resp.token;
|
||||
});
|
||||
|
||||
storage.get("extract", function(resp) {
|
||||
extractInput.value = resp.extract;
|
||||
});
|
||||
|
||||
urlInput.addEventListener("blur", function(e) {
|
||||
var value = this.value;
|
||||
storage.set({ url: value }, function() {
|
||||
message.innerHTML = ext.i18n.getMessage("URLChanged");
|
||||
});
|
||||
var value = this.value;
|
||||
storage.set({ url: value }, function() {
|
||||
message.textContent = ext.i18n.getMessage("URLChanged");
|
||||
});
|
||||
});
|
||||
|
||||
tokenInput.addEventListener("blur", function(e) {
|
||||
var value = this.value;
|
||||
storage.set({ token: value }, function() {
|
||||
message.innerHTML = ext.i18n.getMessage("tokenSaved");
|
||||
});
|
||||
var value = this.value;
|
||||
storage.set({ token: value }, function() {
|
||||
message.textContent = ext.i18n.getMessage("tokenSaved");
|
||||
});
|
||||
});
|
||||
|
||||
extractInput.addEventListener("change", function(e) {
|
||||
var value = this.value;
|
||||
storage.set({ extract: value }, function() {
|
||||
message.textContent = ext.i18n.getMessage("optionSaved");
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll("[data-message]").forEach(function(elt) {
|
||||
elt.innerHTML = ext.i18n.getMessage(elt.dataset.message);
|
||||
elt.textContent = ext.i18n.getMessage(elt.dataset.message);
|
||||
});
|
||||
|
@@ -2,80 +2,82 @@ import ext from "./utils/ext";
|
||||
import storage from "./utils/storage";
|
||||
|
||||
var page_data = {
|
||||
title: "",
|
||||
description: "",
|
||||
image: "",
|
||||
comment: "",
|
||||
url: document.location.href
|
||||
title: "",
|
||||
description: "",
|
||||
image: "",
|
||||
comment: "",
|
||||
url: document.location.href
|
||||
};
|
||||
|
||||
var popup = document.getElementById("app");
|
||||
storage.get('color', function(resp) {
|
||||
var color = resp.color;
|
||||
if(color) {
|
||||
popup.style.backgroundColor = color
|
||||
storage.get("extract", function(resp) {
|
||||
var extract = resp.extract;
|
||||
if (extract) {
|
||||
document.getElementById("save-content").checked = extract
|
||||
? "checked"
|
||||
: false;
|
||||
}
|
||||
});
|
||||
|
||||
var template = (data) => {
|
||||
return (`
|
||||
<div class="site-description">
|
||||
<h3 class="title">${data.title}</h3>
|
||||
<p class="description">${data.description}</p>
|
||||
<p class="image"><img src="${data.image}"></p>
|
||||
<div>
|
||||
<label for="comment">Comment:</label>
|
||||
<textarea id="comment" name="comment"></textarea>
|
||||
</div>
|
||||
<a href="${data.url}" target="_blank" class="url">${data.url}</a>
|
||||
</div>
|
||||
<div class="action-container">
|
||||
<button id="save-btn" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
`);
|
||||
};
|
||||
var renderMessage = (message) => {
|
||||
var displayContainer = document.getElementById("display-container");
|
||||
displayContainer.innerHTML = `<p class='message'>${message}</p>`;
|
||||
var renderMessage = message => {
|
||||
document.getElementById("display-container").textContent = message;
|
||||
};
|
||||
|
||||
var renderBookmark = (data) => {
|
||||
var displayContainer = document.getElementById("display-container");
|
||||
if(data) {
|
||||
page_data = data;
|
||||
displayContainer.innerHTML = template(data);
|
||||
var renderBookmark = data => {
|
||||
if (data) {
|
||||
page_data = data;
|
||||
document.querySelector("[data-template=title]").textContent =
|
||||
page_data.title;
|
||||
document.querySelector("[data-template=description]").textContent =
|
||||
page_data.description;
|
||||
if ("" !== img) {
|
||||
var img = document.createElement("image");
|
||||
img.src = page_data.image;
|
||||
document.querySelector("[data-template=image]").appendChild(img);
|
||||
}
|
||||
document.querySelector("[data-template=url]").textContent = page_data.url;
|
||||
document
|
||||
.querySelector("[data-template=url]")
|
||||
.setAttribute("href", page_data.url);
|
||||
} else {
|
||||
renderMessage(ext.i18n.getMessage("cantExtractTitle"));
|
||||
}
|
||||
};
|
||||
|
||||
ext.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
||||
ext.tabs.query({ active: true, currentWindow: true }, function(tabs) {
|
||||
var activeTab = tabs[0];
|
||||
chrome.tabs.sendMessage(activeTab.id, { action: 'process-page' }, renderBookmark);
|
||||
ext.tabs.sendMessage(
|
||||
activeTab.id,
|
||||
{ action: "process-page" },
|
||||
renderBookmark
|
||||
);
|
||||
});
|
||||
|
||||
popup.addEventListener("click", function(e) {
|
||||
if(e.target && e.target.matches("#save-btn")) {
|
||||
e.preventDefault();
|
||||
page_data.comment = document.getElementById("comment").value;
|
||||
ext.runtime.sendMessage({action: "perform-save", data: page_data}, function (response) {
|
||||
if (response && response.action === "saved") {
|
||||
renderMessage(ext.i18n.getMessage("savedSuccessfully"));
|
||||
} else {
|
||||
renderMessage(response.error + " ("+response.status+")");
|
||||
}
|
||||
});
|
||||
if (e.target && e.target.matches("#save-btn")) {
|
||||
e.preventDefault();
|
||||
page_data.comment = document.getElementById("comment").value;
|
||||
page_data.extract = document.getElementById("save-content").checked;
|
||||
ext.runtime.sendMessage(
|
||||
{ action: "perform-save", data: page_data },
|
||||
function(response) {
|
||||
if (response && response.action === "saved") {
|
||||
renderMessage(ext.i18n.getMessage("savedSuccessfully"));
|
||||
} else {
|
||||
renderMessage(response.error + " (" + response.status + ")");
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
var dataMessages = document.querySelectorAll("[data-message]");
|
||||
[].forEach.call(dataMessages, function(elt) {
|
||||
console.log(elt.dataset.message);
|
||||
elt.innerHTML = ext.i18n.getMessage(elt.dataset.message);
|
||||
elt.textContent = ext.i18n.getMessage(elt.dataset.message);
|
||||
});
|
||||
|
||||
var optionsLink = document.querySelector(".js-options");
|
||||
optionsLink.addEventListener("click", function(e) {
|
||||
e.preventDefault();
|
||||
ext.tabs.create({'url': ext.extension.getURL('options.html')});
|
||||
ext.tabs.create({ url: ext.extension.getURL("options.html") });
|
||||
});
|
||||
|
@@ -1,68 +1,66 @@
|
||||
const apis = [
|
||||
'alarms',
|
||||
'bookmarks',
|
||||
'browserAction',
|
||||
'commands',
|
||||
'contextMenus',
|
||||
'cookies',
|
||||
'downloads',
|
||||
'events',
|
||||
'extension',
|
||||
'extensionTypes',
|
||||
'history',
|
||||
'i18n',
|
||||
'idle',
|
||||
'notifications',
|
||||
'pageAction',
|
||||
'runtime',
|
||||
'storage',
|
||||
'tabs',
|
||||
'webNavigation',
|
||||
'webRequest',
|
||||
'windows',
|
||||
]
|
||||
"alarms",
|
||||
"bookmarks",
|
||||
"browserAction",
|
||||
"commands",
|
||||
"contextMenus",
|
||||
"cookies",
|
||||
"downloads",
|
||||
"events",
|
||||
"extension",
|
||||
"extensionTypes",
|
||||
"history",
|
||||
"i18n",
|
||||
"idle",
|
||||
"notifications",
|
||||
"pageAction",
|
||||
"runtime",
|
||||
"storage",
|
||||
"tabs",
|
||||
"webNavigation",
|
||||
"webRequest",
|
||||
"windows"
|
||||
];
|
||||
|
||||
function Extension () {
|
||||
const _this = this
|
||||
function Extension() {
|
||||
const _this = this;
|
||||
|
||||
apis.forEach(function (api) {
|
||||
|
||||
_this[api] = null
|
||||
apis.forEach(function(api) {
|
||||
_this[api] = null;
|
||||
|
||||
try {
|
||||
if (chrome[api]) {
|
||||
_this[api] = chrome[api]
|
||||
_this[api] = chrome[api];
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
if (window[api]) {
|
||||
_this[api] = window[api]
|
||||
_this[api] = window[api];
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
if (browser[api]) {
|
||||
_this[api] = browser[api]
|
||||
_this[api] = browser[api];
|
||||
}
|
||||
} catch (e) {}
|
||||
try {
|
||||
_this.api = browser.extension[api]
|
||||
_this.api = browser.extension[api];
|
||||
} catch (e) {}
|
||||
})
|
||||
});
|
||||
|
||||
try {
|
||||
if (browser && browser.runtime) {
|
||||
this.runtime = browser.runtime
|
||||
this.runtime = browser.runtime;
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
if (browser && browser.browserAction) {
|
||||
this.browserAction = browser.browserAction
|
||||
this.browserAction = browser.browserAction;
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
}
|
||||
|
||||
module.exports = new Extension();
|
||||
module.exports = new Extension();
|
||||
|
@@ -1,3 +1,3 @@
|
||||
import ext from "./ext";
|
||||
|
||||
module.exports = (ext.storage.sync ? ext.storage.sync : ext.storage.local);
|
||||
module.exports = ext.storage.sync ? ext.storage.sync : ext.storage.local;
|
||||
|
9
src/styles/contentstyle.css
Normal file
9
src/styles/contentstyle.css
Normal file
@@ -0,0 +1,9 @@
|
||||
div:hover,
|
||||
section:hover {
|
||||
border: 3px solid yellow;
|
||||
}
|
||||
|
||||
div,
|
||||
section {
|
||||
border: none;
|
||||
}
|
Reference in New Issue
Block a user