Skip to content

Commit

Permalink
Merge pull request #18 from yuki777/delete-sweetalert2
Browse files Browse the repository at this point in the history
Delete toast option
  • Loading branch information
yuki777 authored Aug 27, 2022
2 parents 6e6b146 + c41786c commit 4c0116c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 62 deletions.
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,3 @@
```json
"style": false,
```
### toast
- Show popup box via [`sweetalert2`](https://github.com/sweetalert2/sweetalert2)
```json
"toast": {
"icon": "error",
"position": "center",
"showConfirmButton": false,
"timer": 1000,
"title": "Hey, Watch out! It's PRODUCTION!!!"
},
```
- Disable to show popup box
```json
"toast": false,
```
57 changes: 26 additions & 31 deletions content.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
(function() {
chrome.runtime.onMessage.addListener(
async function(message, sender, callback) {
if (message.type === "notify") {
let body = document.querySelector('html body');
let config = message.config;
if (message.type !== "notify") {
return;
}

// alert
if(config.alert){
alert(config.alert);
}
if (! message.hasOwnProperty('config')) {
return;
}

// style
if(config.style){
body.style.backgroundColor = config.style.backgroundColor;
}
let body = document.querySelector('html body');
let config = message.config;

// favicon
if(config.favicon){
document.querySelectorAll("link[rel=icon]").forEach((element) => element.remove());
let favicon;
favicon = document.createElement('link');
favicon.rel = config.favicon.rel;
favicon.type = config.favicon.type;
favicon.href = config.favicon.href;
document.getElementsByTagName('head')[0].appendChild(favicon);
}
// alert
if(config.alert){
alert(config.alert);
}

// style
if(config.style){
body.style.backgroundColor = config.style.backgroundColor;
}

// toast
if(config.toast){
Swal.fire({
position: config.toast.position,
icon: config.toast.icon,
title: config.toast.title,
showConfirmButton: config.toast.showConfirmButton,
timer: config.toast.timer
});
}
// favicon
if(config.favicon){
document.querySelectorAll("link[rel=icon]").forEach((element) => element.remove());
let favicon;
favicon = document.createElement('link');
favicon.rel = config.favicon.rel;
favicon.type = config.favicon.type;
favicon.href = config.favicon.href;
document.getElementsByTagName('head')[0].appendChild(favicon);
}
}
);
Expand Down
5 changes: 2 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"manifest_version": 3,
"name": "Peacekeeper",
"version": "1.3.0",
"version": "1.4.0",
"description": "Peacekeeper will notify you for each website you specify.",
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"js": [
"content.js",
"sweetalert2.all.min.js"
"content.js"
],
"matches": [
"*://*/*"
Expand Down
3 changes: 0 additions & 3 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ <h3>Configs</h3>
<li>
style: Change style <code>backgroundColor</code>
</li>
<li>
toast: Show popup box via <a href="https://github.com/sweetalert2/sweetalert2" target="_blank">sweetalert2</a>
</li>
<li>
url: Specify the target URL
</li>
Expand Down
4 changes: 0 additions & 4 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function getDefaultConfigs(){
"style": {
"backgroundColor": "rgb(48,209,88)"
},
"toast": false,
"url": "^https?://(127.0.0.1|localhost):(.+83|8080)"
},
{
Expand All @@ -70,7 +69,6 @@ function getDefaultConfigs(){
"style": {
"backgroundColor": "rgb(10,132,255)"
},
"toast": false,
"url": "^https?://dev-.+-admin.+"
},
{
Expand All @@ -84,7 +82,6 @@ function getDefaultConfigs(){
"style": {
"backgroundColor": "rgb(255,214,10)"
},
"toast": false,
"url": "^https?:\/\/.*stage-admin.+|^https?:\/\/admin-.+stage.+"
},
{
Expand All @@ -98,7 +95,6 @@ function getDefaultConfigs(){
"style": {
"backgroundColor": "rgb(255,69,58)"
},
"toast": false,
"url": "^https?:\/\/.*admin.+"
}
];
Expand Down
2 changes: 0 additions & 2 deletions sweetalert2.all.min.js

This file was deleted.

4 changes: 0 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function getDefaultConfigs(){
"style": {
"backgroundColor": "rgb(48,209,88)"
},
"toast": false,
"url": "^https?://(127.0.0.1|localhost):(.+83|8080)"
},
{
Expand All @@ -17,7 +16,6 @@ function getDefaultConfigs(){
"style": {
"backgroundColor": "rgb(10,132,255)"
},
"toast": false,
"url": "^https?://dev-.+-admin.+"
},
{
Expand All @@ -31,7 +29,6 @@ function getDefaultConfigs(){
"style": {
"backgroundColor": "rgb(255,214,10)"
},
"toast": false,
"url": "^https?:\/\/.*stage-admin.+|^https?:\/\/admin-.+stage.+"
},
{
Expand All @@ -45,7 +42,6 @@ function getDefaultConfigs(){
"style": {
"backgroundColor": "rgb(255,69,58)"
},
"toast": false,
"url": "^https?:\/\/.*admin.+"
}
];
Expand Down

0 comments on commit 4c0116c

Please sign in to comment.