parent
78fcc974da
commit
c044a68a13
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 4
|
||||
"tabWidth": 2
|
||||
}
|
||||
35
README.md
35
README.md
|
|
@ -4,12 +4,16 @@ Chrome/Firefox extension which can import media from various sites into a [szuru
|
|||
|
||||
## Supported sites
|
||||
|
||||
- Gelbooru/Safebooru/Rule34.xxx
|
||||
- Danbooru (and Safebooru variant)
|
||||
- Rule34 paheal (Shimmie2)
|
||||
- Gelbooru/Safebooru/Rule34.xxx/tbib.org
|
||||
- yande.re/konachan (Moebooru)
|
||||
- SankakuComplex (doesn't currently work because of the hotlink protection)
|
||||
- Rule34 paheal (Shimmie2)
|
||||
- E-Shuushuu
|
||||
- Zerochan
|
||||
- Reddit
|
||||
- Twitter
|
||||
- Fallback (simply grabs the largest image on a page)
|
||||
|
||||
## Installation
|
||||
|
||||
|
|
@ -26,15 +30,24 @@ The layout is obviously not designed for mobile, so at times it looks less than
|
|||
|
||||
## How does it work?
|
||||
|
||||
This add-on has two parts. The first part is the popup, which is what pops up when you click on the logo. The second part is a content script which is injected on _every_ website ([why?](#Why-is-the-content-script-injected-on-every-page)).
|
||||
This add-on has three parts.
|
||||
The first part is the popup, which is what pops up when you click on the logo.
|
||||
|
||||
The second part is a content script which is injected on the page you visit. This script tries to find importable content on the current page and sends this to the popup.
|
||||
|
||||
The third part is the background script which handles the upload functionality. This was previously part of the popup, but has since been moved to the background script.
|
||||
|
||||
### The popup
|
||||
|
||||
When opened (when you click on the add-on logo in your browser) it sends a message to the content script injected on the current page (active tab). This message asks the content script to scrape the DOM and return a SzuruPost element (with a source, imageUrl, safety, and a list of tags). Once it receives this element it renders it in the popup where you can make changes before importing it.
|
||||
When opened (when you click on the add-on logo in your browser) it sends a message to the content script injected on the current page (active tab). This message asks the content script to scrape the DOM and return a SzuruPost element (with a source, imageUrl, safety, and a list of tags). Once it receives this element it renders it in the popup where you can make changes before importing it. When you click on the "Upload" button the SzuruPost will be sent to the background script which will handle the upload functionality. This is done so that the upload continues even after you close the popup. This means that you can close the popup after clicking the "Upload" button and it'll continue with the upload.
|
||||
|
||||
### The content script
|
||||
|
||||
This script is injected on every page ([why?](#Why-is-the-content-script-injected-on-every-page)) and does absolutely nothing until it receives the 'grab_post' message from the popup. Once it does received this message it checks if there are any loaders available to scrape this page. If a matching loader is found it'll pass the DOM of this page to the loader. The loader then uses the DOM to fill (as much as possible) a SzuruPost object. The SzuruPost is then passed back to the popup where you can change the post before importing it.
|
||||
This script is injected on every page and does absolutely nothing until it receives the 'grab_post' message from the popup. Once it does received this message it checks if there are any loaders available to scrape this page. If a matching loader is found it'll pass the DOM of this page to the loader. The loader then uses the DOM to fill (as much as possible) a SzuruPost object. The SzuruPost is then passed back to the popup where you can change the post before importing it.
|
||||
|
||||
### The background script
|
||||
|
||||
This script handles the uploading of a post. It will also update a tag's category in your szurubooru instance when it differs from what is imported.
|
||||
|
||||
## Build/debug
|
||||
|
||||
|
|
@ -57,9 +70,9 @@ Firefox: `about:debugging` -> "Load Temporary Add-on..." -> Select any file in t
|
|||
|
||||
## Planned features
|
||||
|
||||
These are some things I might work on. Though honestly I don't expect this extension to change much anytime soon.
|
||||
|
||||
- Finishing the initial version of this add-on (see visual design doc for all features)
|
||||
- Auto-set tag category when creating a new tag (imported tag)
|
||||
- Reverse image search to check whether (similar) file already exist before uploading it
|
||||
- Right click any image on a page to import it
|
||||
- Configurable list of tags to always ignore (e.g. tagme, highres)
|
||||
- [low priority] Import artist commentary
|
||||
|
|
@ -97,10 +110,6 @@ Because the CORS spec is a bitch the preflight request is sent without the clien
|
|||
</Location>
|
||||
```
|
||||
|
||||
### Why is the content script injected on every page?
|
||||
|
||||
Because I didn't know that you can inject a script from the popup (after opening it, so only when needed). I might change this later.
|
||||
|
||||
### Why send the DOM to the ILoader instead of just an url?
|
||||
|
||||
If we send an URL to the ILoader it has to download the page again itself, which can go wrong in a dozen ways:
|
||||
|
|
@ -110,7 +119,3 @@ If we send an URL to the ILoader it has to download the page again itself, which
|
|||
3. If you made changes to the DOM but didn't submit them to the server (e.g. edit post page) the ILoader would see a different page (kinda the same as point 2)
|
||||
4. If any form of authentication (username+password/client certificate/etc) is involved it gets tricky
|
||||
5. We already have the DOM, why download it again?
|
||||
|
||||
### Why is the CSS so bad?
|
||||
|
||||
Because CSS scares me.
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
|
|
@ -1,9 +1,12 @@
|
|||
{
|
||||
"name": "szuru-chrome",
|
||||
"version": "0.3.2",
|
||||
"description": "Import media from various sites into szurubooru",
|
||||
"version": "0.4.1",
|
||||
"description": "Import media from various sites into szurubooru.",
|
||||
"author": "neobooru",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"url": "https://github.com/neobooru/SzuruChrome"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cross-env NODE_ENV=production webpack --hide-modules",
|
||||
"build:dev": "cross-env NODE_ENV=development webpack --hide-modules",
|
||||
|
|
@ -12,9 +15,8 @@
|
|||
"watch:dev": "cross-env HMR=true npm run build:dev -- --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.19.2",
|
||||
"axios": "^0.21.1",
|
||||
"neo-scraper": "^0.2.5",
|
||||
"ts-optchain": "^0.1.8",
|
||||
"vue": "^2.6.11",
|
||||
"webextension-polyfill": "^0.3.1"
|
||||
},
|
||||
|
|
@ -24,7 +26,6 @@
|
|||
"core-js": "^3.6.5",
|
||||
"cross-env": "^5.2.1",
|
||||
"css-loader": "^2.1.1",
|
||||
"ejs": "^2.7.4",
|
||||
"file-loader": "^1.1.11",
|
||||
"mini-css-extract-plugin": "^0.4.4",
|
||||
"node-sass": "^4.14.1",
|
||||
|
|
|
|||
|
|
@ -1,52 +1,52 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const archiver = require('archiver');
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const archiver = require("archiver");
|
||||
|
||||
const DEST_DIR = path.join(__dirname, '../dist');
|
||||
const DEST_ZIP_DIR = path.join(__dirname, '../dist-zip');
|
||||
const DEST_DIR = path.join(__dirname, "../dist");
|
||||
const DEST_ZIP_DIR = path.join(__dirname, "../dist-zip");
|
||||
|
||||
const extractExtensionData = () => {
|
||||
const extPackageJson = require('../package.json');
|
||||
const extPackageJson = require("../package.json");
|
||||
|
||||
return {
|
||||
name: extPackageJson.name,
|
||||
version: extPackageJson.version
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const makeDestZipDirIfNotExists = () => {
|
||||
if(!fs.existsSync(DEST_ZIP_DIR)) {
|
||||
if (!fs.existsSync(DEST_ZIP_DIR)) {
|
||||
fs.mkdirSync(DEST_ZIP_DIR);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const buildZip = (src, dist, zipFilename) => {
|
||||
console.info(`Building ${zipFilename}...`);
|
||||
|
||||
const archive = archiver('zip', { zlib: { level: 9 }});
|
||||
const archive = archiver("zip", { zlib: { level: 9 } });
|
||||
const stream = fs.createWriteStream(path.join(dist, zipFilename));
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
archive
|
||||
.directory(src, false)
|
||||
.on('error', err => reject(err))
|
||||
.on("error", err => reject(err))
|
||||
.pipe(stream);
|
||||
|
||||
stream.on('close', () => resolve());
|
||||
stream.on("close", () => resolve());
|
||||
archive.finalize();
|
||||
});
|
||||
};
|
||||
|
||||
const main = () => {
|
||||
const {name, version} = extractExtensionData();
|
||||
const { name, version } = extractExtensionData();
|
||||
const zipFilename = `${name}-v${version}.zip`;
|
||||
|
||||
makeDestZipDirIfNotExists();
|
||||
|
||||
buildZip(DEST_DIR, DEST_ZIP_DIR, zipFilename)
|
||||
.then(() => console.info('OK'))
|
||||
.then(() => console.info("OK"))
|
||||
.catch(console.err);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
export type Safety = "safe" | "sketchy" | "unsafe";
|
||||
|
||||
export type TagsResult = PagedSearchResult<Tag>
|
||||
export type TagCategoriesResult = UnpagedSearchResult<TagCategory>
|
||||
export type TagsResult = PagedSearchResult<Tag>;
|
||||
export type TagCategoriesResult = UnpagedSearchResult<TagCategory>;
|
||||
|
||||
export interface SzuruError {
|
||||
name: string;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export default class SzuruWrapper {
|
|||
authToken: string;
|
||||
|
||||
private readonly baseHeaders = {
|
||||
"Accept": "application/json",
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json"
|
||||
};
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ export default class SzuruWrapper {
|
|||
const config: AxiosRequestConfig = {
|
||||
method: "GET",
|
||||
url: fullUrl
|
||||
}
|
||||
};
|
||||
|
||||
config.headers = { ...this.baseHeaders, ...additionalHeaders };
|
||||
return await this.execute(config);
|
||||
|
|
@ -91,7 +91,7 @@ export default class SzuruWrapper {
|
|||
method: "POST",
|
||||
url: fullUrl,
|
||||
data: data
|
||||
}
|
||||
};
|
||||
|
||||
config.headers = { ...this.baseHeaders, ...additionalHeaders };
|
||||
return await this.execute(config);
|
||||
|
|
@ -103,7 +103,7 @@ export default class SzuruWrapper {
|
|||
method: "PUT",
|
||||
url: fullUrl,
|
||||
data: data
|
||||
}
|
||||
};
|
||||
|
||||
config.headers = { ...this.baseHeaders, ...additionalHeaders };
|
||||
return await this.execute(config);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "SzuruChrome",
|
||||
"description": "Import media from various sites into szurubooru",
|
||||
"description": "Import media from various sites into szurubooru.",
|
||||
"version": null,
|
||||
"manifest_version": 2,
|
||||
"icons": {
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
},
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "{8cc2afc8-6c4a-4d2b-9513-46e46e5b4208}"
|
||||
"id": "{13372607-2257-4360-8f51-5ce66fa73350}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,11 +24,7 @@
|
|||
<br />
|
||||
<label>
|
||||
Automatically search for similar posts
|
||||
<input
|
||||
type="checkbox"
|
||||
name="autoSearchSimilar"
|
||||
v-model="autoSearchSimilar"
|
||||
/>
|
||||
<input type="checkbox" name="autoSearchSimilar" v-model="autoSearchSimilar" />
|
||||
</label>
|
||||
<br />
|
||||
<div class="settings-footer-buttons">
|
||||
|
|
@ -41,7 +37,6 @@
|
|||
|
||||
<script lang="ts">
|
||||
import Vue from "vue";
|
||||
import { oc } from "ts-optchain";
|
||||
import SzuruWrapper from "../SzuruWrapper";
|
||||
import { Config, SzuruSiteConfig } from "../Config";
|
||||
|
||||
|
|
@ -51,7 +46,7 @@ export default Vue.extend({
|
|||
domain: "",
|
||||
username: "",
|
||||
authToken: "",
|
||||
autoSearchSimilar: false
|
||||
autoSearchSimilar: false,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
|
|
@ -64,7 +59,7 @@ export default Vue.extend({
|
|||
const api = new SzuruWrapper(this.domain, this.username, this.authToken);
|
||||
try {
|
||||
const info = (await api.getInfo()) as any;
|
||||
const instanceName = oc(info).config.domain;
|
||||
const instanceName = info?.config.name;
|
||||
|
||||
if (instanceName == undefined) {
|
||||
alert(`Connected to ${this.domain}, but it is not a szurubooru instance.`);
|
||||
|
|
@ -88,7 +83,7 @@ export default Vue.extend({
|
|||
config.autoSearchSimilar = this.autoSearchSimilar;
|
||||
|
||||
await config.save();
|
||||
}
|
||||
},
|
||||
},
|
||||
async mounted() {
|
||||
let config = await Config.load();
|
||||
|
|
@ -102,7 +97,7 @@ export default Vue.extend({
|
|||
this.authToken = config.sites[0].authToken;
|
||||
this.autoSearchSimilar = config.autoSearchSimilar;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>SzuruChrome - Options</title>
|
||||
<link rel="stylesheet" href="options.css" />
|
||||
<% if (NODE_ENV === 'development') { %>
|
||||
<!-- Load some resources only in development environment -->
|
||||
<% } %>
|
||||
</head>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="options.js"></script>
|
||||
</body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import '../css/style.css';
|
||||
import "../css/style.css";
|
||||
|
||||
import Vue from 'vue';
|
||||
import App from './App';
|
||||
import Vue from "vue";
|
||||
import App from "./App";
|
||||
|
||||
new Vue({
|
||||
el: '#app',
|
||||
el: "#app",
|
||||
render: h => h(App)
|
||||
})
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,12 +2,7 @@
|
|||
<div class="popup-container">
|
||||
<div class="popup-messages">
|
||||
<ul class="messages">
|
||||
<li
|
||||
v-for="msg in messages"
|
||||
:key="msg.name"
|
||||
:class="getMessageClasses(msg)"
|
||||
v-html="msg.content"
|
||||
></li>
|
||||
<li v-for="msg in messages" :key="msg.name" :class="getMessageClasses(msg)" v-html="msg.content"></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
@ -51,13 +46,9 @@
|
|||
<span>Tags</span>
|
||||
</div>
|
||||
|
||||
<div class="section-row" style="display:flex;">
|
||||
<div class="section-row" style="display: flex">
|
||||
<input type="text" v-model="addTagInput" v-on:keyup.enter="addTag" />
|
||||
<button
|
||||
class="primary"
|
||||
style="margin-left: 5px; height: auto;"
|
||||
@click="addTag"
|
||||
>Add</button>
|
||||
<button class="primary" style="margin-left: 5px; height: auto" @click="addTag">Add</button>
|
||||
</div>
|
||||
|
||||
<div class="section-row">
|
||||
|
|
@ -83,20 +74,16 @@
|
|||
<div class="popup-right">
|
||||
<div class="popup-section">
|
||||
<select v-model="selectedPost">
|
||||
<option
|
||||
v-for="post in posts"
|
||||
v-bind:key="post"
|
||||
v-bind:value="post"
|
||||
>{{ post.name }}</option>
|
||||
<option v-for="post in posts" v-bind:key="post" v-bind:value="post">{{ post.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="popup-section">
|
||||
<img :src="selectedPost.imageUrl" />
|
||||
|
||||
<div style="display: flex;">
|
||||
<div style="display: flex">
|
||||
<button class="primary" @click="findSimilar">Find similar</button>
|
||||
<button class="primary full" style="margin-left: 5px;" @click="upload">Import</button>
|
||||
<button class="primary full" style="margin-left: 5px" @click="upload">Import</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -125,7 +112,7 @@ export default Vue.extend({
|
|||
posts: [] as ScrapedPostViewModel[],
|
||||
selectedPost: new ScrapedPost(), // Shouldn't be null because VueJS gets a mental breakdown when it sees a null.
|
||||
messages: [] as Message[],
|
||||
addTagInput: ""
|
||||
addTagInput: "",
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
|
|
@ -134,7 +121,7 @@ export default Vue.extend({
|
|||
// No need to check if any vars are unset, findSimilar does that internally
|
||||
this.findSimilar();
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
// Try to scrape the post from the page
|
||||
|
|
@ -143,7 +130,7 @@ export default Vue.extend({
|
|||
const activeTab = (
|
||||
await browser.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
currentWindow: true,
|
||||
})
|
||||
)[0];
|
||||
|
||||
|
|
@ -254,7 +241,7 @@ export default Vue.extend({
|
|||
if (this.selectedPost) {
|
||||
const tagName = this.addTagInput;
|
||||
this.addTagInput = "";
|
||||
if (this.selectedPost.tags.find(x => x.name == tagName) == undefined) {
|
||||
if (this.selectedPost.tags.find((x) => x.name == tagName) == undefined) {
|
||||
this.selectedPost.tags.push(new ScrapedTag(tagName));
|
||||
}
|
||||
}
|
||||
|
|
@ -292,7 +279,7 @@ export default Vue.extend({
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
async mounted() {
|
||||
this.config = await Config.load();
|
||||
|
|
@ -320,7 +307,7 @@ export default Vue.extend({
|
|||
|
||||
// Always call grabPost, even when there is no activeSite
|
||||
this.grabPost();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Title</title>
|
||||
<link rel="stylesheet" href="popup.css" />
|
||||
<% if (NODE_ENV === 'development') { %>
|
||||
<!-- Load some resources only in development environment -->
|
||||
<% } %>
|
||||
</head>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="popup.js"></script>
|
||||
</body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import '../css/style.css';
|
||||
import '../css/fontawesome.css';
|
||||
import '../css/solid.css';
|
||||
import "../css/style.css";
|
||||
import "../css/fontawesome.css";
|
||||
import "../css/solid.css";
|
||||
|
||||
import Vue from 'vue';
|
||||
import App from './App';
|
||||
import Vue from "vue";
|
||||
import App from "./App";
|
||||
|
||||
new Vue({
|
||||
el: '#app',
|
||||
el: "#app",
|
||||
render: h => h(App)
|
||||
})
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ async function uploadPost(post: ScrapedPost) {
|
|||
browser.runtime.sendMessage(new BrowserCommand("push_message", new Message("Uploading...")));
|
||||
const createdPost = await szuru.createPost(post);
|
||||
browser.runtime.sendMessage(new BrowserCommand("remove_messages", 1));
|
||||
browser.runtime.sendMessage(new BrowserCommand("push_message", new Message("Uploaded post " + createdPost.id, "success")));
|
||||
browser.runtime.sendMessage(
|
||||
new BrowserCommand("push_message", new Message("Uploaded post " + createdPost.id, "success"))
|
||||
);
|
||||
|
||||
// TODO: Clicking a link doesn't actually open it in a new tab,
|
||||
// see https://stackoverflow.com/questions/8915845
|
||||
|
|
@ -32,18 +34,24 @@ async function uploadPost(post: ScrapedPost) {
|
|||
.filter(x => x.category == "default")
|
||||
.filter(x => tagsWithCategory.some(y => x.names.includes(y.name)));
|
||||
if (unsetCategoryTags.length != 0) {
|
||||
browser.runtime.sendMessage(new BrowserCommand("push_message", new Message(`${unsetCategoryTags.length} tags need a different category`)));
|
||||
browser.runtime.sendMessage(
|
||||
new BrowserCommand("push_message", new Message(`${unsetCategoryTags.length} tags need a different category`))
|
||||
);
|
||||
// unsetCategoryTags is of type MicroTag[] and we need a Tag resource to update it, so let's get those
|
||||
const query = "?query=" + unsetCategoryTags.map(x => encodeTagName(x.names[0]));
|
||||
const tags = (await szuru.getTags(query)).results;
|
||||
for (let i in tags) {
|
||||
browser.runtime.sendMessage(new BrowserCommand("remove_messages", 1));
|
||||
browser.runtime.sendMessage(new BrowserCommand("push_message", new Message(`Updating tag ${i}/${unsetCategoryTags.length}`)));
|
||||
browser.runtime.sendMessage(
|
||||
new BrowserCommand("push_message", new Message(`Updating tag ${i}/${unsetCategoryTags.length}`))
|
||||
);
|
||||
tags[i].category = tagsWithCategory.find(x => tags[i].names.includes(x.name))!.category!;
|
||||
await szuru.updateTag(tags[i]);
|
||||
}
|
||||
browser.runtime.sendMessage(new BrowserCommand("remove_messages", 1));
|
||||
browser.runtime.sendMessage(new BrowserCommand("push_message", new Message(`Updated ${tags.length} tags`, "success")));
|
||||
browser.runtime.sendMessage(
|
||||
new BrowserCommand("push_message", new Message(`Updated ${tags.length} tags`, "success"))
|
||||
);
|
||||
}
|
||||
} catch (ex) {
|
||||
const error = ex as SzuruError;
|
||||
|
|
@ -65,7 +73,8 @@ function encodeTagName(tagName: string) {
|
|||
|
||||
async function messageHandler(cmd: BrowserCommand, sender: Runtime.MessageSender): Promise<any> {
|
||||
switch (cmd.name) {
|
||||
case "upload_post": return uploadPost(cmd.data);
|
||||
case "upload_post":
|
||||
return uploadPost(cmd.data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ function grabPost(): ScrapeResults {
|
|||
|
||||
async function messageHandler(cmd: BrowserCommand, sender: Runtime.MessageSender): Promise<any> {
|
||||
switch (cmd.name) {
|
||||
case "grab_post": return grabPost();
|
||||
case "grab_post":
|
||||
return grabPost();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
"outDir": "./dist/",
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"module": "es2015",
|
||||
"module": "es2020",
|
||||
"moduleResolution": "node",
|
||||
"target": "es6",
|
||||
"skipLibCheck": true,
|
||||
|
|
@ -12,11 +12,6 @@
|
|||
"lib": [
|
||||
"es2017",
|
||||
"dom"
|
||||
],
|
||||
"plugins": [
|
||||
{
|
||||
"transform": "ts-optchain/transform"
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
|
|
|
|||
|
|
@ -1,118 +1,114 @@
|
|||
const webpack = require('webpack');
|
||||
const ejs = require('ejs');
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
const ExtensionReloader = require('webpack-extension-reloader');
|
||||
const { VueLoaderPlugin } = require('vue-loader');
|
||||
const { version } = require('./package.json');
|
||||
const webpack = require("webpack");
|
||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
const ExtensionReloader = require("webpack-extension-reloader");
|
||||
const { VueLoaderPlugin } = require("vue-loader");
|
||||
const { version } = require("./package.json");
|
||||
|
||||
const config = {
|
||||
mode: process.env.NODE_ENV,
|
||||
context: __dirname + '/src',
|
||||
context: __dirname + "/src",
|
||||
entry: {
|
||||
'scripts/content': './scripts/content.ts',
|
||||
'scripts/background': './scripts/background.ts',
|
||||
'popup/popup': './popup/popup.ts',
|
||||
'options/options': './options/options.ts',
|
||||
"scripts/content": "./scripts/content.ts",
|
||||
"scripts/background": "./scripts/background.ts",
|
||||
"popup/popup": "./popup/popup.ts",
|
||||
"options/options": "./options/options.ts"
|
||||
},
|
||||
output: {
|
||||
path: __dirname + '/dist',
|
||||
filename: '[name].js',
|
||||
path: __dirname + "/dist",
|
||||
filename: "[name].js"
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js', '.vue'],
|
||||
extensions: [".ts", ".js", ".vue"]
|
||||
},
|
||||
devtool: 'inline-source-map',
|
||||
performance: {
|
||||
hints: false
|
||||
},
|
||||
devtool: "inline-source-map",
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.vue$/,
|
||||
loaders: 'vue-loader',
|
||||
loaders: "vue-loader"
|
||||
},
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
loader: 'ts-loader',
|
||||
loader: "ts-loader",
|
||||
exclude: /node_modules/,
|
||||
options: {
|
||||
appendTsSuffixTo: [/\.vue$/],
|
||||
appendTsSuffixTo: [/\.vue$/]
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [MiniCssExtractPlugin.loader, 'css-loader'],
|
||||
use: [MiniCssExtractPlugin.loader, "css-loader"]
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpg|gif|svg|ico)$/,
|
||||
loader: 'file-loader',
|
||||
loader: "file-loader",
|
||||
options: {
|
||||
name: '[name].[ext]?emitFile=false',
|
||||
},
|
||||
name: "[name].[ext]?emitFile=false"
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
|
||||
loader: 'file-loader',
|
||||
loader: "file-loader",
|
||||
options: {
|
||||
name: '[name].[ext]?emitFile=false',
|
||||
outputPath: '/fonts/'
|
||||
},
|
||||
},
|
||||
],
|
||||
name: "[name].[ext]?emitFile=false",
|
||||
outputPath: "/fonts/"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
global: 'window',
|
||||
global: "window"
|
||||
}),
|
||||
new VueLoaderPlugin(),
|
||||
new MiniCssExtractPlugin({
|
||||
filename: '[name].css',
|
||||
filename: "[name].css"
|
||||
}),
|
||||
new CopyWebpackPlugin([
|
||||
{ from: 'icons', to: 'icons', ignore: ['icon.xcf'] },
|
||||
{ from: 'popup/popup.html', to: 'popup/popup.html', transform: transformHtml },
|
||||
{ from: 'options/options.html', to: 'options/options.html', transform: transformHtml },
|
||||
{ from: "icons", to: "icons", ignore: ["icon.xcf"] },
|
||||
{ from: "popup/popup.html", to: "popup/popup.html" },
|
||||
{ from: "options/options.html", to: "options/options.html" },
|
||||
{
|
||||
from: 'manifest.json',
|
||||
to: 'manifest.json',
|
||||
transform: (content) => {
|
||||
from: "manifest.json",
|
||||
to: "manifest.json",
|
||||
transform: content => {
|
||||
const jsonContent = JSON.parse(content);
|
||||
jsonContent.version = version;
|
||||
|
||||
if (config.mode === 'development') {
|
||||
jsonContent['content_security_policy'] = "script-src 'self' 'unsafe-eval'; object-src 'self'";
|
||||
if (config.mode === "development") {
|
||||
jsonContent["content_security_policy"] = "script-src 'self' 'unsafe-eval'; object-src 'self'";
|
||||
}
|
||||
|
||||
return JSON.stringify(jsonContent, null, 2);
|
||||
},
|
||||
},
|
||||
]),
|
||||
}
|
||||
}
|
||||
])
|
||||
]
|
||||
};
|
||||
|
||||
if (config.mode === 'production') {
|
||||
if (config.mode === "production") {
|
||||
config.plugins = (config.plugins || []).concat([
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
NODE_ENV: '"production"',
|
||||
},
|
||||
}),
|
||||
"process.env": {
|
||||
NODE_ENV: '"production"'
|
||||
}
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
if (process.env.HMR === 'true') {
|
||||
if (process.env.HMR === "true") {
|
||||
config.plugins = (config.plugins || []).concat([
|
||||
new ExtensionReloader({
|
||||
entries: {
|
||||
contentScript: 'scripts/content',
|
||||
background: 'scripts/background'
|
||||
contentScript: "scripts/content",
|
||||
background: "scripts/background"
|
||||
}
|
||||
}),
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
function transformHtml(content) {
|
||||
return ejs.render(content.toString(), {
|
||||
...process.env,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = config;
|
||||
|
|
|
|||
Loading…
Reference in New Issue