add files

This commit is contained in:
z0ccc 2021-06-03 01:25:03 -04:00
parent 8286109fa3
commit 5708740aa4
23 changed files with 25926 additions and 0 deletions

14
.babelrc Normal file
View file

@ -0,0 +1,14 @@
{
"presets": [
[
"@babel/preset-env",
{
"modules": false
}
],
"@babel/preset-react"
],
"plugins": [
"react-hot-loader/babel"
]
}

32
.eslintrc.js Normal file
View file

@ -0,0 +1,32 @@
module.exports = {
env: {
browser: true,
es2021: true,
webextensions: true,
},
// settings: {
// 'import/resolver': {
// typescript: {},
// },
// },
extends: ['plugin:react/recommended', 'airbnb'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: 'module',
},
plugins: ['react', '@typescript-eslint'],
rules: {
'no-plusplus': 'off',
'comma-dangle': 'off',
'operator-linebreak': 'off',
'no-use-before-define': 'off',
'linebreak-style': 'off',
'react/jsx-filename-extension': [1, { extensions: ['.tsx', '.ts'] }],
'jsx-a11y/label-has-associated-control': 'off',
'prefer-destructuring': 'off'
},
};

24
.gitignore vendored Normal file
View file

@ -0,0 +1,24 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
/dist
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

25548
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

45
package.json Normal file
View file

@ -0,0 +1,45 @@
{
"name": "reddit-toolkit",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack",
"start": "webpack --watch"
},
"keywords": [],
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.12.1",
"@hot-loader/react-dom": "^17.0.0-rc.2",
"@types/chrome": "0.0.143",
"@types/react": "^16.9.53",
"@types/react-dom": "^16.9.8",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"babel-loader": "^8.1.0",
"copy-webpack-plugin": "^6.2.1",
"css-loader": "^5.0.0",
"eslint": "^7.27.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"file-loader": "^6.1.1",
"style-loader": "^2.0.0",
"ts-loader": "^8.0.5",
"typescript": "^4.0.3",
"url-loader": "^4.1.1",
"webpack": "^5.1.3",
"webpack-cli": "^4.0.0",
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-hot-loader": "^4.13.0"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

BIN
promo_images/vytal3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

BIN
public/icon_128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
public/icon_16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

BIN
public/icon_32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
public/icon_48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

41
public/manifest.json Normal file
View file

@ -0,0 +1,41 @@
{
"name": "Reddit Toolkit",
"description": "Reddit Toolkit",
"manifest_version": 3,
"version": "1.0.0",
"permissions": ["storage", "declarativeNetRequest"],
"icons": {
"16": "icon_16.png",
"32": "icon_32.png",
"48": "icon_48.png",
"128": "icon_128.png"
},
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icon_16.png",
"32": "icon_32.png",
"48": "icon_48.png",
"128": "icon_128.png"
}
},
"background": {
"service_worker": "background.js"
},
"declarative_net_request": {
"rule_resources": [
{
"id": "ruleset_1",
"enabled": false,
"path": "rules.json"
}
]
},
"host_permissions": [
"*://reddit.com/*",
"*://www.reddit.com/*",
"*://np.reddit.com/*",
"*://amp.reddit.com/*",
"*://i.reddit.com/*"
]
}

14
public/popup.html Normal file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="popup"></div>
</body>
<script src="popup.js"></script>
</html>

16
public/rules.json Normal file
View file

@ -0,0 +1,16 @@
[
{
"id": 1,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"transform": { "scheme": "https", "host": "old.reddit.com" }
}
},
"condition": {
"urlFilter": "||reddit.com",
"resourceTypes": ["main_frame"]
}
}
]

8
src/App.css Normal file
View file

@ -0,0 +1,8 @@
.optionWrap {
display: flex;
align-items: center;
}
input {
margin: 0 8px 0 0;
}

48
src/App.tsx Normal file
View file

@ -0,0 +1,48 @@
import * as React from 'react';
import { useState, useEffect } from 'react';
import './App.css';
const handleChange = (el: React.ChangeEvent<HTMLInputElement>) => {
chrome.storage.sync.set({ [el.target.id]: el.target.checked });
console.log(el.target.id);
};
// function getChecked(elID: string): boolean {
// // console.log(elID);
// chrome.storage.sync.get('oldRedirect', (res) => {
// console.log(res.oldRedirect + '123');
// });
// console.log('?');
// return true;
// }
const App = () => {
useEffect(() => {
chrome.storage.sync.get(null, (res) => {
const allKeys = Object.entries(res);
console.log(allKeys);
allKeys.forEach((item) => {
console.log(item);
const test: any = document.getElementById(item[0]);
test.checked = item[1];
});
});
}, []);
return (
<div className="App">
<label>
<div className="optionWrap">
<input
type="checkbox"
id="oldRedirect"
onChange={handleChange}
/>
Redirect to old Reddit
</div>
</label>
</div>
);
};
export default App;

16
src/background.ts Normal file
View file

@ -0,0 +1,16 @@
// Initialize storage values
chrome.storage.sync.set({ oldRedirect: false });
chrome.storage.onChanged.addListener((changes) => {
if ('oldRedirect' in changes) {
if (changes.oldRedirect.newValue) {
(chrome as any).declarativeNetRequest.updateEnabledRulesets({
enableRulesetIds: ['ruleset_1'],
});
} else {
(chrome as any).declarativeNetRequest.updateEnabledRulesets({
disableRulesetIds: ['ruleset_1'],
});
}
}
});

2
src/content.ts Normal file
View file

@ -0,0 +1,2 @@
// This file is injected as a content script
console.log("Hello from content script!")

4
src/custom.d.ts vendored Normal file
View file

@ -0,0 +1,4 @@
declare module "*.svg" {
const content: any;
export default content;
}

12
src/popup.css Normal file
View file

@ -0,0 +1,12 @@
:root {
--text: #212121;
--background: #fff;
}
body {
color: var(--text);
background-color: var(--background);
font-size: 12px;
line-height: 22px;
width: 300px;
}

8
src/popup.tsx Normal file
View file

@ -0,0 +1,8 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App from './App';
import './popup.css';
const mountNode = document.getElementById('popup');
ReactDOM.render(<App />, mountNode);

18
tsconfig.json Normal file
View file

@ -0,0 +1,18 @@
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"strict": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"module": "es6",
"moduleResolution": "node",
"target": "es5",
"allowJs": true,
"jsx": "react",
},
"include": [
"./src/**/*",
"src/custom.d.ts"
]
}

76
webpack.config.js Normal file
View file

@ -0,0 +1,76 @@
const webpack = require("webpack");
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const config = {
entry: {
popup: path.join(__dirname, "src/popup.tsx"),
content: path.join(__dirname, "src/content.ts"),
background: path.join(__dirname, "src/background.ts"),
},
output: { path: path.join(__dirname, "dist"), filename: "[name].js" },
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: "babel-loader",
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
exclude: /\.module\.css$/,
},
{
test: /\.ts(x)?$/,
loader: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
importLoaders: 1,
modules: true,
},
},
],
include: /\.module\.css$/,
},
{
test: /\.svg$/,
use: "file-loader",
},
{
test: /\.png$/,
use: [
{
loader: "url-loader",
options: {
mimetype: "image/png",
},
},
],
},
],
},
resolve: {
extensions: [".js", ".jsx", ".tsx", ".ts"],
alias: {
"react-dom": "@hot-loader/react-dom",
},
},
devServer: {
contentBase: "./dist",
},
plugins: [
new CopyPlugin({
patterns: [{ from: "public", to: "." }],
}),
],
};
module.exports = config;